I need to have a script create several instances of an app and then wait until all the instances have completed. Each instance is run with its own set of data, so they may not all finish at the same time. I need to wait until all of my instances have finished to continue my process so all the data are complete before acting on them. My original thought was to use open2 to open each instance of the program and pass its stderr and stdout to a file (2>&1) ignoring the file handle open2 creates. Each instance will run in it's own directory and the app creates it's files in the current durectory. My thought was that as long as I don't use waitpid() I can launch all of them without hanging. Then I would watch /proc/$pid/cwd and as long as it matches my cwd I know the process is still running. As soon as
/proc/$pid/cdw ne $curdir
I know my child is no longer running. When all of my children are complete I can then move on collecting my data and finishing the process. I coded up a test and it seems to work as I expect. However I did not use my actual app to test as it runs many hours, so the app I launched was a very trivial perl script. As I said this worked fine but before I code this into my actual process and use it to launch many instances of this non-trivial app that takes hours to run I thought I'd read IPC::Open2 and make sure I wouldn't have any trouble , but I became nervious and thought perhaps there is a better way. The process that I'm adding this to is one that currently takes all the data and passes it to a single instance of the app and therefore does not take advantage of the systems 4 cpus. I thought perhaps of using forking but I've never done that before and was unsure of how I would make it work.

Any suggestions would be greatly appreciated.

Sweetblood


In reply to creating multiple instances of a process by sweetblood

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.