linux process creates

  

/****fork_test.c ***** /# include # include # includemain () {pid_t pid; /* At this time only one process * /int n = 4; pid = fork (); /* this case has two processes running simultaneously * /if (pid & lt; 0) printf (" error in fork /n "!); else if (pid == 0) /* returns 0 represents child process * /{n ++; printf (" I am the child process, my process ID is% d, n =% d /n ", getpid (), n);} else /* returns greater than 0 indicates the parent process * /{n--; printf (" I am the parent process, my process ID is% d, n =% d /n ", getpid (), n);}}

statement & ldquo; pid =fork()”, which produced two processes, the original parent process, and the newly created child process.

The difference between the parent and child processes is different from the return value of the different fork functions of the PID. In the parent process, the child process Pid is returned, and the child process returns 0;

Copyright © Windows knowledge All Rights Reserved