Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program on a Unix OS to create several child and grandchild processes.

ID: 3755577 • Letter: W

Question

Write a C program on a Unix OS to create several child and grandchild processes. Once the main process starts, it asks the user to enter two positive integer numbers n, and m. The main process should display its process ID. Then, the main process creates n child processes. Also, each child process creates m grandchild processes. Finally, each created process should display its process ID and its parent process ID.

Here is a sample output:

Main process ID = xxx.

Enter n: 2

Enter m: 3

Child 1 process ID = xxx and its parent process ID = xxx.

Child 2 process ID = xxx and its parent process ID = xxx.

Grandchild 1 process ID = xxx and its parent process ID = xxx.

Grandchild 2 process ID = xxx and its parent process ID = xxx.

Grandchild 3 process ID = xxx and its parent process ID = xxx.

Grandchild 1 process ID = xxx and its parent process ID = xxx.

Grandchild 2 process ID = xxx and its parent process ID = xxx.

Grandchild 3 process ID = xxx and its parent process ID = xxx.

Grandchild 1 process ID = xxx and its parent process ID = xxx.

Grandchild 2 process ID = xxx and its parent process ID = xxx.

Grandchild 3 process ID = xxx and its parent process ID = xxx.

**Note the created processes output statements could be in a different order.

Explanation / Answer

To simply answer the question that was asked. You could store the process ID of each script you're calling into the same variable:

$child_process_ids would just be a space delimited string of process Ids. Now, this answers the question asked, however, what I would do would be a bit different. I would call each script from a for loop, store its process ID, then wait on each one in another for loop to finish and inspect each exit code individually. Using the same example, here's what it would look like.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote