System call provides an interface between user program and operating system. The structure of system call is as follows −
When the user wants to give an instruction to the OS then it will do it through system calls. Or a user program can access the kernel which is a part of the OS through system calls.
It is a programmatic way in which a computer program requests a service from the kernel of the operating system.
The different system calls are as follows −
System calls for Process management
System calls for File management
System calls for Directory management
Now let us discuss process management system calls.
A system is used to create a new process or a duplicate process called a fork.
The duplicate process consists of all data in the file description and registers common. The original process is also called the parent process and the duplicate is called the child process.
The fork call returns a value, which is zero in the child and equal to the child’s PID (Process Identifier) in the parent. The system calls like exit would request the services for terminating a process.
Loading of programs or changing of the original image with duplicate needs execution of exec. Pid would help to distinguish between child and parent processes.
Process management system calls in Linux.
fork − For creating a duplicate process from the parent process.
wait − Processes are supposed to wait for other processes to complete their work.
exec − Loads the selected program into the memory.
exit − Terminates the process.
The pictorial representation of process management system calls is as follows −
fork() − A parent process always uses a fork for creating a new child process. The child process is generally called a copy of the parent. After execution of fork, both parent and child execute the same program in separate processes.
exec() − This function is used to replace the program executed by a process. The child sometimes may use exec after a fork for replacing the process memory space with a new program executable making the child execute a different program than the parent.
exit() − This function is used to terminate the process.
wait() − The parent uses a wait function to suspend execution till a child terminates. Using wait the parent can obtain the exit status of a terminated child.