Question: This assignment involves the writing of a simplified version of the shell utility nohup called my_nohup. The utility is used to prevent processes from being
This assignment involves the writing of a simplified version of the shell utility nohup called my_nohup. The utility is used to prevent processes from being killed by the SIGHUP or SIGQUIT signals when the user logs off from a session.
First read the man pages on nohup to understand how the utility works. Also read the man pages on the function isatty().
Your code will carry out the following actions:
1.) If the user supplies no command line arguments (other than the name of the executable) write an informative message to stderr (STDERR_FILENO) and exit with an error value.
2.) Use the function isatty(int filedesc) to determine if the standard output file descriptor is associated with a terminal file. If it is, your code needs to redirect standard output to the file nohup.out (which may already exist.) nohup.out needs to be created or opened for writing. If you need to create the file, give it permissions such the owner has read/write permission. When this section of code is completed, if isatty() returned true, the file descriptior originally assigned to STDOUT_FILENO should be associated with nohup.out. If you are unable to open/create nohup.out, write an informative error message and exit with an error value.
3.) If standard error, STDERR_FILENO, is associated with a terminal device, close it and associate file descriptor 2 with nohup.out.
4.) Ignore SIGHUP and SIGQUIT. You must do this using sigaction() and the appropriate macros. If you are unable to ignore these signals, write an informative message to stderr and exit with an error value.
5.) The new program is the first command line argument to my_nohup. exec*() this program and its arguments, e.g.
$ my_nohup testsim 5 10
In this example, my_nohup would use exec*() to execute the program testsim with the command line arguments 5 and 10.
If the exec*() fails, write out an informative message using either perror() or strerror(). Exit with an error value.
Note: the standard output of the new program will be written to nohup.out.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
