Created
May 4, 2012 08:56
-
-
Save satoyuichi/2593422 to your computer and use it in GitHub Desktop.
Fork test
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
#include <stdio.h> | |
#include <stdlib.h> | |
int main( int argc, char** argv ); | |
int main( int argc, char** argv ) | |
{ | |
int pid; | |
printf( "Start main function.(%d)\n", __LINE__ ); | |
pid = fork(); | |
printf( "Forked process id is %d.(%d)\n", pid, __LINE__ ); | |
switch( pid ) { | |
case 0: | |
printf( "I am child process.(%d)\n", __LINE__ ); | |
exit( 0 ); | |
break; | |
case -1: | |
printf( "Fork is failed.(%d)\n", __LINE__ ); | |
exit( 0 ); | |
break; | |
default: | |
printf( "I am parent process.(%d)\n", __LINE__ ); | |
wait( NULL ); | |
break; | |
} | |
printf( "End main function.(%d)\n", __LINE__ ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment