Skip to content

UGC NET CS 2020System Software and Operating System › Basics of Operating SystemsVerified

UGC NET CS 2020 PYQ: Assuming that the system call $\text{fork}()$ never fails, consider the following C program $P1$ and $P2$…

Assuming that the system call $\text{fork}()$ never fails, consider the following C program $P1$ and $P2$ executed on a UNIX/Linux system:

$\begin{array}{|ll|ll|} \hline & /*P1*/ & &/*P2*/ \\ \text{int} & \text{main}() \{ & \text{int} & \text{main} () \{ \\ & \text{fork} (); & & \text{fork();} \\ & \text{fork}(); && \text{printf(“Happy ”)}; \\ & \text{fork}(); & & \text{fork()}; \\ & \text{printf(“Happy ”);} & &\text{printf(“Happy ”);} \\ \} & & & \text{fork()};\\ && & \text{printf(“Happy ”);} \\ && \} \\ \hline \end{array}$

Statement $I$: $P1$ displays “Happy” 8 times

Statement $II$: $P2$ displays “Happy” 12 times

In the light of the above statements, choose the correct answer from the options given below

  1. A
    Both Statement $I$ and Statement $II$ are true
  2. B
    Both Statement $I$ and Statement $II$ are false
  3. C
    Statement $I$ is correct but Statement $II$ is false
    Correct answer
  4. D
    Statement $I$ is incorrect but Statement $II$ is true

Answer

(C) Statement $I$ is correct but Statement $II$ is false

Approach

Count processes created by successive fork calls, counting prints after each fork.

Reviewed by UGC IQ Editorial Team.