Operating System MCQs - Threads, fork(), IPC and System Calls (Set 4)

Operating System MCQs - Threads, fork(), IPC and System Calls (Set 4) - CodingHumans

Threads, process creation and inter-process communication come up often in GATE, university exams and systems interviews. This set covers multithreading models, fork() and exec(), zombie and orphan processes, IPC mechanisms, system calls and dual-mode operation, and kernel design.

How to practise: read each question and tap the option you think is correct. You will see right away whether you got it, along with a short explanation, and your score is tracked at the bottom of the screen. This set has 15 questions.

Topics covered in this set

  • What threads share and what they do not
  • User-level vs kernel-level threads and threading models
  • fork(), exec() and wait()
  • Zombie and orphan processes
  • Pipes, shared memory and signals
  • System calls, dual-mode operation and kernel types

Operating System MCQs with answers and explanations

Q1. Which of the following is NOT shared by threads of the same process?

a) Global variables

b) Open files

c) Stack

d) Code section

Q2. Why is switching between threads of the same process usually faster than switching between processes?

a) The address space does not have to be changed

b) Threads never use the CPU

c) The kernel is not involved at all

d) Threads have higher priority

Q3. What is the main drawback of the many-to-one threading model?

a) Threads cannot share memory

b) It needs special hardware

c) It uses too many kernel threads

d) A blocking system call by one thread blocks the entire process

Q4. What value does fork() return in the child process?

a) The parent's PID

b) 0

c) -1

d) The child's PID

Q5. How many times is "hello" printed by this C program?

#include <stdio.h>
#include <unistd.h>

int main() {
    fork();
    fork();
    fork();
    printf("hello\n");
    return 0;
}

a) 6

b) 8

c) 4

d) 3

Q6. What does a successful call to exec() do?

a) Terminates the parent process

b) Duplicates the file descriptors only

c) Creates a new child process

d) Replaces the current process image with a new program

Q7. A zombie process is one that:

a) Has finished, but its parent has not yet called wait() to read its exit status

b) Has lost its parent

c) Is using 100 percent of the CPU

d) Is waiting for I/O

Q8. What happens to an orphan process in Linux?

a) It is moved to swap space

b) It is killed immediately

c) It is adopted by init (PID 1) or systemd, which later reaps it

d) It becomes a zombie forever

Q9. An ordinary (unnamed) pipe is best described as:

a) A form of shared memory

b) A network socket

c) Bidirectional communication between any two processes

d) Unidirectional communication, usually between related processes such as parent and child

Q10. Which IPC mechanism is generally the fastest once it is set up?

a) Shared memory

b) Sockets

c) Pipes

d) Message queues

Q11. When a user program makes a system call, the CPU:

a) Disables all interrupts permanently

b) Stays in user mode

c) Switches from user mode to kernel mode through a trap

d) Restarts the process

Q12. In the classic dual-mode design described in textbooks, what is the mode bit's value in kernel mode?

a) 1

b) 0

c) 2

d) -1

Q13. Which Linux signal can be neither caught nor ignored by a process?

a) SIGKILL

b) SIGHUP

c) SIGTERM

d) SIGINT

Q14. What is a key advantage of kernel-level threads over user-level threads?

a) They need no system calls

b) They use no memory

c) They are always faster to create

d) The kernel can schedule them on different processors at the same time

Q15. How does a microkernel differ from a monolithic kernel?

a) It cannot support multitasking

b) It runs all services in kernel space

c) It keeps only essential services in the kernel and runs drivers and file systems as user-space processes

d) It has no kernel mode

Quick revision notes

  • Threads share code, data, heap and files, but each has its own stack, registers and program counter.
  • fork() returns 0 in the child and the child's PID in the parent; n fork() calls create 2^n processes.
  • exec() replaces the process image; wait() lets the parent collect the child's exit status.
  • Zombie: child finished, but the parent has not called wait(). Orphan: parent finished first and init adopts the child.
  • Shared memory is the fastest IPC; pipes are one-way; SIGKILL and SIGSTOP cannot be caught.
  • A system call traps into kernel mode; a microkernel moves drivers and services into user space.

Frequently asked questions

What is the difference between a process and a thread?

A process is a program in execution with its own address space and resources. A thread is a unit of execution inside a process; threads of the same process share memory and files, which makes them lighter to create and switch.

Why are fork() output questions so common in exams?

They test whether you understand that each fork() duplicates the running process. Draw a tree: every fork() doubles the number of processes, and each process then runs the remaining code.

Which threading model does Linux use?

Linux uses a one-to-one model. Each user thread created with pthreads maps to a kernel task that the scheduler manages.

Comments

Answered 0/0Correct 0