Professional Documents
Culture Documents
Oslab 1
Oslab 1
Write programs using the following system calls of UNIX operating system:
fork, exec, getpid, exit
Aim :
To write a C program using the system calls - fork, exec, getpid, exit
Algorithm :
Result :
Thus the program using the system calls - fork, exec, getpid, exit is executed and verified
Source Code:-
#include <stdio.h>
main()
{
int pid,pid1;
www.Technicalsymposium.com
pid=fork();
if(pid==-1)
{
printf(“Error in fork”);
exit(0);
}
if(pid==0)
{
pid1=fork();
exit(0);
}
printf(“\n parent id: %d”,getppid());
printf(“\n Child id : %d”,getpid());
}
OUTPUT:-
Parent id : 3233
Child id : 3664
www.Technicalsymposium.com