7 Dec 2019

  • December 07, 2019
  • Amitraj
Introduction to System Calls

To understand system calls, first one needs to understand the difference between kernel mode and user mode of a CPU. Every modern operating system supports these two modes.





1. Kernel Mode

-> When CPU is in kernel mode, the code being executed can access any memory address and any hardware resource.

-> Hence kernel mode is a very privileged and powerful mode.

-> If a program crashes in kernel mode, the entire system will be halted.


2. User Mode

-> When CPU is in user mode, the programs don't have direct access to memory and hardware resources.

->In user mode, if any program crashes, only that particular program is halted.

-> That means the system will be in a safe state even if a program in user mode crashes.

-> Hence, most programs in an OS run in user mode.




System  Call:-

-> When a program in user mode requires access to RAM or a hardware resource, it must ask the kernel to provide access to that resource. This is done via something called a system call.

-> When a program makes a system call, the mode is switched from user mode to kernel mode. This is called a context switch.

-> Then the kernel provides the resource which the program requested. After that, another context switch happens which results in change of mode from kernel mode back to user mode.

-> Generally, system calls are made by the user level programs in the following situations:

1. Creating, opening, closing and deleting files in the file system.
2. Creating and managing new processes.
3. Creating a connection in the network, sending and receiving packets.
4. Requesting access to a hardware device, like a mouse or a printer.

-> In a typical UNIX system, there are around 300 system calls. Some of them which are important ones in this context, are described below.



1. Process Management
Scheduling, deadlock detection is transparent.

1. fork, vfork, exit, exec
2. wait
3. signals, pipes, streams, sockets


2. Memory management
For the most part, transparent to the user.

1. malloc, free


3. I/O Device Management
   
Devices are treated as files, so I/O devices are supported by the file system.


4. File System

1. creat, open, close
2. lseek, read, write
3. stat, chmod, chown
4. link, unlink
5. mkdir, rmdir
6. sync

Translate

Popular Posts