Created
March 20, 2018 09:12
-
-
Save sashuu69/7d2da6247ce7a6b33ecfb18dd9cd4124 to your computer and use it in GitHub Desktop.
C program to implement fork
This file contains hidden or 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<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