Operating System

⌘K
  1. Home
  2. Docs
  3. Operating System
  4. Operating system Overview
  5. System Call and Handling of System Calls

System Call and Handling of System Calls

A system call is a mechanism that allows user-level processes to request services from the operating system’s kernel.

• System calls provide an essential interface between a process and the operating system.

• They enable processes to perform operations such as file manipulation, process control, communication, and more, by invoking functions provided by the kernel.

System calls can be categorized into several types based on their functionality:

  1. Process Control: It is a system calls that manage the creation, execution, and termination of processes, as well as operations like waiting for a process to finish, and altering a process’s priority.
    • fork(): Creates a new process.
    • exec(): Executes a new program in the current process.
    • exit(): Terminates a process.
    • wait(): Waits for a process to change state.
  2. File Management: It is a system calls that handle file operations, such as creating, opening, reading, writing, closing, and deleting files.
    • open(): Opens a file.
    • close(): Closes a file.
    • read(): Reads data from a file.
    • write(): Writes data to a file.
    • unlink(): Deletes a file.
  3. Device Management: It is a system calls that allow programs to interact with hardware devices, such as requesting access, releasing devices, reading from or writing to devices, and controlling device settings.
    • ioctl(): Controls device-specific operations.
    • read(), write(): Interact with device data.
  4. Information Maintenance: It is a system calls that provide functionality for retrieving or updating system information, such as time, date, system status, process attributes, and configuration settings.
    • getpid(): Gets the process ID.
    • gettimeofday(): Gets the current time.
    • sysinfo(): Retrieves system information.
  5. Communication: It is a system calls that facilitate inter-process communication (IPC), enabling data exchange between processes through mechanisms like pipes, shared memory, sockets, or message passing.
    • pipe(): Creates a pipe for inter-process communication.
    • shmget(), shmat(), shmdt(): Manage shared memory.
    • msgget(), msgsnd(), msgrcv(): Manage message queues.
    • socket(), bind(), listen(), accept(): Network communication.

Handling of system calls involves a series of steps that the operating system’s kernel undertakes to process requests from user-space applications for various services.

Here’s a detailed look at the steps involved:

  1. System Call Invocation

A user-space application requests a system service by invoking a system call, usually through a library function that interacts with the OS.

  1. Switch to kernel Mode

When a system call is invoked, The CPU switches from user mode to kernel mode to access protected resources safely. This switch is triggered by an interrupt or trap instruction.

  1. System Call Identification

The OS identifies the requested system call using a unique identifier passed by the application.

  1. Parameter Validation

The OS verifies the parameters passed with the system call to ensure they are valid and accessible, preventing errors and security issues.

  1. System Call Execution

The OS kernel executes the requested service, such as file access, memory allocation, or process control, as identified by the system call.

  1. Result Generation

After executing the call, the OS generates a result, which could be data, a status code, or a response to the user’s request.

  1. Switch back to User Mode

Once the system call completes, the CPU switches back from kernel mode to user mode, allowing the user application to continue.

  1. Error Handling

If an error occurs during the system call, the OS returns an error code or message, allowing the application to handle it appropriately.

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *