Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 Write a C/C++ program that emulates a simple shell. When started, this program should display a prompt consisting of a single # followed

Part 1

Write a C/C++ program that emulates a simple shell. When started, this program should display a prompt consisting of a single # followed by a space. It then awaits user input. For this program, each input must consist of a single line of text terminated by a newline. That is, you dont have to handle commands that span more than one line.

If the input is "exit" (without the double quotes), the program terminates. The program should also exit if the user provides the end-of-file control code.

If the input is "jobs" (without the double quotes), the program prints a list of previously executed commands with the following columns:

Process ID | State | Command

"Process ID" is the process id of the previously executed commands.

"State" is the current state of the previously executed commands. Ensure your program is capable of displaying all states that are possible in Linux.

"Command" is the command that was executed.

If the input is killeverything (without the double quotes), the program sends the SIGKILL signal to all currently running processes that have been launched by this program in a subshell.

Any other non-empty command should be executed by a subshell and tracked for future calls to print the job table.

Part 2

Create that catches and handles all the exceptions possible ranging from SIGHUP (1) to SIGTERM (15). When this program receives a signal, it should print a message to the screen displaying the identity of the received signal and terminate the program.

Overall

Be sure to document the programs. Be sure to handle unexpected input and errors as gracefully as possible. Be sure the programs are well structured and clear (e.g., use meaningful variable names, functions).

Be sure your programs compile without error or warning when compiled with the -Wall -Wextra and - pedantic options of gcc.

Sample Run

The captures show a sample session running the program. DO NOT OUTPUT ANY DEBUG INFORMATION ==============================================================

{cslinux1:~/src/project3} ./mysh

# jobs

Process ID | State | Command

-----------+-----------+------------------------------------------------

[NO PROCESSES]

# ls

catch_signal catch_signal.c compile.sh mysh mysh.c t

# ls > t

# ls ; pwd

catch_signal catch_signal.c compile.sh mysh mysh.c t

/people/cs/j/jcb011200/src/project3

# ./catch_signal

Unable to handle signal Killed (9) with error Invalid argument (22).

Continuing...

Running forever until I receive a signal

# ./catch_signal

Unable to handle signal Killed (9) with error Invalid argument (22)

. Continuing...

Running forever until I receive a signal

# ./catch_signal

Unable to handle signal Killed (9) with error Invalid argument (22).

Continuing...

Running forever until I receive a signal

# ./catch_signal

Unable to handle signal Killed (9) with error Invalid argument (22).

Continuing...

Running forever until I receive a signal

# ./catch_signal Unable to handle signal Killed (9) with error Invalid argument (22).

Continuing... Running forever until I receive a signal

# jobs

Process ID | State | Command

-----------+-----------+------------------------------------------------

21172 | Exited| ls 21179 | Exited| ls > t

21202 | Exited| ls ; pwd

21278 | Running| ./catch_signal

21313 | Running| ./catch_signal

21336 | Running| ./catch_signal

21358 | Running| ./catch_signal

21400 | Running| ./catch_signal

# kill -2 21278

Received signal Interrupt (2)

# kill -9 21313

# kill -19 21336

# jobs

Process ID | State | Command

-----------+-----------+------------------------------------------------

21172 | Exited| ls

21179 | Exited| ls > t

21202 | Exited| ls ; pwd

21278 | Exited| ./catch_signal

21313 | Killed| ./catch_signal

21336 | Stopped| ./catch_signal

21358 | Running| ./catch_signal

21400 | Running| ./catch_signal

21571 | Exited| kill -2 21278

21628 | Exited| kill -9 21313

21670 | Exited| kill -19 21336

# killeverything

# jobs

Process ID | State | Command

-----------+-----------+------------------------------------------------

21172 | Exited| ls

21179 | Exited| ls > t

21202 | Exited| ls ; pwd

21278 | Exited| ./catch_signal

21313 | Killed| ./catch_signal

21336 | Stopped| ./catch_signal

21358 | Killed| ./catch_signal

21400 | Killed| ./catch_signal

21571 | Exited| kill -2

21278 21628 | Exited| kill -9 21313

21670 | Exited| kill -19 21336

# exit

Received signal Hangup (1)

{cslinux1:~/src/project3}{cslinux1:~/src/cs3377.002/project3} ==============================================================

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions