Processes & Threads Questions with Answers

43 practice questions on Processes & Threads (Operating Systems) with answers and step-by-step solutions. Try 10 samples below, then practise all 43 free in the AptiNest app.

Sample questions

Question 1Easy

Which UNIX system call returns the process ID of the calling process?

  1. fork()
  2. getppid()
  3. getpid()
  4. wait()

Answer: C. getpid()

Explanation

getpid() returns the caller's own PID; getppid() returns its parent's PID.

Step-by-step solution

  1. getpid() is used to get the process ID of the calling process.
  2. getppid() is used to get the process ID of the parent process.
  3. The question asks for the process ID of the calling process itself.
  4. Therefore, getpid() is the correct system call.
  5. The final answer is getpid().

Why the other options are wrong

  • A. fork() creates a child process; it does not return the caller's process ID.
  • B. getppid() returns the parent's process ID, not the calling process's own ID.
  • D. wait() waits for a child to end; it does not return any process ID.

Tip: Remember: getpid() gives your own PID, getppid() gives your parent's.

Question 2Easy

A process that has all the resources it needs and is waiting only for the CPU is in which state?

  1. Waiting (blocked)
  2. New
  3. Terminated
  4. Ready

Answer: D. Ready

Explanation

Ready processes sit in the ready queue waiting to be dispatched. A waiting/blocked process is waiting for an event such as I/O completion.

Step-by-step solution

  1. A process needing only CPU is not waiting for I/O.
  2. It is prepared to run but waiting for the CPU.
  3. Such a process is in the ready state.
  4. Ready processes are in the ready queue.
  5. The correct answer is Ready.

Why the other options are wrong

  • A. Waiting or blocked means the process waits for I/O or an event, not only for the CPU.
  • B. New means the process is still being created and has not yet been admitted to the ready queue.
  • C. Terminated means the process has finished execution and is no longer scheduled to run.

Tip: Remember: Ready means waiting for CPU, Blocked means waiting for I/O.

Question 3Easy

Why is creating a thread usually cheaper than creating a process?

  1. Threads do not need a stack or registers of their own
  2. Threads share the address space and resources of their process
  3. Processes are created by hardware
  4. Threads do not run on the CPU

Answer: B. Threads share the address space and resources of their process

Explanation

A new thread needs only a stack and register context; a new process needs a new address space and resource tables.

Step-by-step solution

  1. A thread is created inside its process, so it reuses the process's address space.
  2. It does not need to set up new memory mapping or copy resources.
  3. So creating a thread is cheaper, option B.

Why the other options are wrong

  • A. Threads do have their own stacks and registers.
  • C. Processes are created by the operating system, not hardware.
  • D. Threads run on the CPU just like processes.

Tip: Threads share memory; processes do not.

Question 4Easy

On UNIX-like systems, which system call replaces the current process image with a new program?

  1. fork()
  2. exec()
  3. wait()
  4. exit()

Answer: B. exec()

Explanation

fork() creates a copy of the calling process; exec() loads a new program into the calling process, replacing its code and data.

Step-by-step solution

  1. exec() replaces the current process image with a new program.
  2. fork() creates a copy of the calling process but does not replace it.
  3. wait() pauses the parent process until a child process completes.
  4. exit() terminates the calling process and returns control to the parent.
  5. The correct system call is exec().

Why the other options are wrong

  • A. fork creates a copy of the calling process; it does not replace the current program image with a new one.
  • C. wait makes the parent pause until a child finishes; it does not load a new program into the process.
  • D. exit ends the calling process; it does not replace its image with a new program.

Tip: Remember: exec() changes the process, fork() creates a copy.

Question 5Medium

The one-to-one threading model (e.g. Linux and Windows) maps:

  1. Each kernel thread to many processes
  2. All user threads to one kernel thread
  3. Many user threads to fewer kernel threads
  4. Each user thread to its own kernel thread

Answer: D. Each user thread to its own kernel thread

Explanation

One-to-one gives true parallelism and independent blocking, at the cost of one kernel thread per user thread.

Step-by-step solution

  1. One-to-one model links each user thread to a unique kernel thread.
  2. This ensures direct mapping without sharing kernel threads.
  3. Each user thread gets its own dedicated kernel thread.
  4. So, the correct answer is Each user thread to its own kernel thread.

Why the other options are wrong

  • A. Kernel threads do not map to many processes; in one-to-one each user thread gets its own kernel thread.
  • B. All user threads on one kernel thread describes the many-to-one model, not one-to-one.
  • C. Many user threads on fewer kernel threads describes the many-to-many model, not one-to-one.

