Experiment 2
Experiment 2
System Call :
A system call is a mechanism that provides the interface between a process and Operating system. It
is a programming method in which a computer program requests any service from the Kernel to
Operating System.
Example-
3. To manage memory.
1. fork() – This method is used to create a child process within a parent process.
Example :-
# include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
Int main()
Fork();
Return 0;
EXAMPLE 2
int main()
fork();
fork();
fork();
return 0;
EXAMPLE 3
int main()
int i , n=5;
fork();
printf("/n hello..CSE");
}
return 0;
2. getpaid()
EXAMPLE
#include<iostream>
#include<sys/types.h>
#include<unistd.h>
Int main()
int n=fork();
if(n==0)
else
return 0;
}
3) getppid()- the method is used to get id of the parent process.”
EXAMPLE
#include<iostream>
#include<sys/typrs.h>
#include<unistal.h>
Int main()
int n=fork();
if(n==0)
return 0;
4. exec() - This method is used to execute all the executable files within the process.
5. execl() – This methos is used to list out all the executable files from root as well as system
Kernel.
Example :
# include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
Int main()
Char *path=”/bin/ls”;
Char *a=”lh”;
Char *b=”/home”;
Execl(path,path,a,ab,NULL);
Return 0;
}
6. exit():-
EXAMPLE 1
# include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
Int main()
Int i;
For (i=1;i<=10;i++)
If (i>=5)
Exit(0)
printf(“\n %d”,i);
return 0;
EXAMPLE 2
Int n=fork();
If(n==0)
fork();
fork();
}else
exit(0);
return 0;
}