Created
November 3, 2016 17:19
-
-
Save skymansandy/80b1ebdb811ee70a59924692a6a09164 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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