recategorized by
119 views
0 votes
0 votes

Consider a program using the fork and exec system calls shown below. Assume that the code shown below executes correctly, and that the fork and exec system calls succeed. The exec system call (invoked via the “execv” function) correctly runs the sleep command to sleep for $1$ second.

#include <studio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
void main(int argc, char **argv) {
int rc;
int a = 0;
rc = fork();
if(rc == 0) {
char *const exec_arg[] = {"/bin/sleep", "1", NULL};
execv(exec_arg[0], exec_arg);
printf("a=%d\n", a);
}
else {
a++;
wait(NULL);
printf("a=%d\n", a);
}
}


Which of the following is/are possible output when this program is executed?

 

  1. $\textsf{a = 0}\\
    \textsf{a = 1}$
  2. $\textsf{a = 1}\\
    \textsf{a = 0}$
  3. $\textsf{a = 1}$
  4. $\textsf{a = 0}$

 

recategorized by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
3
0 votes
0 votes
0 answers
4
admin asked Nov 30, 2021
117 views
Kamala tosses $11$ fair coins and Rajani tosses $10$ fair coins. The probability that the number of heads obtained by Kamala is more than the number of tails obtained by ...