System Programs and Calls
System Calls and Programs
There are two modes of operation for the CPU that are supported by all current operating systems:
Fig. Modes supported by the operating system
In user mode, programs cannot directly access memory or hardware.
Furthermore, when a program crashes in user mode, its effect is limited to that particular program only. Therefore, programs in this mode are in a safe state.
When some privileged instructions, error handling, exception handling, hardware access or other hardware related access needs to be invoked, the program switches from user mode to kernel mode.
Kernel mode allows programs to access memory and hardware directly. All privileged commands are executed only in kernel mode. If a program fails in kernel mode, the system will cease to function.
All the important library functions, subroutines, etc. are executed here only. The user has no involvement in this process, and the kernel uses the hardware to provide the requested service.
A program is initially in the user mode, but whenever it invokes a privileged command, the control is transferred from the user mode to the kernel mode. When the OS is completed with its work and the service has been provided, the kernel mode is switched back to the user mode, known as context switching.
A system call occurs whenever a program requires hardware access, performs an I/O operation or encounters an exception or interrupt. In other words, a system call occurs when a context switch takes place from user mode to kernel mode.
System programs are nothing more than special utility programs that provide a user-friendly environment in which the user can accomplish his desired tasks.
There are several types of system programs, including operating systems, interpreters, compilers, editors, etc. Several useful functions are provided by them to the user, such as compiling, editing, interrupt handling, memory management, etc. These functions are already defined and do not require the user to write any code for them.