Tip: Remember: one-to-one means each user thread has its own kernel thread.

Question 6Medium

Which item is NOT usually stored in a process control block (PCB)?

  1. CPU register values
  2. The source code of the program
  3. Memory-management information
  4. Process state

Answer: B. The source code of the program

Explanation

The PCB holds state, PC, registers, scheduling, memory, accounting and I/O status, not the program text.

Step-by-step solution

  1. The PCB holds the process state, CPU register values and memory-management information.
  2. The PCB stores process metadata, not the program's source code.
  3. So the source code is not usually in the PCB, option B.

Why the other options are wrong

  • A. CPU register values are saved in the PCB during a context switch.
  • C. Memory-management information such as page tables pointers is kept in the PCB.
  • D. Process state is a core PCB field.

Tip: PCB = bookkeeping for the OS, not the program text.

Question 7Medium

Which state transition is NOT possible in the basic five-state process model?

  1. Ready to Running
  2. Running to Waiting
  3. Waiting to Running
  4. Running to Ready

Answer: C. Waiting to Running

Explanation

A waiting process must first become ready when its event occurs; only the dispatcher moves a ready process to running.

Step-by-step solution

  1. Ready to Running: dispatcher picks it.
  2. Running to Waiting: I/O request.
  3. Running to Ready: pre-emption.
  4. Waiting to Running is impossible: after I/O completes it first goes to Ready.

Why the other options are wrong

  • A. Valid: scheduler dispatch.
  • B. Valid: process blocks for I/O.
  • D. Valid: time slice expires.

Tip: Waiting always goes via Ready.

Question 8Medium

How many times is "*" printed? Assume every fork() succeeds and output is unbuffered.

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main(void) {
    for (int i = 0; i < 4; i++) {
        if (fork() == 0)
            break;
    }
    printf("*\n");
    while (wait(NULL) > 0);
    return 0;
}
  1. 5
  2. 16
  3. 15
  4. 4

Answer: A. 5

Explanation

Each child breaks out of the loop immediately, so only the original process keeps forking: 4 children + 1 parent = 5 processes, each printing once.

Step-by-step solution

  1. Each child hits break in the first iteration it is created, so it stops forking.
  2. The parent keeps looping and creates 4 children in total.
  3. After the loop, the parent and each of the 4 children print one star.
  4. Total is 4 + 1 = 5, option A.

Why the other options are wrong

  • B. 16 is 2^4, but children do not keep forking.
  • C. 15 would need every child to fork again.
  • D. 4 leaves out the parent, which also prints.

Tip: A break after fork stops that child from forking again.

Question 9Hard

If 10% of a program is strictly serial, what is the upper limit on its speedup no matter how many cores are used?

  1. 100
  2. 90
  3. 10
  4. 9

Answer: C. 10

Explanation

As cores go to infinity, speedup = 1 / (serial fraction)
= 1 / 0.1
= 10.

Step-by-step solution

  1. Serial fraction is 10% or 0.1.
  2. Speedup formula is 1 divided by serial fraction.
  3. 1 divided by 0.1 equals 10.

Why the other options are wrong

  • A. A serial part of 10% caps speedup at 10, so 100 would need only 1% serial work.
  • B. 90 does not come from 1 divided by 0.1; the 10% serial part gives a limit of 10.
  • D. 9 is one less than 10 and is not 1 divided by the serial fraction 0.1.

Tip: Use the formula: Speedup = 1 / (serial fraction).

Question 10Hard

How many times is "hello" printed? Assume every fork() succeeds and output is unbuffered.

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main(void) {
    if (fork() && fork())
        fork();
    printf("hello\n");
    while (wait(NULL) > 0);
    return 0;
}
  1. 3
  2. 5
  3. 8
  4. 4

Answer: D. 4

Explanation

The original runs both forks (&& needs both non-zero) and then the third fork; the two children of the first two forks see a 0 and skip. Processes: original + 3 children = 4.

Step-by-step solution

  1. The first fork creates child C1, which gets 0 and skips the rest of the condition, then prints hello.
  2. The parent runs the second fork, creating C2, which gets 0 so the condition is false, and prints hello.
  3. The parent gets nonzero, so it forks C3 inside the if body; C3 prints hello.
  4. The parent also prints hello, so 4 processes print, option D.

Why the other options are wrong

  • A. 3 misses one of the four processes.
  • B. 5 counts one process too many.
  • C. 8 is far more than the four processes created.

Tip: Trace each fork's return value: 0 for child, pid for parent.

Practise all 43 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Operating Systems topics · All topics