Created
December 2, 2016 16:45
-
-
Save 78526Nasir/9693c65c82d7faae28e6ea4eaa927763 to your computer and use it in GitHub Desktop.
Creating Child Process using Fork!
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
/* This Program is for creating child process. It works only in Linux operating System. | |
//To run this code in linux environment you need to follow the below steps: | |
1. write cc and then put the '.c' "file location/address here" then press enter. | |
2. write ./a.out to generate the output of the code. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> // this header file needed for using fork(), getpid() functions | |
int main() | |
{ | |
int pid=fork(); | |
if(pid<0){ | |
printf("Fork Failed !"); | |
} | |
else if(pid==0){ | |
printf("\nChild Process Created!\n"); | |
} | |
else{ | |
printf("\nParent Process!\n"); | |
printf("Process ID : %d \n",getpid()); | |
wait(NULL); | |
} | |
printf("Child Process Complete !"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment