Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!