In an operating system, what is the difference between a system call and an interrupt?

Brad Penney picture Brad Penney · Nov 11, 2015 · Viewed 18.7k times · Source

In an operating system, what is the difference between a system call and an interrupt? Are all system calls interrupts? Are all interrupts system calls?

Answer

Ali picture Ali · Nov 11, 2015

Short Answer: They are different things.

  • A system call is call by software running on the OS to services provided by the OS.
  • An interrupt is usually external hardware component notifying the CPU/Microprocessor about an event that needs handling in software (usually a driver).

I say usually external, because some interrupts can be raised by software (soft interrupt)

Are all system calls interrupts? Depends

Are all interrupts system calls? No

Long answer: The OS manages CPU time and other hardware connected to the CPU (Memory (RAM), HDD, keyboard, to name a few). It exposes services that allow user programs to access the underlying hardware and these are system calls. Usually these deal with allocating memory, reading/writing files, printing a document and so on.

When the OS interacts with other hardware it usually does so through a driver layer which sets-up the task for the hardware to perform and interrupt once the job is done, so the printer may interrupt once the document is printed or it runs out of pages. It is therefore often the case that a system call leads to generation of interrupts.

Are all system calls interrupts - Depends as they may be implemented as soft interrupts. So when a user program makes a system call, it causes a soft interrupt that results in the OS suspending the calling process, and handle the request itself, then resume the process. But, and I quote from Wikipedia,

"For many RISC processors this (interrupt) is the only technique provided, but CISC architectures such as x86 support additional techniques. One example is SYSCALL/SYSRET, SYSENTER/SYSEXIT (the two mechanisms were independently created by AMD and Intel, respectively, but in essence do the same thing). These are "fast" control transfer instructions that are designed to quickly transfer control to the OS for a system call without the overhead of an interrupt"