edited by
375 views
0 votes
0 votes

Consider the following program.

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main(void)
{
    pid_t pid;
    int varl = 100;
    pid = fork();
    if(pid == 0)           /* Child process */
        varl = 200;
    fork();
    printf(“%d”, varl);
    return 0;
}

Assuming all invocations of fork are successful, which of the following is a correct output when the program is executed on the $\text{UNIX OS}?$

  1. $100 \; 100 \; 200 \; 200$
  2. $200 \; 200 \; 200 \; 200$
  3. $100 \; 100 \; 100 \; 100$
  4. $100 \; 200 \; 200 \; 200$
edited by

1 Answer

Answer:

Related questions

2 votes
2 votes
3 answers
3