Question: In C Programming: I am writing a small shell and I'm kind of confused on where to start with this: Managing background processes Before printing

In C Programming:

I am writing a small shell and I'm kind of confused on where to start with this:

Managing background processes

Before printing a prompt message, smallsh shall check for any un-waited-for background processes in the same process group ID as smallsh, and print the following informative message to stderr for each:

If exited: Child process %d done. Exit status %d. , ,

If signaled: Child process %d done. Signaled %d. , ,

If a child process is stopped, smallsh shall send it the SIGCONT signal and print the following message to stderr: Child process %d stopped. Continuing. , (See KILL(2))

Any other child state changes (e.g. WIFCONTINUED) shall be ignored.

Note, the pid of a process is of type pid_t, and should be printed using the %jd format specifier. This also requires explicitly casting the value to intmax_t because of the way variadic arguments (used by printf functions) work. For example:

#include  /* pid_t pid; */ fprintf(stderr, "Child process %jd done. Exit status %d ", (intmax_t) pid, status); 

The "$?" and "$!" variables are not modified in this stage.

The prompt

Smallsh shall print a prompt to stderr by expanding the PS1 parameter (see parameter expansion below).

Explanation:

PS1 stands for Prompt String 1. There are three PSx parameters specified in POSIX:

PS1 (default: $ for users, # for root user): Printed before each new command line

Smallsh does not support line continuation or tracing, and does not implement the select builtin, so we will only use PS1 in this assignment.

Reading a line of input

After printing the command prompt, smallsh shall read a line of input from stdin. (See GETLINE(3))

If reading is interrupted by a signal (see signal handling), a newline shall be printed, then a new command prompt shall be printed (including checking for background processes), and reading a line of input shall resume. (See CLEARERR(3), and dont forget to reset errno).

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!