Question: Write a program using C to generate a binary tree of processes. The input to the program includes the number of levels in the tree.

Write a program using C to generate a binary tree of processes. The input to the program includes the number of levels in the tree. The maximum number of levels is 5, but the program should work for a general case of any number. Use command line arguments. Example of a program run is as follows: ecs416lin213.cecs.csuld.edu:1>p1 4

Please show output listing using N = 3. My previous lab is shown as reference, please complete. The project is to generate a binary tree. Therefore, you should at least describe what a binary tree is in context of processes and how to generate a binary tree. Just Focus on the important implementation (e.g., generate exactly two child processes by calling fork() twice and use break to allow parent process to break out of loop).

Write a program using C to generate a binary tree of processes.

Starting point:

The input to the program includes the number of levels in the

tree. The maximum number of levels is 5, but the program should

/**************************************************************************/ /* 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

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!