I am a beginner in C programming. This semester, I took the Operating Systems course with a lab that requires the use of the C language to understand the concept of processes and threads, mainly.
My lab instructor asked us to write a small code to develop a new Unix command to execute many sub-commands simultaneously and the submission is after two days from now.
Here is the question:
Any help would be appreciated.You are requested to develop a new UNIX command named “cone” to execute many sub-commands simultaneously. The set of sub-commands to be executed by cone will be provided as command-line arguments. For each command-line argument, cone will create a new process in order to execute the corresponding sub-command. For example, if we type at UNIX’s shell prompt
cone ls ps
cone will create two child processes such that the first child executes “ls” command and the second child executes “ps” command.
An option (-w) can be supplied to enforce cone command to suspend until all sub-commands have been terminated. In this case, a log file “.cone.log” will be generated describing the termination status for each child process. A typical log file might look as follows:
CMD TERMINATION EXIT CODE OR SIGNAL#
ps normal 0
mycode normal 2
prog abnormal 14
cone command terminates with exit code 0 (zero) if all child processes are successfully forked (when –w option is not specified) or if all child processes are successfully executed (i.e. the processes are terminated normally with exit status 0) Otherwise it terminates with non-zero value according to the following table :
Exit code Meaning
1 cone was executed without arguments
2 If cone command fails to fork a new process, the program should terminate directly with exit code 2.
3 If any child process terminated normally with exit code greater than 0 then the cone command should terminate with exit code 3. Provided that all other child processes were terminated normally.
4 One of the child processes was terminated abnormally.
If a sub-command requires an option or options then the command name along with its options are surrounded by quotation mark. For example
cone "ls –l -a" "ps –l"
You may e-mail me at: firstname.lastname@example.org