Processes questions

Q63

GATE CS 2026 CS-1Processes and ThreadsNAT2 marks
Consider the following program snippet. Assume that the program compiles and runs successfully. Further, assume that the fork() system call is always successful in creating a process.
int main () {
 int i;
 for (i = 0; i < 3; i++){
 if (fork() == 0){
 continue;
 }
 break;
 }
 printf("Hello!");
 return 0;
}
The total number of times that the printf statement gets executed is ________. (answer in integer)
Show answer without attempting

Answer: 4

Q29

GATE CS 2025 CS-1Processes and ThreadsNAT1 mark
Suppose in a multiprogramming environment, the following C program segment is executed. A process goes into I/O queue whenever an I/O related operation is performed. Assume that there will always be a context switch whenever a process requests for an I/O, and also whenever the process returns from an I/O. The number of times the process will enter the ready queue during its lifetime (not counting the time the process enters the ready queue when it is run initially) is _______. (Answer in integer)
int main()
{
 int x=0,i=0;
 scanf("%d",&x);
 for(i=0; i<20; i++)
 {
 x = x+20;
 printf("%d
",x);
 }
 return 0;
}
Show answer without attempting

Answer: 21

Q25

GATE CS 2024 CS-1Processes and ThreadsMSQ1 mark
Which of the following process state transitions is/are NOT possible?
More than one option can be correct.
Show answer without attempting

Answer: B, C

Q57

GATE CS 2024 CS-1Processes and ThreadsNAT2 marks
Consider the following code snippet using the fork() and wait() system calls. Assume that the code compiles and runs correctly, and that the system calls run successfully without any errors.
int x = 3;
while(x > 0) {
 fork();
 printf("hello");
 wait(NULL);
 x--;
}
The total number of times the printf statement is executed is _______
Show answer without attempting

Answer: 14

Q25

GATE CS 2024 CS-2Processes and ThreadsMSQ1 mark
Consider a process P running on a CPU. Which one or more of the following events will always trigger a context switch by the OS that results in process P moving to a non-running state (e.g., ready, blocked)?
More than one option can be correct.
Show answer without attempting

Answer: A, B

Q12

GATE CS 2020 CSProcesses and ThreadsMCQ1 mark−1/3 if wrong
Consider the following statements about process state transitions for a system using preemptive scheduling.

I. A running process can move to ready state.
II. A ready process can move to running state.
III. A blocked process can move to running state.
IV. A blocked process can move to ready state.

Which of the above statements are TRUE?
Show answer without attempting

Answer: C

Q17

GATE CS 2019 CSProcesses and ThreadsNAT1 mark
The following C program is executed on a Unix/Linux system:
#include <unistd.h>
int main()
{
    int i;
    for (i=0; i<10; i++)
        if (i%2 == 0) fork();
    return 0;
}
The total number of child processes created is __________.
Show answer without attempting

Answer: 31

Q8

GATE CS 2012 CSProcesses and ThreadsMCQ1 mark−1/3 if wrong
A process executes the code
fork();
fork();
fork();
The total number of child processes created is
Show answer without attempting

Answer: C

0/80 correct0 marks

Related topics in Processes and Threads