C. Your program uses a loop to create ten (10) child processes, printing message
ID: 3822697 • Letter: C
Question
C. Your program uses a loop to create ten (10) child processes, printing messages at the start and end of each process as described in part A. D. Your program is almost identical to part C, but the number of child processes is based on a command line argument passed to your executable. (For example, if your executable is named "proj1", executing the command ./proj1 6 will run a version of your program that creates 6 child processes. Assume the maximum number of child processes is 25. E. Your program is almost identical to part D, but the program is able to discern when each of its child processes completes and print an appropriate message. (For example, when the first child process completes, print a message saying, "Child 1 (PID xxxxx) finished", where xxxxx would be replaced by the actual PID. F. Your program is almost identical to Part E, but each child process starts a new program, replacing the address space of the parent process with that of the new program. For this part, all child processes should start the same program.Explanation / Answer
Assuming C language:
C.
void FORKCHILD(INT noOfProcessesToCreate)
{
pid_t pid;
if(noOfProcessesToCreate > 0)
{
if ((pid = fork()) < 0)
{
printf("Err");
}
else if (pid == 0)
{
printf("Childs%d created ", noOfProcessesToCreate);
}
else if(pid > 0)
{
FORKCHILS(noOfProcessesToCreate - 1);
}
}
}
D.
Program method is same:
just use
int main ( int argc, char *argv[] ) // this contains Command Line args
E.
Already present in Cexplained above.
F. For starting new program, its ame as part E with an addn:
if (pid==0) { /* child process created */
static char *arg[]={//Command Line arguments};
execv("/bin/newprog",argv);
/*if execv fails */
exit(127);}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.