http://www.perlmonks.org?node_id=50990

Terrabyte has asked for the wisdom of the Perl Monks concerning the following question:

How can I launch many instances of the same program from within a perl script. An example would be starting 10 instances of calc on the Win32 platform. When I use system, it waits for a response. When I use exec, it shifts to calc. If I fork, I just start myself again. Help!!!!

Originally posted as a Categorized Question.

  • Comment on Launching numerous instances of the same program

Replies are listed 'Best First'.
Re: Launching numerous instances of the same program
by extremely (Priest) on Jan 11, 2001 at 02:11 UTC
    Fork 10 children and exec calc in the children. Also, FYI a fork in a loop is called a fork-bomb. Make sure you know exactly how your loop works so that you don't consume all the allowed resources under your OS and kill the box. I've personally seen a 1/4 million dollar machine rebooted more than once over other goofballs doing this. People loose root access, their jobs, or get the FBI called on them for tricks of this sort. =)
Re: Launching numerous instances of the same program
by repson (Chaplain) on Jan 11, 2001 at 07:55 UTC
    On a win32 system you will want create processes with Win32::Process in a loop. A fork and exec will not work in windows.
Re: Launching numerous instances of the same program
by turnstep (Parson) on Jan 11, 2001 at 03:10 UTC

    Don't expect fork to work very well under Win32 either...see the thread fork on Win32

Re: Launching numerous instances of the same program
by jplindstrom (Monsignor) on Jan 12, 2001 at 02:42 UTC
    I personally like Win32::Process, but another way of doing this (the Windows way of starting things with &) is to use the "start" command.

    Type "start /?" at the command line to get the options.

    /J