Question: (d.) Explain, using examples how the following sample code, which utilises the linux fork(). wait() and exec() command, can be used to run new
(d.) Explain, using examples how the following sample code, which utilises the linux fork(). wait() and exec() command, can be used to run new processes. (12 marks). Void execute (char* argv[]) { . /* variable declaration */ pid_t pid; int status; if ((pid = fork()) < 0) { here */ } else if (pid == 0) { printf("*** ERROR: forking child process failed "); exit(42); } if (execvp(*argv, argv) < 0) { printf("*** ERROR: exec failed "); exit(1): } } else { here */ /* What is happening while (wait(&status) != pid); /* what is happening here /* what is happening here */ /* what is happening
Step by Step Solution
There are 3 Steps involved in it
The provided sample code demonstrates how the Linux system calls fork wait and exec can be utilized to run new processes Lets break down the code and ... View full answer
Get step-by-step solutions from verified subject matter experts
