What is a System Call?

A system call is a way through which the CPU can access the kernel mode from the user mode. There are different types of system calls to perform different tasks. When a System Call is generated, the CPU switches from user mode to kernel mode to perform that particular task and returns to user mode again. That is why these two modes are also called CPU execution modes.

There are some systems calls like

  • PRINTF in C language
  • CreateFile(),ReadFile(), WriteFile() and CloseHandle() in file management

As we know, Processes run in user mode by CPU until the system call occurs. When it occurs, then the control of the CPU shifts to kernel mode.

Let’s Explain with an example: When we use the translator of C language and put a command like “PRINTF,” this command will first check in the Standard Library of that program. If that particular command exists in Standard Library, then that command moves to System Call Handler in Kernel Mode. Otherwise, an invalid system call message will appear without going to Kernel mode. The explanation is given under the diagram

Importance

If applications go to directly read and write to the kernel space then system stability and security will be gone because there will be no restriction for any user to access the protected area. So, Kernel mode is the basic need.

Purpose

System calls are mostly used when a process in user mode requires access to a resource.

Situations 

There are some basic situations when system calls are invoked,

  • Creation of new processes.
  • Reading and writing, creating or deletion the file
  • Network connections, sending and receiving packets.
  • Accessing devices such as a printer, scanner, etc.

A table of system calls in Windows and Linux OS is given below.

Types of System Calls

Windows

Linux

Process Control
CreateProcess()
ExitProcess()
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()