Getting values back from forked programs can be tricky because when a program is forked, its child process is completely seperate (well, mostly) from the parent process - it just happens to be identical to it at first. Because of this, any values that you change in the child process are lost when it exits unless you somehow get them back to the parent process.

There are several ways you can do this, the easiest would be to use the exit code. However, if I remember correctly, exit codes can only be integers from 0 to 255, so that limits how much information you can pass back. Another option would be to use some form of shared memory, but that can be difficult to program. You could also have all the processes write to a file, but you should make sure to have each one obtain an exclusive lock on the file before writing to it, then close it to prevent a race condition between all the processes that are going to be using it.

Probably one of the nicest ways is to use a database. The database won't have any problem accepting connections from many multiple clients and it will take care of locking issues for you as well. The only problem is a speed tradeoff, as opening a connection to the database will take a little bit.

Just thought of another one, you could use something like syslog if you're just writing out the result of an operation.

Hope that helps!


In reply to Re: Parallel::ForkManager question by Mr_Person
in thread Parallel::ForkManager question by crackotter

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.