Question: Write a program in C to create N processes that form a ternary tree (i.e., each node has exactly three child nodes) where N is

Write a program in C to create N processes that form a ternary tree (i.e., each node has exactly three child nodes) where N is the command line input to the program (N must be greater than zero and less than 10). Each process prints out its own PID and its parent PID. Use loop structure. Explain fully how the program works. For brevity, do not write include files. My previous lab was provided as starting point,please complete.

Write a program in C to create N processes that form a

ternary tree (i.e., each node has exactly three child nodes) where N

/**************************************************************************/ /* PROGRAM: lab2.c */ /* DESCRIPTION: This program generates a chain of processes */ /* using fork(). The number of processes n is a command line argument. */ /* Each process sleeps for a random time less than 10 seconds then prints out */ /* process ID, parent ID, and child ID */ /**************************************************************************/ # include # include # include # include int main(int argc, char *argv[]) { int i, m, n, sleeptime, seed; pid_t childpid; if (argc !=2) { printf(" Usage: %s processes ", argv[0]); exit(1); } n = atoi(argv[1]); m = 10; childpid = 0; for (i=0; i # include # include # include # include unistd.h? int main int argc, char *argvI) int i, m, n, sleeptime, seed pid t childpid; if (argc 2) { printf("in Usage: %s processesa", argv[0]) exit(1) n = atoi(argv[1]); m = 10; childpid = 0; for (i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!