×

Operating System Tutorial

Operating System Practice

System Calls: What It Is, Types

Last Updated : January 02, 2026

What is a System Call in Operating System?

A system call is a mechanism that allows a user program to request services from the operating system. It provides an interface between user-level applications and the kernel, enabling programs to perform operations such as file handling, process control, memory management, and input/output operations in a secure and controlled manner.

Interface Between User Programs and Operating System

The interface between the operating system and a user program is defined by a set of extended instructions provided by the operating system. These extended instructions are known as system calls. A user program communicates with the operating system and requests services by making system calls.

System Calls

Role of Library Procedures

For each system call, there exists a corresponding library procedure that a user program can call. These procedures place the system call parameters in a specified location, such as machine registers, and then issue a TRAP instruction to transfer control to the operating system.

Execution of a System Call

When the operating system gains control after the TRAP instruction, it checks whether the parameters are valid. If valid, it performs the requested operation. After completing the task, the operating system places a status code in a register indicating success or failure and executes a RETURN FROM TRAP instruction to return control to the library procedure, which then returns the result to the user program.

Error Handling Using System Calls

Any operation performed in the system requires system calls. If an error occurs, additional system calls are used to handle it. For example, if a program tries to open a file that does not exist, the system call handles the error and displays an appropriate message on the console.

System Calls and Assembly Language

System calls are callable from assembly language. Phrases like “assembly language under DOS” mean that the programmer must know both the machine’s instruction set and the system calls provided by the operating system.

System Calls in High-Level Languages

Many high-level languages such as C allow system calls to be explicitly embedded within the program. However, languages like Java and C++ usually do not require explicit system calls. In such cases, the compiler automatically inserts system calls at appropriate places.

Mapping System Calls Across Operating Systems

Different operating systems may provide different system calls for similar operations such as fread, fwrite, or execute. The mapping between system calls of two operating systems is usually not straightforward. Before invoking the actual system call, the compiler generates preparatory machine instructions specific to the target operating system.

How Do System Calls Work?

A system call is a controlled mechanism that allows a user program to request services from the operating system. It acts as a bridge between user-level applications and the kernel.

When a user program needs to perform an operation such as file access, process creation, or memory allocation, it cannot directly access hardware. Instead, it uses a system call to safely request the operating system to perform the task.

Steps Involved in a System Call

  • The user program executes a system call instruction (for example, syscall or int 0x80).
  • The CPU switches from user mode to kernel mode to ensure secure execution.
  • The kernel identifies the system call number and performs the requested operation such as file handling, process management, or memory allocation.
  • After completing the operation, the kernel switches back to user mode.
  • The result of the operation (success, failure, or returned data) is passed back to the user program.

Why System Calls Are Important

Without system calls, each program would require its own method to access hardware resources, which would make systems insecure, inconsistent, and difficult to manage.System calls provide a standard and safe way to interact with the operating system.

System Calls vs Context Switching

System calls do not always cause a context switch. They mainly involve a mode switch from user mode to kernel mode.A context switch occurs only when the calling process is blocked, such as when waiting for input/output operations to complete.

What are the Types of System Calls?

System calls can be divided into five categories- process control, file management, device management, information management, and communication. Let's discuss each category in detail.

1. Process control

A process or the job which is currently run in the system always want to load and execute another program. The command interpreter executes a program for example when the user clicks on the mouse button. Now the question arises that when the loaded program terminates when the control return. When any new program terminates in the system the memory the currently running program must be saved. So in this way we can efficiently create a program which calls another program and both are running concurrently. For the multiprogramming, we have created jobs or process. So the system calls for this purpose is called create a process or submit the job. When a new job, process or the group of the process is created then we have to manage the execution of these process.

2. File management

In the file management system, we should be able to create or delete the files. For creating a file the system call requires the names of the file and some attribute of the files. When the file is created we should be able to open and use these files. We can also read-write or reposition the files. After all the work is done we need to close the file which indicates that the file is no longer need. We can also use these operations for directories also. In the file management system, we should be able to determine the values of various attributes for the file and directories. There are various file attributes like name, types, size, location, accounting information and so on. The two important system calls get attribute and file set attribute is required for this function.

3. Device management

When the program is running in the system it needs some resources such as memory, input, output, and so on. The resources are only granted when they are available and not held by another process. If the resources are not free the program has to wait for the resources. Files are the abstract or virtual devices. So there are many system calls which are needed for the files and also for the devices. If there are multiple users then first it requests for the devices and after finishing the work with these devices we should release it. When the devices are allocated to the user then we can perform different operations like reading, write and execute.

4. Information management

In information management, various system calls are used to communicate the information between the operating system and user program. For example, some system has a system call forget the current time or date. There are many another system call like for the number of the user, different versions of operating system., free space in memory etc.

5. Communication

There are mainly two models for communication. First is the message passing model in this the information is exchanged between the process and this communication facility is provided by the operating system. When the process wants to communicate first the other communicator should be know so that the communication is established and they can communicate. Second is the shared memory model in this model different process shared memory and communicate with each other.

System Calls Exercise

Select the correct option to complete each statement about system calls in an operating system.

  1. A system call is used by a user program to request ___ from the operating system.
  2. When a system call is executed, the CPU switches from user mode to ___.
  3. The instruction used to transfer control from a user program to the operating system is known as a ___.
  4. A context switch occurs during a system call only when the calling process is ___.


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.