Created
October 15, 2013 02:14
-
-
Save jeonghwan-kim/6985547 to your computer and use it in GitHub Desktop.
fork() sample
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 <sys/types.h> | |
| #include <stdio.h> | |
| int a = 6; | |
| int main( void ) | |
| { | |
| int b; | |
| pid_t pid; | |
| b = 88; | |
| printf( "before fork : a = %d, b=%d\n", a, b ); | |
| pid = fork(); | |
| printf( "after fork\n" ); | |
| if( pid == 0 ) { /* child */ | |
| printf( "I'm clild : a = %d, b=%d\n", ++a, ++b ); | |
| } else { /* parent */ | |
| printf( "I'm parent : a = %d, b=%d\n", a, b ); | |
| wait( pid ); | |
| } | |
| exit( 0 ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment