fork

Discussion in 'Perl' started by CwK, Dec 22, 2003.

  1. CwK

    CwK Guest

    How to use fork() system function to fork multi child process at the same
    time ?

    For example:

    Run a program to fork 5 child process at the same time and the parent must
    wait until all child exit.

    The child do some thing like to read different file at the same time.

    Thanks
     
    CwK, Dec 22, 2003
    #1
    1. Advertising

  2. CwK

    Jim Gibson Guest

    In article <bs76pq$>, CwK <>
    wrote:

    > How to use fork() system function to fork multi child process at the same
    > time ?
    >
    > For example:
    >
    > Run a program to fork 5 child process at the same time and the parent must
    > wait until all child exit.
    >
    > The child do some thing like to read different file at the same time.
    >
    > Thanks
    >
    >


    Execute the fork call 5 times. You can't start 5 processes "at the same
    time", but you can do it quickly one after another. You will then need
    to execute the wait call 5 times in the parent process, one for each
    child. No single process can do two or more different things
    simultaneously. Two or more processes can execute simultaneously only
    if you have more than one processor in your system.

    Once you have a Perl program coded, and if it doesn't work, you should
    then post it here for additional help.
     
    Jim Gibson, Dec 22, 2003
    #2
    1. Advertising

  3. CwK

    Misha Gale Guest

    "Jim Gibson" <> wrote in message
    news:221220031029144359%...
    > In article <bs76pq$>, CwK <>
    > wrote:
    >
    > > How to use fork() system function to fork multi child process at the

    same
    > > time ?
    > >
    > > For example:
    > >
    > > Run a program to fork 5 child process at the same time and the parent

    must
    > > wait until all child exit.
    > >
    > > The child do some thing like to read different file at the same time.
    > >
    > > Thanks
    > >
    > >

    >
    > Execute the fork call 5 times.


    Be sure that only the top-level parent atually executes the forks, otherwise
    rather than having five processes you will end up with 2^5=32 processes.
     
    Misha Gale, Jan 4, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Josh Denny

    fork in perl 5.8.3 on windows

    Josh Denny, Mar 2, 2004, in forum: Perl
    Replies:
    2
    Views:
    6,743
    Jim Gibson
    Mar 2, 2004
  2. Patrick
    Replies:
    1
    Views:
    538
  3. xchris
    Replies:
    5
    Views:
    4,148
  4. Doug Nichols

    objects and fork command?

    Doug Nichols, Aug 6, 2004, in forum: Perl
    Replies:
    1
    Views:
    823
  5. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    604
    Eric Snow
    Jan 8, 2009
Loading...

Share This Page