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.
or-bash-2.05b$ cat Agent.SOLSPARC caught SIGTERM signal, cleaning up
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.-bash-2.05b$ cat Agent.SOLSPARC Host: EBSO9SPC Login: esm2
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |