Summary of Linux printf and fork () issues

Source: Internet
Author: User

Summarized as follows:

printf"father begin");      pid_t pid; PID=Fork (); if(PID >0)      {           while(1) {printf ("Father out"); Sleep (1); }      }      Else if(PID = =0)      {           while(1) {printf ("Child out \ n" ); Sleep (1); }     }     

It is important to note that printf is a C standard library function that runs in a user-owned buffer where a row buffer encounters \ n or a full or similar getchar scanf function will flush the buffer or the process will not automatically flush the buffer when it finishes running

A generic open file when fully buffered Linux endpoints are also row buffers

Fork () assigns all the data of the main process to include buffers so it happens that some of your unexpected results are different from what you think.

Summary of Linux printf and fork () issues

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.