You will develop a proc_manager program that executes multiple commands. It read

You will develop a proc_manager program that executes multiple commands. It reads a command for each execution from stdin on one line of input. So, it reads in the command and its parameters to execute from the stdin (FD0 – file descriptor 0) with each line specifying one command execution. You will execute one command and its parameters as specified on each line of stdin input. The proc_manager program will start up all the processes with the exec command and wait for them to complete, while each command will write its stdout and stderr to log files.
The exec system call (or one of its variants) is going to be at the heart of your code. It is recommended to use execvp, as it takes a flexible number of parameters.
You will run each command in a child process using exec (or one of its variants) and the parent process will wait for each exec to complete. For each child process there will be log messages written to output and error files, which are named after its PID for the executed command. You can use dup2() to make file FD 1 (stdout) go to a file PID.out and FD 2 (stderr) go to a file PID.err for pid PID.
See the dup2 examples in the ipc/connect2.c code file to see how to open the files and use dup2 in the child. You can open the files with flags O_RDWR | O_CREAT | O_APPEND. Remember to set file permissions to be open for everyone, such as 0777
For example, process pid #156 will have logs written to 156.out and 156.err. Upon start, the string “Starting command INDEX: child PID pid of parent PPID” (replace INDEX, PID, PPID) will be logged to the corresponding output file 156.out; you can retrieve PID and PPID through the return value of fork() in the parent, or through getpid() or getppid(); INDEX is the linecount of the command in the input. Either the parent or child can open and write this to the log file for each child process. Upon finish of an exec (either a successful finish or termination via a signal), the parent process should write to the output file PID.out the string “Finished child PID pid of parent PPID” (replace PID, PPID).
Each time a child process finishes, the message “Exited with exitcode = X” should be written to the error file of the process PID.err. X is the PID process’s exit code. This information is gathered using the status parameter of the wait() system call 1.
In case exec fails and the program cannot be started, write a descriptive error message with the command name to stderr (to the command’s error file); for this purpose you may use fprintf(stderr…) or perror(“name of command”) 2. In other words, if the child processes encounter an invalid command (exec fails due to an invalid command) they should have an exit code of 2. Remember the exit code of 0 indicates success, while exit codes other than 0 indicate some failure that was detected.
Here is an example run to run wc (wordcount command) on multiple files and a sleep command:
$ ./proc_manager
wc names.txt
wc names_long_redundant.txt
wc afilethatdoesnotexist
sleep 10
^D <--Ctrl-D is the EOF signal, which terminates your input $ cat 2353.out Starting command 1: child 2353 pid of parent 2234 9 16 88 names.txt Finished child 2353 pid of parent 2234 $ cat 2353.err Exited with exitcode = 0 $ cat 2363.out Starting command 2: child 2363 pid of parent 2234 134 265 1835 names_long_redundant.txt Finished child 2363 pid of parent 2234 $ cat 2363.err Exited with exitcode = 0 $ cat 2377.out Starting command 3: child 2377 pid of parent 2234 Finished child 2377 pid of parent 2234 $ cat 2377.err wc: afilethatdoesnotexist: No such file or directory Exited with exitcode = 1 $ cat 2379.out Starting command 4: child 2379 pid of parent 2234 Finished child 2379 pid of parent 2234 $ cat 2379.err Killed with signal 15

Posted in Uncategorized

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount