in reply to multiple fork()

The Async module may be helpful here. It takes care of the forking for you automatically; you just give it a subroutine to execute and it automatically executes the subroutine in a separate process.

You get back an object which supports methods that allow you to ask if the subprocess has finished, and if so what the subroutine's return value was.

If you're interested in how to handle the fork stuff yourself, the code for Async might be worth looking at; it's pretty simple.

Happy Bicycle Day!

Replies are listed 'Best First'.
Re: Re: multiple fork()
by Galen (Beadle) on Apr 16, 2001 at 20:48 UTC
    Don't I have to recompile my perl binary to support threading in order to use Async? I suppose this is doable, but then it means my code is even less portable than it already is using the telnet module.
      The comment about a "separate process" makes me think that it is using fork. (Which is certainly how I would write it.) So you should not need to recompile, but you may have some problems on Windows. (Try it.)

      UPDATE
      Follow Dominus' link above for the Perl module under discussion...

        I don't need to worry about Windows, since it's all running on a solaris box. However, my "Network Programming with Perl" book says that the async function is used to create a thread object. Perhaps there is a separate perl module called Async as well. Hmm.. dunno. I'll look around.
      Says Galen:
      Don't I have to recompile my perl binary to support threading in order to use Async?
      No; Async uses fork, which I believe is what you were asking for.

      Happy Bicycle Day!

      --
      Mark Dominus
      Perl Paraphernalia