Leser: 2
10 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/perl -w
use strict;
pipe(READER,WRITER); # used for communication between child and parent
#$SIG{'CHLD'} = 'reaper'; # used for killing zombies
my $zahl = 0; # number of currently running children
my $zeile; # row
my $pid; # process ID
if (open FILE, "< /sls_backup/mdjanan/sleep.txt")
{
while($zeile = <FILE>)
{
if ($zahl < 4)
{
$zahl++; # increase number of children
$pid = fork(); # a new child is born. yay :)
print $pid."\n";
}
if($pid == 0)
{
# child-process
#close WRITER;
# wait for command from parent
while (my $line = <READER>)
{
print "$line\n";
exec($line); # execute command
}
}
else
{
#close READER;
# send child a command
sleep 1;
print WRITER $zeile;
if($zahl == 4) # four children are running. wait till one of them finishes.
{
while(! wait()) # *waiting*
{
}
print "returncode ".$?."\n";
$zahl--; # decrease number of children
}
}
}
}
else
{
print "\nCan't open file /sls_backup/mdjanan/sleep.txt\n";
}
exit 0;
# Waits for zombies
#sub reaper
#{
# wait(); # grab a zombie
#} # sub reaper
1
2
3
4
5
6
7
ps -ef | grep sleep
root 25610 13616 0 11:17:02 pts/1 0:00 /bin/perl -w ./sleep.pl
root 25625 25610 0 11:17:07 pts/1 0:00 sleep 12
root 25614 25610 0 11:17:02 pts/1 0:00 sleep 11
root 25613 25610 0 11:17:02 pts/1 0:00 sleep 15
root 25634 25610 0 11:17:12 pts/1 0:00 /bin/perl -w ./sleep.pl
root 25636 17134 0 11:17:13 pts/2 0:00 grep sleep
1
2
3
4
5
6
if ($zahl < 4)
{
$zahl++; # increase number of children
$pid = fork(); # a new child is born. yay :)
print $pid."\n";
}
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
38
39
40
41
42
43
44
45
46
47
#!/bin/perl -w
use strict;
pipe(READER,WRITER); # used for communication between child and parent
my $zahl = 0; # number of currently running children
my $zeile; # row
my $pid; # process ID
if (open FILE, "< /sls_backup/mdjanan/sleep.txt")
{
while($zeile = <FILE>)
{
if ($zahl < 5)
{
$zahl++; # increase number of children
$pid = fork(); # a new child is born. yay :)
} # if ($zahl < 5)
if($pid != 0)
{
# parent-process
print WRITER $zeile; # send child a command
$| = 1; # flush pipe
if($zahl == 5) # four children are running. wait till one of them finishes.
{
while(! wait()) # *waiting*
{
} # while(! wait())
$zahl--; # decrease number of children
} # if($zahl == 5)
} # if($pid != 0)
else
{
# child-process
# wait for command from parent
while (my $line = <READER>)
{
exec($line); # execute command
} # while (my $line = <READER>)
} # else
} # while($zeile = <FILE>)
} # if (open FILE, "< /sls_backup/mdjanan/sleep.txt")
else
{
print "\nCan't open file /sls_backup/mdjanan/sleep.txt\n";
} # else
exit 0;
10 Einträge, 1 Seite |