Find the answer to your Linux question:
Results 1 to 2 of 2

Thread: code C (linux)

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    code C (linux)

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

    int main (void)
    {pid_t fils;
        }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
    Nottingham, England
    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

Posting Permissions

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