Re: Simple fork examples
- From: QoS@xxxxxxxxxxxxxx
- Date: Fri, 29 Jun 2007 14:43:17 GMT
"Simon" <shmh@xxxxxxxxxxxxxx> wrote in message-id: <XF8hi.1000$4A1.769@xxxxxxxxxxxxxxxxxxxxxxxxxx>
[snip]
I ran your script, and got the following..
C:\>ballsonforehead.pl
Use of uninitialized value in foreach loop entry at C:\ballsonforehead.pl
line 9
.
Use of uninitialized value in foreach loop entry at C:\ballsonforehead.pl
line 9
.
"it_says_BALLS_on_your forehead" <simon.chao@xxxxxxx> wrote in message
news:1183126806.423422.290430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jun 29, 10:13 am, "Simon" <s...@xxxxxxxxxxxxxx> wrote:
Hi guys!
I have read through the perldoc and must be really stupid.
I want to get my hands on some really basic example scripts of using
fork,
and what it is used for.
Ive looked on the net and cant find too many examples of this anywhere,
that
I can get a grip on.
use strict; use warnings;
$| = 1;
my $num_kids = shift;
^
notice the shift does not supply a default.
you must start this script with a integer as an argument.
my $pid;
for my $i ( 1.. $num_kids ) {
$pid = fork;
die "couldn't fork" if (!defined $pid);
if ( $pid == 0 ) {
print "$i about to sleep 3 secs...\n";
sleep 3;
print "$i done sleeping!\n";
exit;
}
print "pid '$pid'...i am parent\n";
}
do {
$pid = waitpid( -1, 0 );
} until $pid == -1;
In addition, if you want the script to work on more platforms,
afaik it is better to use threads.
.
- Follow-Ups:
- Re: Simple fork examples
- From: Martijn Lievaart
- Re: Simple fork examples
- References:
- Simple fork examples
- From: Simon
- Re: Simple fork examples
- From: it_says_BALLS_on_your forehead
- Re: Simple fork examples
- From: Simon
- Simple fork examples
- Prev by Date: Re: Simple fork examples
- Next by Date: Re: Simple fork examples
- Previous by thread: Re: Simple fork examples
- Next by thread: Re: Simple fork examples
- Index(es):
Relevant Pages
|
|