Processes and Threads 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

Q24

GATE CS 2024 CS-1Processes and ThreadsMSQ1 mark
Which of the following statements about threads is/are TRUE?
More than one option can be correct.
Show answer without attempting

Answer: D

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

Q22

GATE CS 2023 CSProcesses and ThreadsMSQ1 mark
Which one or more of the following need to be saved on a context switch from one thread (T1T_1) of a process to another thread (T2T_2) of the same process?
More than one option can be correct.
Show answer without attempting

Answer: B, C, D

Q23

GATE CS 2023 CSProcesses and ThreadsMSQ1 mark
Which one or more of the following options guarantee that a computer system will transition from user mode to kernel mode?
More than one option can be correct.
Show answer without attempting

Answer: C, D

Q14

GATE CS 2021 CS-1Processes and ThreadsMSQ1 mark
Which of the following standard C library functions will always invoke a system call when executed from a single-threaded process in a UNIX/Linux operating system?
More than one option can be correct.
Show answer without attempting

Answer: A, C

Q42

GATE CS 2021 CS-2Processes and ThreadsMSQ2 marks
Consider the following multi-threaded code segment (in a mix of C and pseudo-code), invoked by two processes P1 and P2, and each of the processes spawns two threads T1 and T2:
int x = 0; // global
Lock L1; // global
main() {
    create a thread to execute foo(); // Thread T1
    create a thread to execute foo(); // Thread T2
    wait for the two threads to finish execution;
    print (x);}

foo() {
    int y = 0;
    Acquire L1;
    x = x + 1;
    y = y + 1;
    Release L1;
    print (y);}
Which of the following statement(s) is/are correct?
More than one option can be correct.
Show answer without attempting

Answer: A, D

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

Q18

GATE CS 2017 CS-1Processes and ThreadsMCQ1 mark−1/3 if wrong
Threads of a process share
Show answer without attempting

Answer: D

Q7

GATE CS 2017 CS-2Processes and ThreadsMCQ1 mark−1/3 if wrong
Which of the following is/are shared by all the threads in a process?

I. Program counter
II. Stack
III. Address space
IV. Registers
Show answer without attempting

Answer: B

Q20

GATE CS 2014 CS-1Processes and ThreadsMCQ1 mark−1/3 if wrong
Which one of the following is FALSE?
Show answer without attempting

Answer: D

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/160 correct0 marks

Related topics in Operating Systems