Breaking

Sunday, August 2, 2020

What is the System Call?
Before we know what is it, we should know why it is. In that way, we can get more involved in any topic.
As we know the Operating System(OS) is the interface between hardware and user-level applications and the OS controls all the hardware resources (like hard disk, display, keyboard, etc.). When a user-level application let's say VLC media player wants to use the 'display' resource to project/show a video on the screen. then it makes a request to the operating system for the 'display' resource. After that, the operating system reserves that particular resource for the VLC media player for the requested time period. Then only the VLC can use the screen to display contents. This request to acquire resources is called a system call. So in order to use any resources managed by the operating system, we need a system call.

How the system call works:-
System calls are like function calls (Not exactly the same). There is a separate piece of code written to access the system hardware through the device driver, which suppose to be accessed by kernel only (Device drivers are another piece of software without which hardware can't interact with OS). The declarations and definitions of these functions are present in the POSIX library. That's why we include the header file from the library to our code in order to use any system calls. For e.g, we include "sys/types.h" header file to use "fork" system call to create a child process and likewise.

how system call works

The starting address of all functions is saved in a table with there respective APIs. Whenever we call a system function, it looks for its API address from the table and jumps to that address to perform the operation. After successful execution, the control returns back to the caller function. This complete process is called a system call. Because we use the system code to make a kernel-level task complete through an API call.


How system call works



System calls are basically written in High-Level languages like C/C++. There are different system calls made for different Operating Systems, like:-

1. POSIX API for POSIX based system (Unix, Linux, macOS).
2. Win32 API for Windows.
3. Java API for Java Virtual Machine (JVM)

Below are some examples of system calls written with respect to their tasks for POSIX Operating System. you can get all Linux system calls from here.

1. Process control:-
a) Create and terminate the process.
b) Get and set process attributes.
c) Load and execute.
d) Wait for time.
e) Wait and signal event.
f) End and abort.
g) Allocate and free memory.

2. File manipulation:-
a) Open and close file
b) Create and delete a file
c) Read and write
d) Get and set file attributes

3. Device manipulation:-

a) Request and release device
b) Logically attach and detach a device
c) Read, write and reposition
d) Get and set device attributes

4. Information maintenance:-
a) Get and set time
b) Get and set date
c) Get and set system data

5. Communication:-
a) Create and delete a communication connection
b) Transfer status information
c) Attach and detach a remote device
d) Send and receive messages

Actually, we can create our own system call. There are several blogs written on how to create a system call and compile it with the Linux kernel source code. Here is a video on the practical demo of system call creation.

The video will be coming soon.



close