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

From a process XX, i launch 3 or 4 other processes which are the child of the XX process.

In each child process i does different things, and finally when each returns i have to find out which child returned by checking the Environment variable i manipulated in the child. That is i have a variable PROJECTNAME in all child process, and each ones value varies as PROJECT1, PROJECT2... Based up on that i do different task in the parent.

That is what i asked how to get the environment variable from the child process to the parent process. Hope it is clear.

Note: As many people felt the explanation given in my previous question is not clear, I am giving better explanation here of my earlier question here.

Replies are listed 'Best First'.
Re: getting values from child process
by Corion (Patriarch) on Nov 10, 2010 at 10:22 UTC

    Using the environment won't work.

    My recommendation is to simply use files to transfer the information.

    For alternative approaches, see perlipc and the discussion in your previous thread. But none of the solutions beats using files written by the children and polling for these files in the parent for simplicity. Threads::Queue comes close, but only if you can write your children as threads instead of separate processes.

    Depending on the size of information, you can even get by by appending to a single file and using File::Tail in the parent.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: getting values from child process
by cdarke (Prior) on Nov 10, 2010 at 11:09 UTC
    i have to find out which child returned by checking the Environment variable i manipulated in the child

    So why not use wait or waitpid? It depends on how you launch the child processes, but you should be able to pick up the exit code from the child, which has a range of 0-255, usually in $?. See perlvar.
Re: getting values from child process
by JavaFan (Canon) on Nov 10, 2010 at 16:36 UTC
    That is what i asked how to get the environment variable from the child process to the parent process.
    I think it's possible on VMS, but on Unix and Windows, it isn't possible. Environment variables are private to the process. On process creation, the new process gets a copy of the environment variables of the parent, but short of peeking directly into memory, there's no easy way to get to the value of an environment variable of another process. The non-easy ways all have to do with modifying your kernel.

    I'd use exit values or pipes to solve your problem.

Re: getting values from child process
by locked_user sundialsvc4 (Abbot) on Nov 10, 2010 at 18:57 UTC

    As a blanket statement, I would advise that you don’t eer expect the parent of a process (or, any other process) to have “specialized knowledge” about another process, nor to magically rendezvous with one.

    If you need to obtain information from the child, have the child give it to the parent by some sharing-friendly mailbox or queue.

    There are a lot of things (like this) that “look good in testing” and “seem to work okay,” that will have you fall flat on your “*” in production.   :-}