System Call :
A system call is the programmatic way in which a computer program requests a service from the kernel of the operating system it is executed on. A system call is a way for programs to interact with the operating system. A computer program makes a system call when it makes a request to the operating system’s kernel. System call provides the services of the operating system to the user programs via Application Program Interface(API). It provides an interface between a process and operating system to allow user-level processes to request services of the operating system. System calls are the only entry points into the kernel system. All programs needing resources must use system calls.
Services Provided by System Calls :
1. Process creation and management
2. Main memory management
3. File Access, Directory and File system management
4. Device handling(I/O)
5. Protection
6. Networking, etc.
Types of System Calls : There are 5 different categories of system calls –
1. Process control: end, abort, create, terminate, allocate and free memory.
2. File management: create, open, close, delete, read file etc.
3. Device management
4. Information maintenance
5. Communication
System call use to create get the child process exit status :
It is
known that fork() system call is used to create a
new process which becomes child of the caller process.
Upon exit, the child leaves an exit status that should be returned
to the parent. So, when the child finishes it becomes a
zombie.
Whenever
the child exits or stops, the parent is sent a SIGCHLD
signal.
The parent can use the system call wait() or waitpid() along with
the macros WIFEXITED and WEXITSTATUS with it to learn about the
status of its stopped child.
// C code to find the exit status of child process
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
// Driver code
int main(void)
{
pid_t pid = fork();
if ( pid == 0 )
{
/* The pathname of the file passed to execl()
is not defined */
execl("/bin/sh", "bin/sh", "-c", "./nopath", "NULL");
}
int status;
waitpid(pid, &status, 0);
if ( WIFEXITED(status) )
{
int exit_status = WEXITSTATUS(status);
printf("Exit status of the child was %d\n",
exit_status);
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.