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?
-
Minimal interrupt example and how some Linux use it for system calls: http://stackoverflow.com/questions/1817577/what-does-int-0x80-mean-in-assembly-code/31836988#31836988 – Ciro Santilli OurBigBook.com Nov 13 '15 at 10:00
2 Answers
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"

- 1,462
- 2
- 17
- 32
-
Thanks for your quick response. So interrupts are hardware, but can be caused by system calls in software? Is that correct? – Brad Penney Nov 11 '15 at 16:16
-
"but can be caused by system calls in software" yes, software is one source of interrupts, but usually all peripherals generate events. The clock tick is an interrupt generated by the system clock which does not require any user/software intervention. – Ali Nov 11 '15 at 16:30
-
Just for further confusion, in many OS classesetc, all syscalls that enter the kernel are described as 'interrupts', even if the mechanism does not involve a classic 'software interrupt' that mimics a 'real' hardware interrupt. The word 'interrupt' is also overloaded further in some languages like Java. Glad that's perfectly clear... :) – Martin James Nov 12 '15 at 02:40
The answer to your question depends upon the underlying hardware (and sometimes operating system implementation). I will return to that in a bit.
In an operating system, what is the difference between a system call and an interrupt?
The purpose of an interrupt handler and a system call (and a fault handler) is largely the same: to switch the processor into kernel mode while providing protection from inadvertent or malicious access to kernel structures.
An interrupt is triggered by an asynchronous external event. A system call (or fault or trap) is triggered synchronously by executing code.
Are all system calls interrupts? Are all interrupts system calls?
System calls are not interrupts because they are not triggered asynchronously by the hardware. A process continues to execute its code stream in a system call, but not in an interrupt.
That being said, Intel's documentation often conflates interrupt, system calls, traps, and faults, as "interrupt."
Some processors treat system calls, traps, faults and interrupts largely the same way. Others (notably Intel) provide different methods for implementing system calls.
In processors that handle all of the above in the same way, each type of interrupt, trap, and fault has a unique number. The processor expects the operating system to set up a vector (array) of pointers to handlers. In addition, there are one or more handlers available for an operating system to implement system calls
Depending upon the number of available handlers, the OS may have a separate handler for each system call or use a register value to determine what specific system function to execute.
In such a system, one can execute an interrupt handler synchronously the same way one invokes a system call.
For example, on the VAX the CHMK #4
instruction, invokes the 4th kernel mode handler. In intel land there is an INT
instruction that does roughly the same.
Intel processors have supported the SYSCALL
mechanism that provides a different way to implement system calls.

- 464
- 1
- 5
- 15

- 20,574
- 3
- 26
- 62