Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Launching numerous instances of the same program

( #50990=categorized question: print w/ replies, xml ) Need Help??
Contributed by Zombie Terrabyte on Jan 11, 2001 at 01:51 UTC
Q&A  > programs and processes


Description:

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!!!!

Answer: Launching numerous instances of the same program
contributed by extremely

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. =)

Answer: Launching numerous instances of the same program
contributed by repson

On a win32 system you will want create processes with Win32::Process in a loop. A fork and exec will not work in windows.

Answer: Launching numerous instances of the same program
contributed by turnstep

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

Answer: Launching numerous instances of the same program
contributed by jplindstrom

I personally like the Win32::Process module, 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

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (12)
    As of 2015-07-02 09:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (33 votes), past polls