System calls in an OS, or operating system, pertain to a mechanism that allows user-level programs to request services from the OS’s kernel. System calls act as intermediaries between applications and the kernel.

They can typically be found as assembly language instructions and are also included in the manuals used by assembly-level programmers. These system calls are needed for every process to interact with the kernel and properly use its services.

System calls provide the interface between the process and the operating system. In this blog, we will explore about the System calls in OS, discuss their types, features, importance, examples and more!

What are the system calls in an OS (operating system)?

A system call is a programmatic way in which a computer program requests a service from the kernel of the operating system on which it is executed.

This mechanism allows the program to call for a service, like reading from a file, without accessing system resources directly. System calls provide the operating system's services to user programs via the application program interface.

  • A system call can be written in a high-level language like C or Pascal or assembly language. If a high-level language is used, the operating system may directly invoke system calls, which are predefined functions.
  • A user program can interact with the operating system using a system call. When the program requests services, the OS responds by launching several system calls to fulfil the request.
  • The system call process is normally run in user mode until another System Call interrupts them. The system call is then carried out in kernel mode according to priority levels.
  • System calls are essential for an operating system's proper functioning, as they provide a standardised way for programs to access system resources.
  • Without system calls, each program would need to implement its own methods for accessing hardware and system services, leading to inconsistent and error-prone behaviour.

Examples of system calls

The most common system calls used on Unix os and other compliant os are as follows.

  • Open: Here, the open system call is used to open and create a file and specific file access mode permission.
  • Read and write: These system calls are used for reading data from and writing data to files.
  • Exec: After forking, a new program is loaded into the current process address space.
  • Exit: After a program is finished, the exit system call terminates and returns status to the parent process.

Services provided by system calls

System calls are the interface that allows user-level programs to request service from the operating system’s kernel. They give a wide range of functionalities, including process management, file system management, memory management, device handling, and network access.

  • Main memory management
  • File access, directory, and file system management
  • Device handling
  • Protection
  • Networking
  • Process control : end, abort, create, terminate, allocate, and free memory
  • File management: create, open, close, delete, read files, etc.
  • Device management
  • Information maintenance
  • Communication

Features of system calls

System calls are important for security, protection, and efficient resource management within a computer system. The following features indicate system calls. 

1. Interface for OS services

System calls act as an interface between users' programs and the operating system kernel, allowing applications to request services from the operating system, which has higher privileges. They give a well-defined set of functions that user programs can call to interact with the kernel. 

2. Protection and security

System calls are necessary for maintaining system security and preventing unauthorized access to sensitive resources. The operating system uses system calls to ensure access control, that only programs that are allowed can do certain tasks. For example, a user program cannot directly write to a file; it must use a system call like write() that is mediated by the kernel to allow proper permissions and security.

3. Error handling

When a system calls return error codes to indicate problems with the requested service. Programs must check for all these errors and solve them.

4. Context switching

System calls involve a context switch, which saves the current state of the running process and switches to the kernel to execute the requested services. 

5. Synchronization

System calls can be used to synchronize access to shared resources like files or network connections. The operating system provides synchronization mechanisms, such as locks or semaphores, to ensure that various programs can access these resources safely.

6. Kernel mode execution

When a system call is made, the program temporarily switches from user mode to kernel mode. Kernel mode gives the program access to all system resources, including hardware, memory, and other processes. This permits the kernel to perform the requested operation on behalf of the user program.

How does a system call work?

A system call is a request for a particular service or action made by user software to the operating system kernel. It is the method by which processes at the user level communicate with the kernel and gain access to hardware resources that are not immediately available to them.

It basically allows a program to request that the OS perform an action on its behalf. Here is a detailed, step-by-step description of how system calls work.

1. Users need special resources

Programs sometimes need to do some special thing 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 space in memory. 

2. The program makes a system call request 

Special predefined instructions to request the operating system. Instructions are nothing but just a “system call.” The program uses these system calls in its code when needed. 

3. System call

When the OS sees the system call, it recognises that the program requires help at this time. So, it temporarily pauses program execution and gives all the control to a special part of itself called the “kernel.” Now, the kernel solves the program's need.

4. Operating systems perform the operations

The operating system performs the operations needed by the programs, such as reading content from a file.

5. Operating systems give control back to the program

After performing the special operations, the OS gives control back to the program for further execution. 

Types of system calls

Services given by the OS are typically related to any kind of operation that a user program can perform like creation, termination, forking, moving, communication, etc..  Types of operations are grouped into a single system call category. There are mainly 5 types of system calls available 

1. Process control

Process control is a system call that directs processes. These system calls are responsible for file manipulation, like creating a file, reading a file, writing into a file, etc. When various programs are run simultaneously, the OS uses system calls to administer resources and schedule the processes. Process control basically manages all the processes that are part of the OS. 

  • Fork (): Creates a new process by duplicating the current process's parent. This call is made when a ss makes a copy of itself, and the parent process is halted temporarily until the child process finishes its execution.
  • Wait (): The primary purpose of this call is to ensure that the parent process doesn’t proceed further with its execution until all its child processes have finished their execution.
  • exit(): It simply terminates the current process.
  • Kill(): This call sends a signal to a specific process and has different purposes, including requesting it to quit voluntarily or force quit or reload configuration. 

2. File management

