int fork( ) |
Effect:
|
int main(int argc, char *argv[] ) { printf("Hello World !\n"); fork( ); printf("Good-bye World !\n"); } |
Output:
Hello World ! Good-bye World ! // Printed twice !!! Good-bye World ! |
How to run the program:
|
|
|
|
|
|
|
int main(int argc, char *argv[] ) { printf("Hello World !\n"); int i = fork( ); printf("i = %d\n", i); // Show the return value of fork() } |
Sample output:
Hello World ! i = 10814 <--- This line was printed by the parent process i = 0 <--- This line was printed by the child process |
How to run the program:
|
if ( fork( ) != 0 ) { code executed by the parent process } else { code executed by the child process } |
int main(int argc, char *argv[] ) { printf("Hello World !\n"); if ( fork( ) != 0 ) { printf("Hello, I am the parent process\n"); } else { printf("Hello, I am the child process\n"); } } |
How to run the program:
|
|
How to run the program:
|