S
Simon
Hi guys!
I have the following fork script:
================================
my $child_pid = fork;
if ($child_pid) {
predator($child_pid);
print "$child_pid";
}
elsif (defined($child_pid)) {
back();
exit;
}
else
{
warn "fork failed: $!\n";
}
sub predator {
print `ping -n 30 predator`;
}
sub back {
print `ping -n 30 backup`;
}
===================================
Output is as follows..
C:\TEMP>hi.pl
Pinging predator [192.168.2.4] with 32 bytes of data:
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
-122
Pinging backup [192.168.2.2] with 32 bytes of data:
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
C:\TEMP>
================================================
What Id like to know is:
1) There is no output on the screen until each process is complete, so I get
a quick flash of the above as output.
Is there any way to kick off the child and parent simultaneously in a new
command window, and see each line eg.each ping reply line by line?
2) Im trying to understand how I can utilize the benefits of fork. Can you
kick off more than 2 processes eg.child and parent, so that you could do
this, for say, 20 systems?
Eg. so you would have 20 instances of this script each pinging a different
system, each in its own command window?
Any help appreciated.
I have the following fork script:
================================
my $child_pid = fork;
if ($child_pid) {
predator($child_pid);
print "$child_pid";
}
elsif (defined($child_pid)) {
back();
exit;
}
else
{
warn "fork failed: $!\n";
}
sub predator {
print `ping -n 30 predator`;
}
sub back {
print `ping -n 30 backup`;
}
===================================
Output is as follows..
C:\TEMP>hi.pl
Pinging predator [192.168.2.4] with 32 bytes of data:
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
Reply from 192.168.2.4: bytes=32 time<10ms TTL=128
-122
Pinging backup [192.168.2.2] with 32 bytes of data:
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
Reply from 192.168.2.2: bytes=32 time<10ms TTL=128
C:\TEMP>
================================================
What Id like to know is:
1) There is no output on the screen until each process is complete, so I get
a quick flash of the above as output.
Is there any way to kick off the child and parent simultaneously in a new
command window, and see each line eg.each ping reply line by line?
2) Im trying to understand how I can utilize the benefits of fork. Can you
kick off more than 2 processes eg.child and parent, so that you could do
this, for say, 20 systems?
Eg. so you would have 20 instances of this script each pinging a different
system, each in its own command window?
Any help appreciated.