fork(), getpid() and exit() in linux- adri jovin
DESCRIPTION
Program to work with fork(), getpid() and exit()TRANSCRIPT
#include<sys/types.h> #include<unistd.h> #include<stdio.h> int main() { int pid; printf("\n\n Fork Function Testing"); printf("\n\n My Process ID=%d",getpid()); printf("\n\n My Parent's ID=%d",getpid()); pid=fork(); if(pid==-1) { printf("\n\n Error occurred... \n Process cannot be created "); exit(0); } if(pid!=0) { printf("\n\n Parent : My ID=%d",getpid()); printf("\n\n My Parent ID=%d",getpid()); exit(0); } else { printf("\n\nChild : My ID=%d",getpid()); printf("\n\n My Parents's ID=%d",getpid()); exit(0); } }