SOURCE CODE:
#include<stdio.h>
#include<unistd.h>
main()
{
int pid;
pid=fork();
if(pid<0)
{
printf(stderr, “fork failed”);
exit(-1)
}
else if(pid==0)
{
printf(“child id is%d”,getpid());
execlp(“/bin/ls”,”is”,NULL);
}
else
{
wait(NULL);
printf(“The parent id is %d\n”,getpid());
printf(“The child id is %d\n”,getpid());
printf(“child completed\n”);
exit(0);
}
}
OUTPUT:
[examuser35@localhost Jebastin]$ cc prob.c
[examuser35@localhost Jebastin]$ ./a.out
amrarpl.c ff.c naan.c
arpraj.c ff.c pca.c
arp.c ftp.c pcb.c
bata.c heema.c pcc.c
bgp.c hema.c run.c
bgpro.c heha.c rr.c
cals.c input.c sr.c
chat.c ktec.c ss.c
client.c ktes.c sss.c
data1.c ls.c tam.c
day.c maa.c tcp.c
echo.c man.c udhai.c
eho.c new1.c ven.c
exam.c nehru1.c wa.c
The parent id is 3286
The child is 6526
Child completed.
EmoticonEmoticon