A small BUG in Ubuntu for Advanced Programming in UNIX environment

Source: Internet
Author: User
In this book, the fork Standard & amp; 26684; formula is pid_tpid; if (pid = fork () in this book, the standard format when fork is used is

Pid_t pid;

If (pid = fork () <0) // error

{}

Else if (pid = 0) // sub-process

{}

Else // parent process

{}

When the code is written in the same format as above, the sub-process is always executed, and the sub-process is executed twice, but the parent process is not executed,

After self-analysis, a new sub-process is generated every time if (pid = fork () <0). The reason seems to be here, but no matter

What about the parent process.

Replace the above format

Pid_t pid;

Pid = fork ();

If (pid <0)

{}

Else if (pid = 0)

{}

Else

{}

My environment is ubuntu. I don't know if it is related to this ~~~
Related Article

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.