Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

FORK SYSTEM

CALL
#include<stdio.h>
#include<sys/types.h
> void main(){ pid_t
pid; pid =getpid();
printf("before fork
%d",pid); pid=fork();
if(pid==0)
printf("\nthisline from child,\nthe child process id %d\n",getpid()); else
if(pid==1)
printf("this line is from
parent,value=%d\n"); else if(pid<1){
printf("\n fork failed"); exit(1); } if(pid==0){
execl("/bin/ls","ls","-1",(char *)0);
}
if(pid>0)
wait((int *)0)
}

d) Output:
before fork 4258
thisline from child,
the child process id 4259
a.out
ch.c
come.c
data
file1.c
file2.c
first.c
fit.c
sysytem.c
before fork 4258

e)Result:
Thus the process system call program was executed and verified successfully.

You might also like