You are on page 1of 1

Ex2b:

#include<stdio.h>
main(int argC,char*argV[])
{
int pid;
pid=fork();
if(pid<0)
{
fprintf(stderr,"fork failed\n");
exit(-1);
}
else if(pid==0)
{
execlp("/bin/ls","ls",NULL);
}
else
{
wait(NULL);
printf("child complete");
exit(0);
}
}

output:

test27@a2227-thinkcentre-m70e:~$ ./a.out
aarthi~ Downloads ex2.c experi1.odt Pictures Videos
a.out ex1 ex6.c Music Public
Desktop ex2a.odt ex6.c~ os1 swetha
Documents ex2b.c examples.desktop os11 Templates
child completetest27@a2227-thinkcentre-m70e:~$

You might also like