Difference Between System Call and Interrupt

System Call vs Interrupt

A typical processor executes instructions one by one. But there may be occasions when the processor has to stop temporarily and hold the current instruction and execute some other program or code segment (residing in some other place). After doing this, the processor returns to normal execution and continues from where it left off. A system call and an interrupt are such occasions. A system call is a call to a subroutine built in to the system. An interrupt is a program control interruption caused by external hardware events.

What is a System Call?

System calls provide programs running on the computer an interface to talk with the operating system. When a program needs to ask for a service (for which it does not have permission itself) from the kernel of the operating system it uses a system call. User level processes do not have the same permissions as the processes directly interacting with the operating system. For example, to communicate with and external I/O device or to interact with any other processes, a program has to use system calls.

What is an Interrupt?

During normal execution of a computer program, there could be events that can cause the CPU to temporarily halt. Events like this are called interrupts. Interrupts can be caused by either software or hardware faults. Hardware interrupts are called (simply) Interrupts, while software interrupts are called Exceptions or Traps. Once an interrupt (software or hardware) is raised, the control is transferred to a special subroutine called ISR (Interrupt Service Routine) that can handle the conditions that are raised by the interrupt.

As mentioned above, the term Interrupt is usually reserved for hardware interrupts. They are program control interruptions caused by external hardware events. Here, external means external to the CPU. Hardware interrupts usually come from many different sources such as timer chip, peripheral devices (keyboards, mouse, etc.), I/O ports (serial, parallel, etc.), disk drives, CMOS clock, expansion cards (sound card, video card, etc). That means hardware interrupts almost never occur due to some event related to the executing program. For example, an event like a key press on the keyboard by the user, or an internal hardware timer timing out can raise this kind of interrupt and can inform the CPU that a certain device needs some attention. In a situation like that the CPU will stop whatever it was doing (i.e. pauses the current program), provides the service required by the device and will get back to the normal program.

What is the difference between System Call and Interrupt?

System call is a call to a subroutine built in to the system, while Interrupt is an event, which causes the processor to temporarily hold the current execution. However one major difference is that system calls are synchronous, whereas interrupts are not. That means system calls occur at a fixed time (usually determined by the programmer), but interrupts can occur at any time due an unexpected event such as a key press on the keyboard by the user. Therefore, when ever a system call occurs the processor only has to remember where to return to, but in the event of an interrupt, the processor has to remember both the place to return to and the state of the system. Unlike a system call, an interrupt usually does not have anything to do with the current program.

ncG1vNJzZmivp6x7pbXFn5yrnZ6YsqOx07CcnqZemLyue8OinZ%2Bdopq7pLGMm5ytr5Wau26%2F2KyrnqVdmK6tuIyapZ1lpqh6qrrTnqmrraCpfA%3D%3D