Many calls are associated with file management. When an application is supposed to open, read, write, or close a file, it relies on System calls to perform these operations. One of the fundamental functions of system calls is to manage files and directories. These operations are important for anything from word processing to gaming.

  • Open(): Opens a file for reading or writing. A file could be of any type, like text file, an audio file, etc.
  • Read(): Reads data from a file. Just after the file is opened through the open() system call, if some process wants to read the data from a file, then it will make a read()  system call.
  • Write(): Writes data to a file. When users make any kind of changes in a file and save it, that’s when this is called.
  • Close(): Closes a previously opened file.
  • Seek() : seek moves a file pointer within a file. This call is typically made when we, the users, try to read the data from a specific position in a file.

3. Device management

These system calls are responsible for manipulating devices, such as reading from device buffers and writing into device buffers. 

  • Devices might be required while a process is running, such as access to the file system, input and output devices, and main memory.
  • It can ask for a device and then release it once the task is complete.
  • To acquire or alter a specific device attribute.
  • To free a device from the processor that is currently running a command, the call can be made.

4. Information management

This type of system call is used to maintain the information about the system, like time and date. The system calls for information maintenance and moves data from the user program to the OS. The services offered by this type of Call are

  • Acquire the system time or date and the system time or date.
  • You can get the features of a specific OS process or a specific file on the system or on any attached system.
  • You can set the characteristics of specific OS processes or files on the system or on any attached system.

5. Communication

These system calls are useful for interprocess communication. They also deal with creating and deleting a communication connection. Communication system calls are used to have interprocess communication, such as sending or receiving messages, creating or deleting communication connections, transferring status information, etc.

Some of the examples of all the above types of system calls in Windows and Unix are given as follows. 

Types of system callsWindows Linux
Process controlCreateProcess()
ExitPrtypesocess()
Waitforsingleobject()
fork()
exit()
wait()
File Management CreateFile()
ReadFile()
WriteFile()
CloseHandle()
open()
read()
write()
close()
Device Management SetConsoleMode()
ReadConsole()
WriteConsole()
ioctl()
read()
write()
Information Maintenance GetCurrentProcessID()
SetTimer()
Sleep()
getpid()
alarm()
sleep()
Communication CreatePipe()
CreateFileMapping()
MapViewOfFile()
pipe()
shmget()
mmap()

Importance of system calls in the operating system 

System calls are important for operating systems, as they provide the interface between user-level programs and the kernel. They facilitate resource management, security, multitasking, and hardware interaction.  System calls allow programs to request services and perform necessary operations. In OSs, system calls are crucial for various resources.

1. Resource management

System calls allow methodical resource management within the computer and help allocate and manage memory. This in turn ensures that the program runs smoothly without consuming extra resources. This is important for multitasking and overall performance. 

2. Security

 System calls ensure that a program connot hinder with or acquire the memory of another program, increasing the overall security and stablity of your device.

3. Multitasking capabilities

System calls allow programs to interact with hardware devices like printers, scanners, and network interfaces. They also allow multiple programs to run simultaneously, improving productivity and facilitating application switching.

4. Enhanced control

System calls give a high level of control over your device's operations. They allow you to start and close processes, manage files, and perform various system-related tasks. 

5. Input/output operations

 System call allows communication with input and output devices. They also ensure that you use your keyboard, mouse, and screen effectively. 

6. Network and communication

System calls facilitate network communication between applications allowing tasks like data transfer, browsing the web, and sending emails. 

Advantages of System Calls

System calls act as an important bridge between programs and the operating system allowing a range of crucial functionalities. 

1. Access to hardware resources

System calls act as an important bridge between programs and the operating system, allowing a range of key functionalities. 

2. Process management

System calls allow programs to generate and terminate processes and manage inter-process communication.

3. Security

System calls allow a program to access privileged resources, such as the ability to modify system settings or program operations that require administrative permission. 

4. Memory mastery

System calls allows programs the ability to request and release memory, ensuring efficient resource allocation. They also facilitate access to hardware devices mapped directly into memory for seamless data transfer.

5. Standardization

No matter the hardware or operating system version, system calls provide a consistent interface for programs to interact with the underlying environment. This promotes compatibility and smooths development across various platforms. 

FAQ's

👇 Instructions

Copy and paste below code to page Head section

A system call acts like a request to the operating system from a program or software to perform tasks reserved for the OS. Various tasks could range from file operations to process control, communication, services, and hardware device management.

There are five types of System calls: process control, file management, device management, information maintenance, and communications.

An operating system is system software that manages computer hardware and software resources and provides common services for computer programs.

A system call is a request for a service that a program makes to the kernel. The service is generally something that only the kernel has the privilege to do, like doing i/o.

In an operating system (OS), a thread is a lightweight unit of execution within a process. A process can have multiple threads, and these threads can run concurrently, sharing the same resources like memory and files within the process.

The full form of BIOS is basic input/output system, a program a computer microprocessor uses to begin the computer system after it is powered on.

Ready to Master the Skills that Drive Your Career?
Avail your free 1:1 mentorship session.
Thank you! A career counselor will be in touch with you shortly.
Oops! Something went wrong while submitting the form.
Join Our Community and Get Benefits of
💥  Course offers
😎  Newsletters
⚡  Updates and future events
undefined
undefined
Ready to Master the Skills that Drive Your Career?
Avail your free 1:1 mentorship session.
Thank you! A career counselor will be in touch with
you shortly.
Oops! Something went wrong while submitting the form.
Get a 1:1 Mentorship call with our Career Advisor
Book free session
a purple circle with a white arrow pointing to the left
Request Callback
undefined
a phone icon with the letter c on it
We recieved your Response
Will we mail you in few days for more details
undefined
Oops! Something went wrong while submitting the form.
undefined
a green and white icon of a phone