[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-win32-admin
Subject:    RE: fork Q
From:       "Gould, Kevin" <Kevin.Gould () gentiva ! com>
Date:       2003-08-15 21:17:23
[Download RAW message or body]

In your else clause, you need to exit after you're done your actions,
otherwise you fall out of your loop and the child will continue through
the loop forking, as well as the parent.

Kevin Gould
Sr. I/T Specialist
Gentiva Health Services, Overland Park, KS
913-814-2369


-----Original Message-----
From: Vinod Panikar [mailto:vinodp@mail.com] 
Sent: Friday, August 15, 2003 2:34 PM
To: perl-win32-admin@listserv.ActiveState.com
Subject: fork Q

I'm trying to use fork in this simple program.I've asked it to do create
only two child process in my program and it does six times, all six are
child process and no parent. I assume this to work as 1 parent and 2
children.

or may be, I'm not understanding fork function properly here

$ttime = time;

($s, $m,$h) = localtime($ttime);

print "\n Start in PARENT : hour=$h min=$m sec=$s\n";

$children="2";

for ($i=0; $i<$children; $i++) {

	if (!defined($pid=fork())) 
	{
	die "\n cannot fork: $! \n";
	}

	else 

	{
	system ("dir /w");
	#print " child process \n";
	$ttime = time;
	($s, $m,$h) = localtime($ttime);
	
	}
waitpid($i,0);
sleep(1);
} # end loop 

Any thoughts here?

Thanks in advance!
-- 
__________________________________________________________
Sign-up for your own personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

CareerBuilder.com has over 400,000 jobs. Be smarter about your job
search
http://corp.mail.com/careers

_______________________________________________
Perl-Win32-Admin mailing list
Perl-Win32-Admin@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Admin mailing list
Perl-Win32-Admin@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic