Question: 1. (3 Marks) You are given the following C program: #include #include #include int main(void) { int var 80; pid t pidA-1, pidB= -1;
1. (3 Marks) You are given the following C program: #include #include #include int main(void) { int var 80; pid t pidA-1, pidB= -1; printf("before fork "); if ((pidA = fork()) < 0) { printf("fork error "); } else if (pidA == 0) { /* child */ var++; } else { /* parent */ pidB wait (NULL); } printf("pidA = %ld, pidB = %ld, var ======= %d ", (long) pidA, (long) pidB, var); exit (0); Assume that the parent process ID is 560 and the child process ID is 561. What is the output of the program? 2. (3 Marks) How many times will this program print "HELLO"? Briefly justify your answer. #include #include #include #include int main() { if execl ("/bin/ls", "ls", NULL) == -1) { printf ("HELLO "); } printf("HELLO ");
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
