What is system call and why it is used?

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. The service may be a hardware-related service such as accessing a hard drive or the creation and execution of new processes. It provides an interface between a process and the operating system.

In this article, you will learn more about system calls and its types on a system.

When system calls are required

Some situations are given below where a system call is required –

  • Reading and writing from files
  • If a filesystem requires the creation or deletion of a file
  • Creation and management of new processes in a system
  • Network connections require system calls for sending and receiving packets
  • Access to a hardware service such as accessing the hard drive, printer, scanner, etc require a system call

Examples of system call on Unix like system

Some Linux/Unix system calls are read(), write(), send(), socket(), open(), close(), etc. When you try to write to a file using a program or read the input of a keyboard it requires a system call.

Types of system calls

Broadly we can divide system calls into six categories and these are given below.

Process control

This type of system calls deals with process creation and management.

Process control functions:

  • create a process (for example fork on Unix systems or NtCreateProcess in Windows)
  • terminate process
  • load and execute
  • get/set process attributes
  • wait and signal event
  • allocate and free memory

File management

The file management system calls are used to manipulate files for example creating, reading, writing a file, etc.

File management functions:

  • create a file
  • delete a file
  • open and close a file
  • read, write a file
  • get/set file attributes

Device management

These system calls are responsible for device manipulation for example reading and writing to a device buffer.

Device management functions are:

  • request device
  • release device
  • logically attach or detach a device
  • read write reposition
  • get/set device attributes

Information maintenance

These system calls are responsible for the information handling and its transfer between the operating system and user program.

Information maintenance function:

  • get/set system information such as time, date, computer name, etc
  • get/set process, file, or device metadata

Communication

These system calls are used specifically for interprocess communication.

The communication functions are:

  • Create delete communication connection
  • send receive messages
  • transfer status information
  • attach or detach remote devices

Protection

These system calls are responsible for the protection of files.

The protection functions are –

Important system calls in Unix-like and Windows OS

The system calls in Unix-like systems and their equivalent in Windows operating system are given below.

CategoryUnixWindows
Process controlfork()
exit()
wait()
CreateProcess()
ExitProcess()
WaitForSingleObject()
File managementopen()
read()
write()
close()
CreateFile()
ReadFile()
WriteFile()
CloseHandle()
Device managementioctl()
read()
write()
SetConsoleMode()
ReadConsole()
WriteConsole()
Information maintenancegetpid()
alarm()
sleep()
GetCurrentProcessID()
SetTimer()
Sleep()
Communicationpipe()
shm_open()
mmap()
CreatePipe()
CreateFileMapping()
MapViewOfFile()
Protectionchmod()
umask()
chown()
SetFileSecurity()
InitlializeSecurityDescriptor()
SetSecurityDescriptorGroup()

Leave a Comment