Enter your email address & Win:

System Software Lab Programs ( UNIX Programs ) – 4b

// June 4th, 2009 // Educational, Engineering, Unix and System Software Lab

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 : %d\n”,mpid,pid);
}

[Click Here to get other programs by email ]


If you enjoyed this post, make sure you subscribe to my RSS feed!

Related posts:

  1. System Software Lab Programs ( UNIX Programs ) – 1B
  2. System Software Lab Programs ( UNIX Programs ) – 3b
  3. System Software Lab Programs ( UNIX Programs ) – 5b
  4. System Software Lab Programs ( UNIX Programs ) – 7b
  5. System Software Lab Programs ( UNIX Programs )
blog comments powered by Disqus

Top Commentators

Get Adobe Flash playerPlugin by wpburn.com wordpress themes