Skip to content

Instantly share code, notes, and snippets.

@jeonghwan-kim
Created October 15, 2013 02:14
Show Gist options
  • Select an option

  • Save jeonghwan-kim/6985547 to your computer and use it in GitHub Desktop.

Select an option

Save jeonghwan-kim/6985547 to your computer and use it in GitHub Desktop.
fork() sample
#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