System Calls & IPC Questions with Answers

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

Sample questions

Question 1Easy

A system call is:

  1. A hardware fault
  2. A call to a function defined elsewhere in the same user program
  3. A request from a user program for a service provided by the OS kernel
  4. A compiler directive

Answer: C. A request from a user program for a service provided by the OS kernel

Explanation

System calls (e.g. read, write, fork) are the programming interface to the kernel; they switch the CPU into kernel mode.

Step-by-step solution

  1. System call is a way for user program to ask OS for help.
  2. It allows user program to use services like file read or process creation.
  3. This request is made through specific functions called system calls.
  4. These functions are part of the OS kernel and not the user program itself.
  5. So, system call is a request from user program to OS kernel.

Why the other options are wrong

  • A. A hardware fault is an error from the hardware; a system call is a request made by software.
  • B. A call to a function in the same user program is an ordinary function call, not a system call.
  • D. A compiler directive is an instruction to the compiler, not a request to the kernel.

Tip: Remember: System calls are requests made by user programs to the OS kernel.

Question 2Easy

In pipe(fd), which descriptor is the read end?

  1. fd[0]
  2. fd[2]
  3. fd[1]
  4. Both ends are the same

Answer: A. fd[0]

Explanation

By convention fd[0] is opened for reading and fd[1] for writing (think of 0 as stdin and 1 as stdout).

Step-by-step solution

  1. In pipe(fd), fd[0] is the read end by convention.
  2. fd[1] is used for writing by default.
  3. So the read end is always fd[0].
  4. Final answer: fd[0].

Why the other options are wrong

  • B. fd[2] is out of range for the two-element array that pipe() fills.
  • C. fd[1] is the write end; data written there is read from fd[0].
  • D. The two ends are different descriptors; one reads and one writes.

Tip: Remember: fd[0] is read end, fd[1] is write end.

Question 3Easy

Why does a CPU have separate user mode and kernel mode?

  1. To make programs run faster
  2. To allow two programs to run on one core at exactly the same time
  3. To save power
  4. To stop user programs from executing privileged instructions directly

Answer: D. To stop user programs from executing privileged instructions directly

Explanation

A mode bit lets the hardware trap privileged operations (I/O, interrupt control, MMU changes) when attempted in user mode.

Step-by-step solution

  1. User code must not access hardware or memory of others directly.
  2. Privileged instructions run only in kernel mode.
  3. Mode separation enforces protection.

Why the other options are wrong

  • A. Mode does not speed up programs.
  • B. Concurrency needs multiple cores or time slicing.
  • C. Not a power feature.

Question 4Easy

Which system call is used to terminate the calling process?

  1. exit()
  2. kill()
  3. fork()
  4. close()

Answer: A. exit()

Explanation

exit() ends the process and passes a status to the parent; kill() sends a signal to some process.

Step-by-step solution

  1. exit() is a function that terminates the calling process.
  2. kill() sends a signal to another process, not itself.
  3. fork() creates a new process, it does not terminate.
  4. close() closes a file descriptor, not a process.
  5. The correct system call to end the process is exit().

Why the other options are wrong

  • B. kill() sends a signal to a process, and it does not end the calling process itself.
  • C. fork() creates a new child process; it does not terminate the caller.
  • D. close() closes a file descriptor; it does not end the process.

Tip: Remember: exit() stops the process, while kill() just sends a signal.

Question 5Medium

Why does an OS set a timer interrupt before switching to a user process?

  1. To start the bootstrap program
  2. To measure disk speed
  3. To trigger a page fault so that memory can be reclaimed
  4. So it can regain control even if the process never yields the CPU

Answer: D. So it can regain control even if the process never yields the CPU

Explanation

Without the timer, a process in an infinite loop could monopolise the CPU; the timer enables preemptive scheduling.

Step-by-step solution

  1. Timer interrupt ensures OS can switch processes even if one runs forever.
  2. It prevents a single process from using all CPU time.
  3. OS uses timer to regain control when process does not yield CPU.
  4. This allows fair sharing of CPU among all running processes.
  5. So it can regain control even if the process never yields the CPU.

Why the other options are wrong

  • A. The bootstrap program is started by the boot process, not by the timer interrupt.
  • B. Measuring disk speed is not the purpose of the timer interrupt set before user code runs.
  • C. A timer interrupt does not trigger page faults; it lets the OS regain CPU control.

Question 6Medium

Which system call does a shell typically call in the child process to run a command such as ls?

  1. kill()
  2. pipe()
  3. An exec-family call such as execvp()
  4. wait() followed by exit()

Answer: C. An exec-family call such as execvp()

Explanation

The shell forks; the child execs the command, while the parent waits (unless the command runs in the background).

Step-by-step solution

  1. The shell creates a new process using fork().
  2. The child process uses an exec-family call to replace its memory with the command.
  3. execvp() matches the command name with available programs in the PATH.
  4. This allows the child to run commands like ls directly.
  5. Other calls like kill(), pipe(), or wait() are used for different purposes.

Why the other options are wrong

  • A. kill() sends a signal to a process; the shell does not use it to run ls.
  • B. pipe() creates a pipe; it does not run a command in the child.
  • D. wait() and exit() manage the parent and the end of a process; they do not run ls.

Tip: Remember: execvp() and similar calls are used to run external programs in a child process.

Question 7Medium

How are system call parameters most commonly passed to the kernel when there are only a few of them?

  1. Through a network socket
  2. Through a file on disk
  3. By changing the page table
  4. In CPU registers

Answer: D. In CPU registers

Explanation

Registers are fastest; for more parameters, a pointer to a memory block or the stack is used.

Step-by-step solution

  1. System calls use registers for fast data transfer.
  2. Registers hold parameters directly in CPU.
  3. Few parameters fit easily into registers.
  4. Changing page tables is not common for this purpose.
  5. Final answer: In CPU registers.

Why the other options are wrong

  • A. A network socket is not how the kernel gets a few parameters; registers are used.
  • B. A file on disk is too slow for a few parameters; they go in registers.
  • C. Changing the page table is for memory mapping, not for passing system call parameters.

Tip: Remember: Few parameters → registers; many → stack or memory.

Question 8Medium

What does the dup2(oldfd, newfd) system call do?

  1. Doubles the size of a buffer
  2. Copies a file on disk
  3. Makes newfd refer to the same open file as oldfd
  4. Duplicates the calling process

Answer: C. Makes newfd refer to the same open file as oldfd

Explanation

Shells use dup2 to redirect standard input or output (e.g. to a pipe or file) before calling exec.

Step-by-step solution

  1. dup2(oldfd, newfd) makes newfd point to the same file as oldfd.
  2. This is used to redirect input/output in shells before executing a command.
  3. It replaces the file descriptor newfd with the one from oldfd.
  4. The calling process is not duplicated (that is fork), so D is wrong.
  5. No file is copied on disk, so B is wrong.
  6. Final answer: Makes newfd refer to the same open file as oldfd.

Why the other options are wrong

  • A. dup2 does not change buffer size; it works on file descriptors.
  • B. dup2 does not copy a file on disk; it makes two descriptors refer to one open file.
  • D. dup2 does not duplicate the process; fork() creates a child process.

Tip: Remember dup2 is for linking file descriptors, not copying files.

Question 9Medium

A library function such as printf() in C eventually uses which system call to send output to the terminal?

  1. read()
  2. write()
  3. open()
  4. fork()

Answer: B. write()

Explanation

printf formats and buffers data in user space, then calls write() on file descriptor 1.

Step-by-step solution

  1. Printf formats and buffers data in user space.
  2. The data is sent via the write() system call.
  3. write() uses file descriptor 1 for standard output.
  4. Thus, printf uses write() as the underlying system call.
  5. Final answer: B (write()).

Why the other options are wrong

  • A. read() gets input from a file or descriptor; printf sends output with write().
  • C. open() opens a file and returns a descriptor; it does not send terminal output.
  • D. fork() creates a new process; printf does not use it to send output.

Tip: Remember: write() is used for output, read() for input.

Question 10Medium

Which mechanism lets a process ask the kernel to deliver a notification after a given number of seconds?

  1. mmap()
  2. pipe()
  3. alarm() with the SIGALRM signal
  4. mmap() with a timeout argument

Answer: C. alarm() with the SIGALRM signal

Explanation

alarm(n) causes SIGALRM to be sent to the process after n seconds.

Step-by-step solution

  1. The process needs a notification after a set number of seconds.
  2. alarm(n) asks the kernel to send SIGALRM after n seconds.
  3. mmap() maps memory and pipe() creates a channel; neither sets a timer.
  4. So alarm() with SIGALRM, option C, is correct.

Why the other options are wrong

  • A. mmap() maps memory; it does not set a timer.
  • B. pipe() creates a communication channel, not a timer.
  • D. mmap() has no timeout argument.

Tip: alarm(seconds) plus SIGALRM is the classic timer answer.

Practise all 34 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