[26570] in Perl-Users-Digest
Perl-Users Digest, Issue: 8707 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 25 21:05:17 2005
Date: Fri, 25 Nov 2005 18:05:03 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 25 Nov 2005 Volume: 10 Number: 8707
Today's topics:
Re: potential problem with fork() xhoster@gmail.com
Re: potential problem with fork() <tadmc@augustmail.com>
Re: potential problem with fork() <nospam-abuse@ilyaz.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Nov 2005 21:32:56 GMT
From: xhoster@gmail.com
Subject: Re: potential problem with fork()
Message-Id: <20051125163256.083$D9@newsreader.com>
bsder <snort_sam@yahoo.com> wrote:
> Hi,
>
> I m not sure whether the following Perl code is correct with fork().
>
> while (1) {
> if (open( FILE, "< $books" ) {
Syntax error, unbalanced parens. Also, you wouldn't you want to do
something more intelligent in case the file can't be opened?
> if (!defined($kidpid = fork())) {
> die "cannot fork: $!";
> }
> elsif ($kidpid == 0) { # child
> child_func();
child_func() had better never return, or else you are making a fork-bomb.
> }
> else # parent.
> sleep(1);
> }
> }
>
> Can anyone please give comment and suggestion of improving it?
Without knowing what it is supposed to do?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Fri, 25 Nov 2005 11:09:51 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: potential problem with fork()
Message-Id: <slrndoehav.4a4.tadmc@magna.augustmail.com>
bsder <snort_sam@yahoo.com> wrote:
> I m not sure whether the following Perl code is correct with fork().
>
> while (1) {
> if (open( FILE, "< $books" ) {
> if (!defined($kidpid = fork())) {
> die "cannot fork: $!";
> }
Control can never get here if the fork() failed, so...
> elsif ($kidpid == 0) { # child
... you don't need an elsif, just an if would do.
> child_func();
> }
Control can never get here in the child process, so ...
> else # parent.
... you don't need an else at all.
(and if you did need an else, you would need an opening curly bracket)
> sleep(1);
> }
> }
>
> Can anyone please give comment and suggestion of improving it?
# untested
while (1) {
if (open( FILE, "< $books" ) {
die "cannot fork: $!" unless defined($kidpid = fork());
if ($kidpid == 0) { # child
child_func();
}
# parent
sleep(1);
}
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 25 Nov 2005 22:30:21 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: potential problem with fork()
Message-Id: <dm839t$n2o$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Tad McClellan
<tadmc@augustmail.com>], who wrote in article <slrndoehav.4a4.tadmc@magna.augustmail.com>:
> # untested
> while (1) {
> if (open( FILE, "< $books" ) {
> die "cannot fork: $!" unless defined($kidpid = fork());
>
> if ($kidpid == 0) { # child
> child_func();
> }
> # parent
How should I guess looking on this code that child_func() never
returns? IMO, one should at least move exit() out of child_func()
into the main loop to make the intent clear...
> sleep(1);
> }
> }
Hope this helps,
Ilya
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8707
***************************************