Skip to content

Instantly share code, notes, and snippets.

@sashuu69
Created March 20, 2018 09:12
Show Gist options
  • Save sashuu69/7d2da6247ce7a6b33ecfb18dd9cd4124 to your computer and use it in GitHub Desktop.
Save sashuu69/7d2da6247ce7a6b33ecfb18dd9cd4124 to your computer and use it in GitHub Desktop.
C program to implement fork
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
int main()
{
pid_t c,d;
int i,x;
c=fork();
d=fork();
if (c>0 && d==0)
{
for(i=0;i<10;++i)
{
printf("%d i am chiled 1 \n",getpid());
sleep(1);
}
}
else if(d>0 && c==0)
{
for(i=0;i<5;++i)
{
printf("%d i am chiled 2 \n",getpid());
sleep(2);
}
}
waitpid(c, &x, 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment