Skip to content

Instantly share code, notes, and snippets.

@78526Nasir
Created December 2, 2016 16:45
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 78526Nasir/9693c65c82d7faae28e6ea4eaa927763 to your computer and use it in GitHub Desktop.
Save 78526Nasir/9693c65c82d7faae28e6ea4eaa927763 to your computer and use it in GitHub Desktop.
Creating Child Process using Fork!
/* 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