Kernel in Operating System
A Kernel is a computer program that is the heart and core of an Operating System. It acts as a
bridge between software applications and the hardware of a computer. Whenever a system starts,
the Kernel is the first program that is loaded after the bootloader because the Kernel has to handle
the rest of the thing of the system for the Operating System.
• The kernel manages system resources, such as the CPU, memory, and devices, ensuring
everything works together smoothly and efficiently.
• It handles tasks like running programs, accessing files, and connecting to devices like
printers and keyboards.
• An Operating System includes the kernel as its core, but also provides a user interface, file
system management, network services, and various utility applications that allow users to
interact with the system
Kernel (Operating System)
• Facilitates communication between hardware and user applications.
• Ensures efficient and secure multitasking.
• Manages system stability and prevents unauthorized resource access.
system call
A system call is a mechanism that provides the interface between a process and the operating system. It
is a programmatic method in which a computer program requests a service from the kernel of the OS.
When a process makes a request to the Kernel, then it is called System Call.
• A user program can interact with the operating system using a system call. A number of
services are requested by the program, and the OS responds by launching a number of
systems calls to fulfill the request.
• A system call can be written in high-level languages like C or Pascal or in assembly
language. If a high-level language is used, the operating system may directly invoke system
calls, which are predefined functions.
• A system call is initiated by the program executing a specific instruction, which triggers a
switch to kernel mode, allowing the program to request a service from the OS. The OS then
handles the request, performs the necessary operations, and returns the result back to the
program.
• System calls are essential for the proper functioning of an operating system, as they provide
a standardized way for programs to access system resources. Without system calls, each
program would need to implement its methods for accessing hardware and system services,
leading to inconsistent and error-prone behavior.
Examples of a System Call in Windows and Unix
System calls for Windows and Unix come in many different forms. These are listed in the table below as
follows:
Process Windows Unix
CreateProcess() Fork()
Process Control ExitProcess() Exit()
WaitForSingleObject() Wait()
Open()
CreateFile()
Read()
File manipulation ReadFile()
Write()
WriteFile()
Close()
SetConsoleMode() Ioctl()
Device Management ReadConsole() Read()
WriteConsole() Write()
Process Windows Unix
GetCurrentProcessID() Getpid()
Information Maintenance SetTimer() Alarm()
Sleep() Sleep()
CreatePipe() Pipe()
Communication CreateFileMapping() Shmget()
MapViewOfFile() Mmap()
SetFileSecurity() Chmod()
Protection InitializeSecurityDescriptor() Umask()
SetSecurityDescriptorgroup() Chown()
Types of System Calls
There are mainly five types of system calls. These are explained in detail as follows −
Here are the types of system calls −
Process Control
These system calls deal with processes such as process creation, process termination etc.
File Management
These system calls are responsible for file manipulation such as creating a file, reading a file, writing into
a file etc.
Device Management
These system calls are responsible for device manipulation such as reading from device buffers, writing
into device buffers etc.
Information Maintenance
These system calls handle information and its transfer between the operating system and the user
program.
Communication
These system calls are useful for interprocess communication. They also deal with creating and deleting a
communication connection.
There are many different system calls as shown above. Details of some of those system calls are as follows
wait()
In some systems, a process may wait for another process to complete its execution. This happens when a
parent process creates a child process and the execution of the parent process is suspended until the child
process executes. The suspending of the parent process occurs with a wait() system call. When the child
process completes execution, the control is returned back to the parent process.
exec()
This system call runs an executable file in the context of an already running process. It replaces the
previous executable file. This is known as an overlay. The original process identifier remains since a new
process is not created but data, heap, stack etc. of the process are replaced by the new process.
fork()
Processes use the fork() system call to create processes that are a copy of themselves. This is one of the
major methods of process creation in operating systems. When a parent process creates a child process
and the execution of the parent process is suspended until the child process executes. When the child
process completes execution, the control is returned back to the parent process.
exit()
The exit() system call is used by a program to terminate its execution. In a multithreaded environment,
this means that the thread execution is complete. The operating system reclaims resources that were used
by the process after the exit() system call.
kill()
The kill() system call is used by the operating system to send a termination signal to a process that urges
the process to exit. However, kill system call does not necessary mean killing the process and can have
various meanings.
What are Privileged Instructions?
In an operating system, instructions executed by the CPU can be classified into privileged and non-
privileged instructions. These classifications help the operating system ensure security, stability, and
efficient resource management. In this article, we will discuss Privileged and Non-Privileged Instructions
in Operating Systems.
Privileged instructions are those that can only be executed by the operating system kernel or a privileged
process, such as a device driver. These instructions typically perform operations that require direct access
to hardware or other privileged resources, such as setting up memory mappings or accessing I/O devices.
The Instructions that can run only in Kernel Mode are called Privileged Instructions.
Dual Mode operations in OS
An error in one program can adversely affect many processes, it might modify data of another
program or also can affect the operating system. For example, if a process stuck in the infinite loop
then this infinite loop could affect the correct operation of other processes. So to ensure the proper
execution of the operating system, there are two modes of operation: User mode, and Kernel Mode.
User Mode: When the computer system is run by user applications like creating a text document
or using any application program, then the system is in user mode. When the user application
requests for a service from the operating system or an interrupt occurs or system call, then there
will be a transition from user to kernel mode to fulfill the requests.
Note: To switch from kernel mode to user mode, the mode bit should be 1.
Kernel Mode: When the system boots, the hardware starts in kernel mode and when the operating
system is loaded, it starts user application in user mode. To provide protection to the hardware, we
have privileged instructions which execute only in kernel mode. If the user attempts to run
privileged instruction in user mode then it will treat instruction as illegal and traps to OS. Some of
the privileged instructions are:
1. Handling Interrupts
2. To switch from user mode to kernel mode.
3. Input-Output management.