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: 3756849 • 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

#include <stdio.h>
#include <stdlib.h>

int main()
{

int proc_id = 333;
int n,m;

printf("Enter the number of child");
scanf("%d",&n);

printf("Enter the number of grandchild");
scanf("%d",&m);

//display the process id and parent process id created for each process

for(int i = 1;i<n;i++)
   {
      printf("child %d process id is %d and its parent process id is %d",&i,&proc_id,&proc_id);

      for(int j = 1;j<m;j++)
          {
             printf("grandchild %d of child %d process id is %dand its parent process id is %d",&i , &j , &proc_id , &proc_id);
          }
   }

return 0;
}

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