Skip to content

Instantly share code, notes, and snippets.

@skymansandy
Created November 3, 2016 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skymansandy/80b1ebdb811ee70a59924692a6a09164 to your computer and use it in GitHub Desktop.
Save skymansandy/80b1ebdb811ee70a59924692a6a09164 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
int main()
{
int status,ppid,mpid,pid;
pid=fork();
if(pid<0)
{
printf("error in the fork call\n");
exit(0);
}
if(pid==0)
{
ppid=getppid(); //return parent process id
mpid=getpid(); //return current process id
printf("I am child process executing\nMy own id is: %d\nMy parent id is %d\n",mpid,ppid);
//printf("My own id is %d\n",mpid);
kill();//terminate child process
exit(0);
}
pid=wait(pid,&status,0);
mpid=getpid();
printf("I am parent with Id %d\n my child with Id %d\n",mpid,pid);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment