Leser: 1
7 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use strict;
use warnings;
use POSIX;
use POSIX "sys_wait_h";
local $SIG{CHLD} = \&REAPER;
my $wert = system('ls');
print "Rueckgabe: $wert\n";
if ($wert == 0) {
print "Ok\n";
}
else {
print "Fehler\n";
}
exit 0;
sub REAPER {
my $sig = shift;
my $pid;
while (($pid = waitpid(-1, WNOHANG)) > 0) {
print "child $pid terminated - status $?\n";
print "sig: $sig\n";
}
$SIG{CHLD} = \&REAPER;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use strict;
use warnings;
use POSIX ":sys_wait_h";
$SIG{CHLD} = \&REAPER;
my @commands = qw/ls w id/;
my %childs = ();
my %reaped = ();
foreach my $cmd (@commands) {
if (my $pid = fork) {
$childs{$pid} = '';
} else {
# 1 sekunde warten, da es sein kann, dass $childs{$pid}
# erst gesetzt wird, wenn der Child schon gestorben ist
sleep 1;
my $foo = qx{$cmd};
exit($?/256);
}
}
# solange schlafen, bis alle Childs eingesammelt wurden
sleep while scalar keys %childs;
print "child $_ terminated - status $reaped{$_}\n"
foreach sort keys %reaped;
sub REAPER {
my $sig = shift;
my $pid;
while (($pid = waitpid(-1, WNOHANG)) > 0) {
delete $childs{$pid};
$reaped{$pid} = $sig.':'.$?;
}
$SIG{CHLD} = \&REAPER;
}
1
2
3
4
5
6
7
8
...
if (my $pid = fork) {
$childs{$pid} = $cmd;
}
...
$reaped{$pid} = $childs{$pid}.':'.$sig.':'.$?;
delete $childs{$pid};
...
7 Einträge, 1 Seite |