Find the answer to your Linux question:
Results 1 to 2 of 2
I've working on a project which gives 10 random numbers with the use of rand... I also have to create a Parent process and two Child ones... my problem is ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    6

    Question Question about Fork & Parent-Child process



    I've working on a project which gives 10 random numbers with the use of rand... I also have to create a Parent process and two Child ones... my problem is that I can use the fork command to produce one Child but then how do I create-define the second one so that I specify which one is which so that I can then run a qsort and sort the numbers, ascended by the one child and descended by the other... any ideas?

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    913
    Fork() returns the child's PID to the parent and zero to the child. So you could use fork() twice in succession, making the second call conditional on the first returning non-zero (i.e. that call would occur in the parent only). Then the parent would have two returned PIDs which would uniquely identify the two children.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

Posting Permissions

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