Professional Documents
Culture Documents
system calls
Diksha Bobade.
System Call:-
System call is a 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).
Types of System calls:-
Process Control:-
These system calls deal with processes such as process
creation, process termination etc.
File Management:-
These system calls are responsible for file manipulation such
as creating a file, reading a file, writing into a file etc.
Device Management :- These system calls are used to
manage and manipulate I/O devices such as printers,
keyboards, and disk drives. Examples include ioctl() and
select().
Information Management : These system calls are used to
retrieve information about the system, the processes running
on the system, and the status of various resources. Examples
include getuid(), getgid(), and getpid().
Communication
These system calls are used for inter-process communication
(IPC) and resource working. Examples include socket(), bind(),
listen(), and accept().
Services Provided by System Calls:-
management
Device handling(I/O)
Protection
Networking, etc.
Process Control System Calls:-
Process control system calls are used to
create and manage processes.
1.Fork
2.Wait
3.waitpid()
4.Wait 3
5.Waitid
fork() in C:-
{
perror("fork fail");
exit(1);
}
printf("Hello world!, process_id(pid) = %d \n",getpid());
return 0;
}
Output:-
Hello world!, process_id(pid) = 31 Hello world!, process_id(pid) = 32
Wait System Call in C
A call to wait() blocks the calling process until one
of its child processes exits or a signal is received.
After child process terminates, parent continues its
execution after wait system call instruction.
Child process may terminate due to any of these:
• It calls exit();
• It returns (an int) from main
• It receives a signal (from the OS or another process)
whose default action is to terminate.
Wait()
// C program to demonstrate working of wait()
#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<unistd.h>
int main()
{
pid_t cpid;
if (fork()== 0)
exit(0); /* terminate child */
else
cpid = wait(NULL); /* reaping parent */
printf("Parent pid = %d\n", getpid());
printf("Child pid = %d\n", cpid);
return 0;
}
Waitpid():-
Waitpid()
Waitid():-
Waitid() - wait for a child process to change state
SYNOPSIS
#include <sys/wait.h>
int waitid(idtype_t idtype, id_t id, siginfo_t
*iThe waitid()