search
Log In
0 votes
124 views
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int value = 5;
int main()
{
pid t pid;
pid = fork();
if (pid == 0) { /* child process */
value += 15;
return 0;
}
else if (pid > 0) { /* parent process */
wait(NULL);
printf("PARENT: value = %d",value); /* LINE A */
return 0;
}
}

Explain what the output will be at LINE A in this program.
in Operating System 124 views

Please log in or register to answer this question.

Related questions

1 vote
1 answer
1
32 views
Including the initial parent process, how many processes are created by the following program. #include <stdio.h> #include <unistd.h> int main() { fork(); fork(); fork(); return 0; }
asked Mar 19, 2019 in Operating System akash.dinkar12 32 views
0 votes
0 answers
2
54 views
Using the program shown below, explain what the output will be at lines X and Y. #include <sys/types.h> #include <stdio.h> #include <unistd.h> #define SIZE 5 int nums[SIZE] = {0,1,2,3,4}; int main() { int i; pid t pid; pid = fork(); if (pid == 0) { for (i = 0; i < SIZE; i++) { ... else if (pid > 0) { wait(NULL); for (i = 0; i < SIZE; i++) printf("PARENT: %d ",nums[i]); /* LINE Y */ } return 0; }
asked Mar 19, 2019 in Operating System akash.dinkar12 54 views
0 votes
0 answers
3
99 views
Using the program in Figure 3.34, identify the values of pid at lines A, B, C, and D. (Assume that the actual pids of the parent and child are 2600 and 2603, respectively.) #include <sys/types.h> #include <stdio.h> #include <unistd.h> int main() { pid t pid, pid1; /* fork a child ... printf("parent: pid = %d",pid); /* C */ printf("parent: pid1 = %d",pid1); /* D */ wait(NULL); } return 0; }
asked Mar 19, 2019 in Operating System akash.dinkar12 99 views
0 votes
1 answer
4
214 views
Explain the circumstances under which which the line of code marked printf("LINE J") in following program will be reached. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int main() { pid t pid; /* fork a child process */ pid = fork(); if (pid < 0) { / ... else { /* parent process */ /* parent will wait for the child to complete */ wait(NULL); printf("Child Complete"); } return 0; }
asked Mar 19, 2019 in Operating System akash.dinkar12 214 views
...