Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

San Jose State University GNU Parallel Program Worksheet

San Jose State University GNU Parallel Program Worksheet

San Jose State University GNU Parallel Program Worksheet

Description

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


Explanation & Answer:

1 Worksheet
User generated content is uploaded by users for the purposes of learning and should be used following Studypool’s honor code & terms of service.

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Essay Noon only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Essay Noon are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Essay Noon are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Essay Noon, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20