1
2
3
my $pid = open(my $njs, '-|', 'node', '../analyser/calc_chunk.js', 'live', $pass_data, $self->username)
or die "Could not run nodejs - $!";
push @{$self->{chld_processes}}, $pid;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sub restart {
my $self = shift;
my $good_data = shift;
sleep 1;
kill('SIGTERM', @{$self->chld_processes});
for my $pid (@{$self->chld_processes}) {
waitpid($pid, 0);
}
exec($^X, $0, $ARGV[0], $good_data);
exit 0;
}
QuoteDu sammelst die Prozesse mit push @{$self->{chld_processes}}. Das läßt vermuten, dass $self ein "übliches" Perl-Objekt ist - und Du direkt in den Hash reingreifst. Bei den Aufrufen von kill und waitpid verwendest Du dagegen die Methode $self->chld_processes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sub restart {
my $self = shift;
my $good_data = shift;
sleep 1;
use POSIX ":sys_wait_h";
kill('SIGTERM', @{$self->chld_processes});
1 while waitpid(-1, WNOHANG) > 0;
# for my $pid (@{$self->chld_processes}) {
# say "WAIT $pid"; #CORRECT PID
# say waitpid($pid, 0); #ALWAYS -1
# }
exec($^X, $0, $ARGV[0], $good_data);
exit 0;
}
1 while waitpid(-1, WNOHANG) > 0;
QuoteA non-blocking wait (with WNOHANG in FLAGS) can return 0 if there are child processes matching PID but none have terminated yet.
1 while waitpid(-1, WNOHANG) > 0;
Quotewaitpid PID,FLAGS
Waits for a particular child process to terminate and returns
the pid of the deceased process, or -1 if there is no such child