1. Consider the following program: #include main) int flag0 int d,e; dfork ; if(
ID: 3719430 • Letter: 1
Question
1. Consider the following program: #include main) int flag0 int d,e; dfork ; if(d 0){ // forkl // fork2 // fork3 // fork4 e-fork ); if e > 0 fork ) else fork if wait (NULL) > 0) flag 1; ", flag) ; printf ("%d exit (0) Suppose the program is run from a shell several times and the output of each run is recorded. Here is a description of the return value of wait) from the corresponding UNIX manpage RETURN VALUES When wait) returns due to a terminated child process, the procesS ID of the child is returned to the calling process Otherwise, -1 is returned and errno is set to indicate the error ERRORS The wait() function will fail if: ECHILD The calling process has no existing unwaited-for child processes.Explanation / Answer
Answer (a).
we are get different results during different runs in fork() system call. because system call fork() is used to create processes. child process is duplicate of parent process, created by fork(). child process is different pid (process ID) then parent.
After the fork, whatever statements once executed by a parent and once executed by child. here child process is seperate process from it's parent process. so, parent process will continue it's own execution after creating child process.
Answer (b).
0 0 1 0 1 = Possible
0 1 0 0 1 = Impossible
1 0 0 1 0 = Impossible
0 1 1 0 0 = Impossible
0 0 0 1 1 = Possible
0 1 1 1 0 = Impossible
0 0 0 0 1 = Impossible
Answer (c).
replaced by while, and only one possible outcomes with 0 0 0 1 1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.