Job Control in a Shell
Hi,
I am writing a C shell for one of my classes. We are tasked to implement job control. I am not entirely sure on how to do this so I come here for some questions regarding the logic in handling this.
Essentially, I think it should work as follows:
When a fork occurs for a command, we will install the signal handlers to allow the correct actions for CTRL-Z and CTRL-C as we need to overwrite the current ones in the shell so we can't use those functions (You can't CTRL-C/Z your own shell). Then, we will set the setpgid of the new forked process and save this in the shell with getpgid (parent process). If the new child process is part of a pipeline, we shall continue calling setpgid on each process so that it is the current process.
In terms of doing the CTRL-Z and CTRL-C aspect, we will be able to refer to the currently controlled process because we saved the getpgid value in our data structure. This will allow us to send the SIGTSTP or SIGINT to the correct process during it's time through the pipeline. Then we can restore any stopped process with the SIGCONT signal.
Is the above correct in the thought process and general implementation?
Thanks for any help you can provide.
|