Linux process creation

Source: Internet
Author: User
/****fork_test.c *****/#include <stdio.h> #include <sys/types.h> #include <unistd.h>main () {pid_t PID;        /* There is only one process at this time */int n=4; Pid=fork ();       /* There are already two processes running at the same time */if (pid<0) printf ("Error in fork!\n"); else if (pid==0)/   * Returns 0 for child process */     {n++;        printf ("I am the child process, my process ID is%d,n=%d\n", Getpid (), n);     }     else/         * Returns greater than 0 for parent process */     {n--;    printf ("I am the parent process, my process ID is%d,n=%d\n", Getpid (), n);     }}

The statement "Pid=fork ()" produces two processes, the parent process that originally existed, and the newly emerging child process.

The difference between the parent and child processes is not the same as the return values for the different fork functions of the PID. In the parent process, the child process PID is returned, and the child process returns 0;









Linux process creation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.