I am trying to run few child processes on different platforms in parallel. Parent should only proceed further once all the child processes have completed on respective platforms.

The problem is that when I use fork and then run the ‘exec’ command in the child process, it ends almost instantly. Also, the output isn't consistent. Almost every time the log shows only one line.

-bash-2.05b$ cat Agent.SOLSPARC caught SIGTERM signal, cleaning up
or
-bash-2.05b$ cat Agent.SOLSPARC Host: EBSO9SPC Login: esm2
Sometimes, there are few extra lines and at last the message, 'Killed by signal 15'. The command that i use in 'exec' actually calls a script which connects to remote boxes and runs make command on them. For testing purpose, i am currently passing only one platform i.e., SOLSPARC. Also, i'm only interested in knowing whether a command finished on any given platform.

I was not sure whether I was passing all the arguments to ‘exec’ correctly so I tried different combinations (after referring different links on the Internet) but to no avail. One important observation is that when i used strace to debug this issue, the command worked fine. I saw in the perldoc that exec uses /bin/sh -c on Unix platforms, but varies on other platforms. Is it that exec and strace use different shell?

Here’s the relevant portion of my code:

sub compile { my %child_pids; foreach $plat (0 .. $#plat_list) { my $pid = fork; # Didn't check the undef condition for child if ($plat_list[$plat] eq "SOLSPARC") { print "\nStarted Solaris build \n"; if ($pid == 0) { print "Inside Child Process \n\n"; exec ( "${ROOT}/${REM_EXEC} -t 1200 -c \"make LANG=en_ +US distclean \" -b ${ROOT} -l Agent. $plat_list[$plat]" ) or die "exe +c failed"; } elsif ($pid > 0) { $child_pids{"SOLSPARC"} = $pid; } } else { print "\nStarted build for other platforms \n"; if ($pid == 0) { print "Inside Child Process \n\n"; exec ( "${ROOT}/${REM_EXEC} -t 1200 -c \"make LANG=en_ +GB clean \" -b ${ROOT} -l Agent. $plat_list[$plat]" ) or die "exec fa +iled"; } elsif ($pid > 0) { $child_pids{"$plat_list[$plat]"} = $pid; } } } my %rev_child_pids = reverse %child_pids; while ((my $kid = waitpid -1, WNOHANG) > 0) { if ($rev_child_pids{$kid} eq "SOLSPARC") { print "\nChild process completed for SOLARIS platform $rev +_child_pids{$kid} \n"; print "Run some other command here \n"; } else { print "\nChild process completed for other platform $rev_c +hild_pids{$kid} \n"; print "No more commands to run \n"; } } }

I tried the following two forms as well but still there is no change in output:

exec ( "${ROOT}/${REM_EXEC}", "-t 1200", "-c \"make LANG=en_US distclean \"", "-b ${ROOT}", "-l Agent.", "$plat_list[$plat]" ) or die "exec failed";

and

exec ( "${ROOT}/${REM_EXEC}", "-t", "1200", "-c", "\"make LANG=en_US distclean \"", "-b", "${ROOT}", "-l", "Agent.", "$plat_list[$plat]" ) or die "exec failed";

The script, ${REM_EXEC}, which runs the code on remote machine is pasted here: http://pastebin.com/j4MJgPPL

Any suggestions?


In reply to Unable to 'exec' by Technext

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.