What Are System Calls in Operating System
What Are System Calls in Operating System
To understand system calls, first one needs to understand the difference between kernel
mode and user mode of a CPU. Every modern operating system supports these two modes.
Kernel Mode
• When CPU is in kernel mode, the code being executed can access any memory
address and any hardware resource.
• Hence kernel mode is a very privileged and powerful mode.
• If a program crashes in kernel mode, the entire system will be halted.
User Mode
• When CPU is in user mode, the programs don't have direct access to memory and
hardware resources.
• In user mode, if any program crashes, only that particular program is halted.
• That means the system will be in a safe state even if a program in user mode crashes.
• Hence, most programs in an OS run in user mode.
System calls:
The interface between a process and an operating system is provided by system calls. In
general, system calls are available as assembly language instructions. They are also included
in the manuals used by the assembly level programmers. System calls are usually made when
a process in user mode requires access to a resource. Then it requests the kernel to provide
the resource via a system call.
• If a file system requires the creation or deletion of files. Reading and writing from
files also require a system call.
• Creation and management of new processes.
• Network connections also require system calls. This includes
includes sending and receiving
packets.
• Access to a hardware devices such as a printer, scanner etc. requires a system call.
Application
on developers often do not have direct access to the system calls, but can access
them through an application programming interface (API). The functions that are
included in the API invoke the actual system calls. By using the API, certain benefits
can be gained:
• Portability: as long a system supports an API, any program using that API can
compile and run.
• Ease of Use: using the API can be significantly easier than using the actual system
call.
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.
• Message-passing
passing uses a common mailbox to pass messages between processes.
• Shared memory use certain system calls to create and gain access to create and gain
access to regions of memory owned by other processes. The two processes
processes exchange
information by reading and writing in the shared data.
System calls can be grouped roughly into six major
categories:
1. Process control
o create process (for example, fork on Unix-like systems, or NtCreateProcess
in the Windows NT Native API)
o terminate process
o load, execute
o get/set process attributes
o wait for time, wait event, signal event
o allocate and free memory
2. File management
o create file, delete file
o open, close
o read, write, reposition
o get/set file attributes
3. Device management
o request device, release device
o read, write, reposition
o get/set device attributes
o logically attach or detach devices
4. Information maintenance
o get/set time or date
o get/set system data
o get/set process, file, or device attributes
5. Communication
o create, delete communication connection
o send, receive messages
o transfer status information
o attach or detach remote devices
6. Protection
o get/set file permissions
Some of the examples of all the above types of system calls in Windows and UNIX are given
as follows:
WaitForSingleObject() wait()
CreateFile() open()
ReadFile() read()
File Management
WriteFile() write()
CloseHandle() close()
SetConsoleMode() ioctl()
WriteConsole() write()
GetCurrentProcessID() getpid()
Sleep() sleep()
CreatePipe() pipe()
MapViewOfFile() mmap()
The Kernel is the heart of the system – a collection of programs mostly written in C that
directly communicate with the hardware. There is only one kernel for any system. It’s the
part of Linux that is loaded into memory when the system is booted. The kernel isolates itself
from the user programs, and these programs are independent of the hardware they use, it is
easy to move them across different systems. Programs, therefore, must not have knowledge
of the devices they use. The kernel, in traditional parlance, is often called the Operating
System.
• Memory Management
• Process Management
• Disk and File System Management
• Networking
• Security
• Graphical User Interface (GUI)
• Device Driver Management
The Shell, on the other hand, is the “Sleeping Beauty” of Linux. It is actually the interface
between the user and the kernel that effectively insulates the user from knowledge of kernel
functions. The shell is the agency which takes care of the features of redirection with the ‘ > ‘
and ‘ | ‘ symbols. It also has a programming capability of its own.
b. Command aliasing
Gives an alias name to a command or phrase. When the shell encounters an alias on the
command line or in a shell script, it substitutes the text to which the alias refers.
c. Command history
Records the commands you enter in a history file. You can use this file to easily access,
modify, and reissue any listed command.
f. Piping
Links any number of commands together to form a complex program. The standard output of
one program becomes the standard input of the next.