Kernel in Operating System
A kernel is the core part of an operating system. It acts as a bridge
between software applications and the hardware of a computer.
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
Facilitates communication between hardware and user
applications.
Ensures efficient and secure multitasking.
Manages system stability and prevents unauthorized resource
access.
Types of Kernel
The kernel manages the system’s resources and facilitates
communication between hardware and software components. These
kernels are of different types let’s discuss each type along with its
advantages and disadvantages:
1. Monolithic Kernel
It is one of the types of kernel where all operating system services
operate in kernel space. It has dependencies between systems
components. It has huge lines of code which is complex.
Example:
Unix, Linux, Open VMS, XTS-400 etc.
Advantages
Efficiency: Monolithic kernels are generally faster than other
types of kernels because they don’t have to switch between user
and kernel modes for every system call, which can cause
overhead.
Tight Integration: Since all the operating system services are
running in kernel space, they can communicate more efficiently
with each other, making it easier to implement complex
functionalities and optimizations.
Simplicity: Monolithic kernels are simpler to design, implement,
and debug than other types of kernels because they have a
unified structure that makes it easier to manage the code.
Lower latency: Monolithic kernels have lower latency than other
types of kernels because system calls and interrupts can be
handled directly by the kernel.
Disadvantages
Stability Issues: Monolithic kernels can be less stable than
other types of kernels because any bug or security vulnerability in
a kernel service can affect the entire system.
Security Vulnerabilities: Since all the operating system
services are running in kernel space, any security vulnerability in
one of the services can compromise the entire system.
Maintenance Difficulties: Monolithic kernels can be more
difficult to maintain than other types of kernels because any
change in one of the services can affect the entire system.
Limited Modularity: Monolithic kernels are less modular than
other types of kernels because all the operating system services
are tightly integrated into the kernel space. This makes it harder
to add or remove functionality without affecting the entire
system.
2. Micro Kernel
It is kernel types which has minimalist approach. It has virtual
memory and thread scheduling. Micro Kernel is more stable with
less services in kernel space. It puts rest in user space. It is use in
small os.
Example :
Mach, L4, AmigaOS, Minix, K42 etc.
Advantages
Reliability: Microkernel architecture is designed to be more
reliable than monolithic kernels. Since most of the operating
system services run outside the kernel space, any bug or security
vulnerability in a service won’t affect the entire system.
Flexibility : Microkernel architecture is more flexible than
monolithic kernels because it allows different operating system
services to be added or removed without affecting the entire
system.
Modularity: Microkernel architecture is more modular than
monolithic kernels because each operating system service runs
independently of the others. This makes it easier to maintain and
debug the system.
Portability: Microkernel architecture is more portable than
monolithic kernels because most of the operating system services
run outside the kernel space. This makes it easier to port the
operating system to different hardware architectures.
Disadvantages
Performance: Microkernel architecture can be slower than
monolithic kernels because it requires more context switches
between user space and kernel space.
Complexity: Microkernel architecture can be more complex than
monolithic kernels because it requires more communication
and synchronization mechanisms between the different operating
system services.
Development Difficulty: Developing operating systems based
on microkernel architecture can be more difficult than developing
monolithic kernels because it requires more attention to detail in
designing the communication and synchronization mechanisms
between the different services.
Higher Resource Usage: Microkernel architecture can use more
system resources, such as memory and CPU, than monolithic
kernels because it requires more communication and
synchronization mechanisms between the different operating
system services.
3. Hybrid Kernel
It is the combination of both monolithic kernel and microkernel. It
has speed and design of monolithic kernel and modularity and
stability of microkernel.
Example :
Windows NT, Netware, BeOS etc.
Advantages
Performance: Hybrid kernels can offer better performance than
microkernels because they reduce the number of context
switches required between user space and kernel space.
Reliability: Hybrid kernels can offer better reliability than
monolithic kernels because they isolate drivers and other kernel
components in separate protection domains.
Flexibility: Hybrid kernels can offer better flexibility than
monolithic kernels because they allow different operating system
services to be added or removed without affecting the entire
system.
Compatibility: Hybrid kernels can be more compatible than
microkernels because they can support a wider range of device
drivers.
Disadvantages
Complexity: Hybrid kernels can be more complex than
monolithic kernels because they include both monolithic and
microkernel components, which can make the design and
implementation more difficult.
Security: Hybrid kernels can be less secure than microkernels
because they have a larger attack surface due to the inclusion of
monolithic components.
Maintenance: Hybrid kernels can be more difficult to maintain
than microkernels because they have a more complex design and
implementation.
Resource Usage: Hybrid kernels can use more system resources
than microkernels because they include both monolithic and
microkernel components.
4. Exo Kernel
It is the type of kernel which follows end-to-end principle. It has
fewest hardware abstractions as possible. It allocates physical
resources to applications.
Example :
Nemesis, ExOS etc.
Advantages
Flexibility: Exokernels offer the highest level of flexibility,
allowing developers to customize and optimize the operating
system for their specific application needs.
Performance: Exokernels are designed to provide better
performance than traditional kernels because they eliminate
unnecessary abstractions and allow applications to directly
access hardware resources.
Security: Exokernels provide better security than traditional
kernels because they allow for fine-grained control over the
allocation of system resources, such as memory and CPU time.
Modularity: Exokernels are highly modular, allowing for the easy
addition or removal of operating system services.
Disadvantages
Complexity: Exokernels can be more complex to develop than
traditional kernels because they require greater attention to
detail and careful consideration of system resource allocation.
Development Difficulty: Developing applications for exokernels
can be more difficult than for traditional kernels because
applications must be written to directly access hardware
resources.
Limited Support: Exokernels are still an emerging technology
and may not have the same level of support and resources as
traditional kernels.
Debugging Difficulty: Debugging applications and operating
system services on exokernels can be more difficult than on
traditional kernels because of the direct access to hardware
resources.
5. Nano Kernel
It is the type of kernel that offers hardware abstraction but without
system services. Micro Kernel also does not have system services
therefore the Micro Kernel and Nano Kernel have become
analogous.
Example :
EROS etc.
Advantages
Small Size: Nanokernels are designed to be extremely small,
providing only the most essential functions needed to run the
system. This can make them more efficient and faster than other
kernel types.
High Modularity: Nanokernels are highly modular, allowing for
the easy addition or removal of operating system services,
making them more flexible and customizable than traditional
monolithic kernels.
Security: Nanokernels provide better security than traditional
kernels because they have a smaller attack surface and a
reduced risk of errors or bugs in the code.
Portability: Nanokernels are designed to be highly portable,
allowing them to run on a wide range of hardware architectures.
Disadvantages
Limited Functionality: Nanokernels provide only the most
essential functions, making them unsuitable for more complex
applications that require a broader range of services.
Complexity: Because nanokernels provide only essential
functionality, they can be more complex to develop and maintain
than other kernel types.
Performance: While nanokernels are designed for efficiency,
their minimalist approach may not be able to provide the same
level of performance as other kernel types in certain situations.
Compatibility: Because of their minimalist design, nanokernels
may not be compatible with all hardware and software
configurations, limiting their practical use in certain contexts.
Functions of Kernel
The kernel is responsible for various critical functions that ensure
the smooth operation of the computer system. These functions
include:
1. Process Management
Scheduling and execution of processes.
Context switching between processes.
Process creation and termination.
2. Memory Management
Allocation and deallocation of memory space.
Managing virtual memory.
Handling memory protection and sharing.
3. Device Management
Managing input/output devices.
Providing a unified interface for hardware devices.
Handling device driver communication.
4. File System Management
Managing file operations and storage.
Handling file system mounting and unmounting.
Providing a file system interface to applications.
5. Resource Management
Managing system resources (CPU time, disk space, network
bandwidth)
Allocating and deallocating resources as needed
Monitoring resource usage and enforcing resource limits
6. Security and Access Control
Enforcing access control policies.
Managing user permissions and authentication.
Ensuring system security and integrity.
7. Inter-Process Communication
Facilitating communication between processes.
Providing mechanisms like message passing and shared memory.
Working of Kernel
A kernel loads first into memory when an operating system is
loaded and remains in memory until the operating system is shut
down again. It is responsible for various tasks such as disk
management , task management, and memory management .
The kernel has a process table that keeps track of all active
processes
The process table contains a per-process region table whose
entry points to entries in the region table.
The kernel loads an executable file into memory during the ‘exec’
system call’.
It decides which process should be allocated to the processor to
execute and which process should be kept in the main memory to
execute. It basically acts as an interface between user
applications and hardware. The major aim of the kernel is to
manage communication between software i.e. user-level
applications and hardware i.e., CPU and disk memory.
Objectives of Kernel
To establish communication between user-level applications and
hardware.
To decide the state of incoming processes.
To control disk management.
To control memory management.
To control task management.
Conclusion
Kernels are the heart of operating systems , managing how
hardware and software communicate and ensuring everything runs
smoothly. Different types of kernels—like monolithic, microkernels,
hybrid kernels, and others—offer various ways to balance
performance, flexibility, and ease of maintenance. Understanding
these kernel types helps us appreciate how operating systems work
and how they handle the complex tasks required to keep our
computers and devices running efficiently. Each type of kernel has
its own strengths and weaknesses, but all play a crucial role in the
world of computing.
Frequently Asked Questions on Kernel – FAQs
What are the main functions of a kernel?
The main functions of a kernel include process management,
memory management, device management, and system calls
handling.
What is a monolithic kernel?
A monolithic kernel is a single large process running entirely in a
single address space, containing all core services like process
management, memory management, file systems, and device
drivers.
What is a microkernel?
A microkernel is a minimalistic kernel that includes only essential
functions such as inter-process communication and basic memory
management, with other services running in user space.
What is a hybrid kernel?
A hybrid kernel combines aspects of both monolithic and
microkernels, running some services in kernel space and others in
user space, to balance performance and modularity.
What is Kernel Panics?
A kernel panic is a safety measure taken by an operating system’s
kernel when it encounters a critical error or fault from which it
cannot safely recover. It indicates that the system has reached an
unrecoverable state, often due to hardware malfunctions, corrupted
drivers, or software bugs.
Introduction of System Call
A system call is a programmatic way in which a computer program
requests a service from the kernel of the operating system it is
executed on. A system call is a way for programs to interact with
the operating system. A computer program makes a system call
when it requests the operating system’s kernel. System
call provides the services of the operating system to the user
programs via the Application Program Interface(API). System calls
are the only entry points into the kernel system and are executed in
kernel mode.
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.
Services Provided by System Calls
Process Creation and Management
Main Memory Management
File Access, Directory, and File System Management
Device Handling(I/O)
Protection
Networking, etc.
o Process Control: end, abort, create, terminate, allocate,
and free memory.
o File Management: create, open, close, delete, read
files, etc.
o Device Management
o Information Maintenance
o Communication
Features of System Calls
Interface: System calls provide a well-defined interface between
user programs and the operating system. Programs make
requests by calling specific functions, and the operating system
responds by executing the requested service and returning a
result.
Protection: System calls are used to access privileged
operations that are not available to normal user programs. The
operating system uses this privilege to protect the system from
malicious or unauthorized access.
Kernel Mode: When a system call is made, the program is
temporarily switched from user mode to kernel mode. In kernel
mode, the program has access to all system resources, including
hardware, memory, and other processes.
Context Switching: A system call requires a context switch,
which involves saving the state of the current process and
switching to the kernel mode to execute the requested service.
This can introduce overhead, which can impact system
performance.
Error Handling: System calls can return error codes to indicate
problems with the requested service. Programs must check for
these errors and handle them appropriately.
Synchronization: System calls can be used to synchronize
access to shared resources, such as files or network connections.
The operating system provides synchronization mechanisms,
such as locks or semaphores, to ensure that multiple programs
can access these resources safely.
How does System Call Work?
Here is a detailed explanation step by step how system calls work:
Users need special resources: Sometimes programs need to
do some special things that can’t be done without the permission
of the OS like reading from a file, writing to a file, getting any
information from the hardware, or requesting a space in memory.
The program makes a system call request: There are special
predefined instructions to make a request to the operating
system. These instructions are nothing but just a “system call”.
The program uses these system calls in its code when needed.
Operating system sees the system call: When the OS sees
the system call then it recognizes that the program needs help at
this time so it temporarily stops the program execution and gives
all the control to a special part of itself called ‘Kernel’. Now
‘Kernel’ solves the need of the program.
The operating system performs the operations: Now the
operating system performs the operation that is requested by the
program. Example: reading content from a file etc.
Operating system give control back to the program : After
performing the special operation, OS give control back to the
program for further execution of program.
Types of System Calls
Services provided by an OS are typically related to any kind of
operation that a user program can perform like creation,
termination, forking, moving, communication, etc. Similar types of
operations are grouped into one single system call category. System
calls are classified into the following categories:
read more about – Different Types of System Calls in OS
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()
GetCurrentProcessID() Getpid()
Information
SetTimer() Alarm()
Maintenance
Sleep() Sleep()
CreatePipe() Pipe()
Communication CreateFileMapping() Shmget()
MapViewOfFile() Mmap()
SetFileSecurity() Chmod()
Protection InitializeSecurityDescriptor() Umask()
SetSecurityDescriptorgroup() Chown()
Open(): Accessing a file on a file system is possible with the open()
system call. It gives the file resources it needs and a handle the
process can use. A file can be opened by multiple processes
simultaneously or just one process. Everything is based on the
structure and file system.
Read(): Data from a file on the file system is retrieved using it. In
general, it accepts three arguments:
A description of a file.
A buffer for read data storage.
How many bytes should be read from the file
Before reading, the file to be read could be identified by its file
descriptor and opened using the open() function.
Wait(): In some systems, a process might need to hold off until
another process has finished running before continuing. When a
parent process creates a child process, the execution of the parent
process is halted until the child process is complete. The parent
process is stopped using the wait() system call. The parent process
regains control once the child process has finished running.
Write(): Data from a user buffer is written using it to a device like a
file. A program can produce data in one way by using this system
call. generally, there are three arguments:
A description of a file.
A reference to the buffer where data is stored.
The amount of data that will be written from the buffer in bytes.
Fork(): The fork() system call is used by processes to create copies
of themselves. It is one of the methods used the most frequently in
operating systems to create processes. When a parent process
creates a child process, the parent process’s execution is suspended
until the child process is finished. The parent process regains control
once the child process has finished running.
Exit(): A system call called exit() is used to terminate a program. In
environments with multiple threads, this call indicates that the
thread execution is finished. After using the exit() system function,
the operating system recovers the resources used by the process.
Methods to Pass Parameters to OS
If a system call occur, we have to pass parameter to the Kernal part
of the Operating system.
For example look at the given open() system call:
1
//function call example
2
3
#include <fcntl.h>
4
5
int open(const char *pathname, int flags, mode_t mode);
Here pathname, flags and mode_t are the parameters.
So it is to be noted that :
We can’t pass the parameters directly like in an ordinary function
call.
In Kernal mode there is a different way to perform a function call.
So we can’t run it in the normal address space that the process had
already created and hence we cant place the parameters in the top
of the stack because it is not available to the Kernal of the operating
system for processing. so we have to adopt any other methods to
pass the parameters to the Kernal of the OS.
We can done it through,
Passing parameters in registers
Address of the block is passed as a parameter in a
register.
Parameters are pushed into a stack.
Let us discuss about each points in detail:
1. Passing Parameters in Registers
It is the simplest method among the three
Here we directly pass the parameters to registers.
But it will it is limited when, number of parameters are greater
than the number of registers.
Here is the C program code:
1
// Passing parameters in registers.
2
3
#include <fcntl.h>
4
#include <stdio.h>
5
6
int main()
7
{
8
const char* pathname = "example.txt";
9
int flags = O_RDONLY;
10
mode_t mode = 0644;
11
12
int fd = open(pathname, flags, mode);
13
// in function call open(), we passed the parameters pathanme,flags,mode
to the kernal directly
14
15
if (fd == -1) {
16
perror("Error opening file");
17
return 1;
18
}
19
20
// File operations here...
21
22
close(fd);
23
return 0;
24
}
2. Address of The Block is Passed as Parameters
It can be applied when the number of parameters are greater
than the number of registers.
Parameters are stored in blocks or table.
The address of the block is passed to a register as a parameter.
Most commonly used in Linux and Solaris.
Here is the C program code:
1
//Address of the block is passed as parameters
2
3
#include <stdio.h>
4
#include <fcntl.h>
5
6
int main() {
7
const char *pathname = "example.txt";
8
int flags = O_RDONLY;
9
mode_t mode = 0644;
10
11
int params[3];
12
// Block of data(parameters) in array
13
params[0] = (int)pathname;
14
params[1] = flags;
15
params[2] = mode;
16
17
int fd = syscall(SYS_open, params);
18
// system call
19
20
if (fd == -1) {
21
perror("Error opening file");
22
return 1;
23
}
24
25
// File operations here...
26
27
close(fd);
28
return 0;
29
}
3. Parameters Are Pushed in a Stack
In this method parameters can be pushed in using the program
and popped out using the operating system
So the Kernal can easily access the data by retrieving information
from the top of the stack.
Here is the C program code
1
//parameters are pushed into the stack
2
3
#include <stdio.h>
4
#include <fcntl.h>
5
#include <unistd.h>
6
7
int main() {
8
const char *pathname = "example.txt";
9
int flags = O_RDONLY;
10
mode_t mode = 0644;
11
12
int fd;
13
asm volatile(
14
"mov %1, %%rdi\n"
15
"mov %2, %%rsi\n"
16
"mov %3, %%rdx\n"
17
"mov $2, %%rax\n"
18
"syscall"
19
: "=a" (fd)
20
: "r" (pathname), "r" (flags), "r" (mode)
21
: "%rdi", "%rsi", "%rdx"
22
);
23
24
if (fd == -1) {
25
perror("Error opening file");
26
return 1;
27
}
28
29
// File operations here...
30
31
close(fd);
32
return 0;
33
}
Advantages of System Calls
Access to Hardware Resources: System calls allow programs
to access hardware resources such as disk drives, printers, and
network devices.
Memory Management: System calls provide a way for
programs to allocate and deallocate memory, as well as access
memory-mapped hardware devices.
Process Management: System calls allow programs to create
and terminate processes, as well as manage inter-process
communication.
Security: System calls provide a way for programs to access
privileged resources, such as the ability to modify system settings
or perform operations that require administrative permissions.
Standardization: System calls provide a standardized interface
for programs to interact with the operating system, ensuring
consistency and compatibility across different hardware platforms
and operating system versions.
Disadvantages of System Call
Performance Overhead: System calls involve switching
between user mode and kernel mode, which can slow down
program execution.
Security Risks: Improper use or vulnerabilities in system calls
can lead to security breaches or unauthorized access to system
resources.
Error Handling Complexity: Handling errors in system calls,
such as resource allocation failures or timeouts, can be complex
and require careful programming.
Compatibility Challenges: System calls may vary between
different operating systems, requiring developers to write code
that works across multiple platforms.
Resource Consumption: System calls can consume significant
system resources, especially in environments with many
concurrent processes making frequent calls.
Conclusion
In conclusion, system calls are a important part of how computer
programs interact with the operating system. They provide a way for
applications to request services from the OS, such as accessing files,
managing memory, or communicating over networks. System calls
act as a bridge between user-level programs and the low-level
operations handled by the operating system kernel. Understanding
system calls is essential for developers to create efficient and
functional software that can leverage the full capabilities of the
underlying operating system.
Frequently Asked Questions on System Call
in Operating Systems – FAQs
How does a system call work?
When a program executes a system call, it transitions from user
mode to kernel mode, which is a higher privileged mode. The
transition is typically initiated by invoking a specific function or
interrupting instruction provided by the programming language or
the operating system.
Once in kernel mode, the system call is handled by the operating
system. The kernel performs the requested operation on behalf of
the program and returns the result. Afterward, control is returned to
the user-level program, which continues its execution.
Why do programs need to use system calls?
Programs use system calls to interact with the underlying operating
system and perform essential tasks that require privileged access or
system-level resources.
What are some examples of system calls?
Examples include opening and closing files, reading and writing
data, creating processes, allocating memory, and performing
network operations like sending and receiving data.
Why are system calls necessary?
System calls are necessary as they enable applications to request
essential services from the operating system, such as file access,
memory management, and hardware control, ensuring secure and
efficient interaction with computer resources.
Privileged and Non-Privileged Instructions in
Operating System
Last Updated : 08 Aug, 2024
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.
What are Privileged Instructions?
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. Privileged Instructions possess the following
characteristics:
If any attempt is made to execute a Privileged Instruction in User
Mode, then it will not be executed and treated as an illegal
instruction. The Hardware traps it in the Operating System.
Before transferring the control to any User Program, it is the
responsibility of the Operating System to ensure that
the Timer is set to interrupt. Thus, if the timer interrupts then the
Operating System regains control.
Thus, any instruction which can modify the contents of the Timer
is Privileged Instruction.
Privileged Instructions are used by the Operating System to
achieve correct operation.
Various examples of Privileged Instructions include:
o I/O instructions and Halt instructions
o Turn off all Interrupts
o Set the Timer
o Context Switching
o Clear the Memory or Remove a process from the Memory
o Modify entries in the Device-status table
Role of OS in managing Privileged
Instructions
Access control: The operating system employs access control
mechanisms to limit access to privileged instructions. These
mechanisms are restricted to authorized processes or users with
elevated privileges. This guarantees that privileged instructions
can only be executed by trusted processes and thwarts
unauthorized access of malicious programs to system resources.
Memory protection: By deploying memory protection
techniques, the operating system restricts processes from
accessing any memory location that belongs to it or other
processes. This aids in preventing tampering with the operating
system or other processes by ensuring that processes cannot do
so. Furthermore, it hinders malevolent programs from resulting in
system crashes or risking the system’s safety.
Interrupt handling: The execution of privileged instructions like
system calls or exceptions is handled by the operating system
through interrupt handling to ensure safety and accuracy, so
when an interrupt occurs during the execution of a process it’s
necessary to save its state before transferring control to a
suitable handler and then restoring it on completion.
Virtualization: Using virtualization techniques allows the
operating system to create a simulated environment where
processes can execute privileged instructions without having
direct access to the underlying hardware thus creating a more
secure and isolated execution environment for privileged
instructions by limiting process access to authorized hardware
resources only.
What are Non-Privileged Instructions?
Non-privileged instructions are those that can be executed by any
process, including user-level processes. These instructions are
typically used for performing computations, accessing user-level
resources such as files and memory, and managing process control.
Non-privileged instructions are executed in user mode, which
provides limited access to system resources and ensures that
processes cannot interfere with one another. The Instructions that
can run only in User Mode are called Non-Privileged Instructions .
Various examples of Non-Privileged Instructions include:
Reading the status of Processor
Reading the System Time
Generate any Trap Instruction
Sending the final printout of Printer
Also, it is important to note that in order to change the mode from
Privileged to Non-Privileged, we require a Non-privileged Instruction
that does not generate any interrupt.
Differences Between Privileged and Non-
Privileged Instructions
Criteria Privileged Instructions Non-Privileged Instructions
Access to Limited access to system
Direct access to system resources
Resources resources
Execution
Executed in kernel mode Executed in user mode
Mode
Execution Require special permissions to Do not require special
Permissions execute permissions to execute
Used for performing low-level Used for general-purpose
Purpose
system operations computing
Higher risk of causing system Less risky in terms of system
Risks
crashes or security vulnerabilities crashes or security vulnerabilities
Advantages of Privileged and Non-Privileged
Instructions
Security: This ensures that unauthorized persons do not access
resources of their system. The operating system or other trusted
processes can only execute privileged instructions while user
programs can run non-privileged instructions.
Performance: This reduces overhead and latency by allowing
them to access hardware resources directly.
Stability: Non-privileged instructions are limited in accessing
system resources while privileged instructions can only be
executed by trusted processes. The distinction between user
programs and critical system functions keeps any harm caused
by the user program at bay.
Flexibility: Operating systems support a variety of applications
and hardware devices because they have both types of
instructions. Developers find it easy to create new applications
and hardware through an interface defined within the operating
system for compatibility purposes.
Debugging: With a clear demarcation between trusted and
untrusted processes, this makes it easier to debug the operating
system itself plus the applications running on top of it. To resolve
issues, developers must identify them first which is made possible
through this separation.
Disadvantages of Privileged and Non-
Privileged Instructions
Overhead: Instructions that are either privileged or non-
privileged can have an impact on overhead as well as
performance degradation. Changes between the two modes,
privileged and non-privileged ones, may take long time causing
the system performance to drop.
Complexity: Operating systems using such instructions with
distinct access levels (privileged or non-privileged) become
extremely complex and challenging to develop and maintain. The
necessity of both types of instructions makes it even harder to
design system features and ensure system stability.
Compatibility: Privileged and non-privileged instructions may
bring compatibility problems among different hardware platforms
or operating systems. Diverse implementations of privileged
instructions make it hard for creation of applications working on
various platforms.
Vulnerabilities: These resources are targeted by attackers who
exploit security flaws in the operating system.
Conclusion
Privileged instructions are used by the operating system kernel and
privileged processes to perform low-level system operations, while
non-privileged instructions are used by user-level processes for
general-purpose computing. The distinction between privileged and
non-privileged instructions is an important mechanism for ensuring
the security and stability of an operating system.
Frequently Asked Questions on Privileged
and Non-Privileged Instructions – FAQs
What do privileged instructions run under?
Privileged instructions only run in kernel mode.
Is reading the clock a privileged instruction?
Non-privileged because it’s how applications invoke system calls.
Is HLT a Non-privileged instruction?
No. HLT(Halt) is a Privileged instruction.
What is the mode bit of a privileged set of
instructions?
The K (kernel-mode) bit indicates whether the processor is in
privileged mode or user mode