in reply to Re^3: Problem with exit status of bash script
in thread Problem with exit status of bash script

thanks for the help, I did add additional exit codes in the my child processes and it solved my problems (I posted code below)

in the end, I figured the easiest way is for the parent to keep track of the children's exit status; because in the end that's all I care about.

I don't have access to "update" my version of perl (or add modules), but I'm definitely going to look more into the IPC, it really interests me.

foreach $element (@updevices) { @ip = split(':',$element); die "Could not fork()\n" unless defined ($pid = fork); if ($pid) { push @pids, $pid; next;} system("ping $ip[2] 2 > /dev/null"); $result = $?; if ( $result != 0) { print "$ip[0] is dead\n"; exit 1; } exit 0; } for $pid(@pids){ waitpid $pid, 0; if ($? != 0) { $i++; } } print "$i dead devices\n";

Replies are listed 'Best First'.
Re^5: Problem with exit status of bash script
by Anonymous Monk on Dec 05, 2014 at 02:37 UTC
    Oh, I see. You were probably asking about the array @dead. I didn't notice it (that's why it's a good idea to use strict and declare all variables). Yeah, parent cannot use @dead because after fork parent and child are two completely different processes and don't share variables (actually, parent can use @dead but it just will be empty).