Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's mind-bending at first, but you seem to grasp that, when you call fork( ): </p> <ul> <li><p>the calling process (the "parent") is essentially duplicated by the operating system and the duplicate process becomes the "child" with a unique PID all its own;</p></li> <li><p>the returned value from the fork( ) call is either: integer 0,<sup>1</sup> meaning that the program receiving the 0 return is the "child"; or it is the non-zero integer PID of that forked child; and </p></li> <li><p>the new child process is entered into the scheduling queue for execution. The parent remains in the scheduling queue and continues to execute as before.</p></li> </ul> <p>It is this ( 0 <strong>.xor.</strong> non-0 ) return from fork( ) that tells the program which role it's playing at this instant -- 0 returned, program is the child process; anything else returned, program is the parent process.</p> <p>If the program playing the parent role wants many children, he has to fork( ) each one separately; there's no such thing as multiple children sharing a fork( ).</p> <p>Intermediate results certainly can be sent via a pipe.</p> <p>As for calling each child with different parameters, there's really nothing special to do: you can be sure that, when the child gets control, he will have (copies of) exactly the same variables as does the parent. So communicating parameters to the child is a matter of the parent's setting up variable values he wants the child to operate on; and then calling fork( ).</p> <hr> <p><sup>1</sup> More accurately: fork( ) returns a value of type <code>pid_t</code>, which these days is identical to an integer on quite a few systems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload