Interview Q&A / Operating Systems

INTERVIEW Q&A · 42 QUESTIONS

Operating Systems interview questions

Processes, threads, scheduling, memory and deadlocks, in plain words.

  1. What does fork() return, and how does a program use that value?

    fork() creates a copy of the calling process. It returns 0 in the child, the child's PID in the parent, and -1 if creation failed. Programs branch on that value to run different code in each.

    BeginnerQuick answer1 min read
  2. If a program calls fork() three times in a row, how many processes run in total?

    Each unconditional fork() doubles the number of processes, so n sequential calls give 2^n processes in total: 8 for three calls, meaning 7 new children plus the original.

    IntermediateQuick answer1 min read
  3. What is the difference between fork() and exec()?

    fork() creates a new process that is a copy of the caller. exec() replaces the current process's program with a new one, keeping the same PID. Shells combine them: fork a child, then exec the command in it.

    IntermediateQuick answer1 min read