Find the answer to your Linux question:
Results 1 to 2 of 2
Hi i have some question about the following code which i understand the purpose but not how it works. Help me plz Code: int main (void) {pid_t fils; do { ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2013
    Posts
    15

    code C (linux)


    Hi
    i have some question about the following code which i understand the purpose but not how it works. Help me plz

    Code:
    int main (void)
    {pid_t fils;
    do
       {
    fils=fork();
        }while (fils==-1)&&(errno==EAGAIN);
    if (fils==-1)
    {  fprint stderr,"fork() impossible, errno=%d\n,errno); return 1;}
     
    if (fils==0) {fprint(stdout,"fils");}
    else {fprint(stdout,"pere");}
    .....
    }
    1/ how is it possible to find fils==-1 i thought while won't let it pass
    2/ does fils change while the code is running ?

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,879
    1. The 'while' only continues to run if fils==-1 AND errno==EAGAIN - i.e. the loop can be terminated by either condition being false.

    2. 'fils' is assigned in the middle of the while loop, so yes, it can change.
    Linux user #126863 - see http://linuxcounter.net/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •