This post was published long ago, when I was a student and an amateur blogger. The links might be outdated and content may not be useful anymore. Please read this content keeping its age in mind.
Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
[Click Here to get other programs by email ]
………………………………………………………………………………………………………………………….
PART -B
………………………………………………………………………………………………………………………….
4b) C program to do the following: Using fork( ) create a child process. The child process prints its own process-id and id of its parent and then exits. The parent process waits for its child to finish (by executing the wait( )) and prints its own process-id and the id of its child process and then exits.
#include<stdio.h>
#include<sys/types.h>
int main()
{
int status,ppid,mpid,pid;
pid=fork();
if(pid<0)
{
printf(“Error in forking a child..!”);
exit(0);
}
if(pid==0)
{
ppid=getppid();
printf(“nChild is executing and it’s Parent ID is : %d”,ppid);
mpid=getpid();
printf(“nChild ID is : %d”,mpid);
kill();
exit(0);
}
//pid=wait(pid,&status,0);
mpid=getpid();
printf(“nParent ID is : %d and it’s child ID is : %dn”,mpid,pid);
}
Leave a ReplyCancel reply