[17833] in Perl-Users-Digest
Perl-Users Digest, Issue: 5253 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 5 00:38:49 2001
Date: Thu, 4 Jan 2001 21:38:22 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978673102-v9-i5253@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 4 Jan 2001 Volume: 9 Number: 5253
Today's topics:
What's wrong with this 2-child fork/wait? <davesisk@ipass.net>
Re: What's wrong with this 2-child fork/wait? <stephenk@cc.gatech.edu>
Re: What's wrong with this 2-child fork/wait? (Greg Bacon)
Re: What's wrong with this 2-child fork/wait? (Randal L. Schwartz)
where do I post an ad for a job? <matt@cipherdesign.com>
Re: where do I post an ad for a job? (Martien Verbruggen)
Re: Why are multiple zeroes true? <ddunham@redwood.taos.com>
win32:netresource help <bruceypants@worldnet.att.net>
window NT and perl <north@nmpm.com.my>
Re: window NT and perl (Josh Geller)
Re: window NT and perl <lvon5150@hotmail.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 03 Jan 2001 19:28:46 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: What's wrong with this 2-child fork/wait?
Message-Id: <O3L46.76576$sr6.13539144@typhoon.southeast.rr.com>
#!/usr/bin/perl -w
# fork 1st child process
if (!defined($kidpid = fork())) {
# fork returned undef, so failed
die "cannot fork: $!";
}
# fork 2nd child process
if (!defined($kidpid = fork())) {
# fork returned undef, so failed
die "cannot fork: $!";
}
# if I'm a child, do this, otherwise, I must be the parent.
if ($kidpid == 0) {
# fork returned 0, so this branch is the child
sleep 1;
exec("echo I'm the child process");
# if the exec fails, fall through to the next statement
die "can't exec echo: $!";
} else {
print "I'm the parent process waiting\n";
wait;
print "I'm the parent process finished waiting\n";
}
The output that I get is:
I'm the parent process waiting
I'm the parent process waiting
I'm the child process
I'm the child process
I'm the parent process finished waiting
I'm the parent process finished waiting
What I expected to get was:
I'm the parent process waiting
I'm the child process
I'm the child process
I'm the parent process finished waiting
What am I doing wrong here?
Best regards,
Dave
------------------------------
Date: Wed, 03 Jan 2001 15:56:45 -0500
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: What's wrong with this 2-child fork/wait?
Message-Id: <3A53920C.8512329C@cc.gatech.edu>
David Sisk wrote:
> #!/usr/bin/perl -w
>
> # fork 1st child process
> if (!defined($kidpid = fork())) {
> # fork returned undef, so failed
> die "cannot fork: $!";
> }
>
> # fork 2nd child process
> if (!defined($kidpid = fork())) {
> # fork returned undef, so failed
> die "cannot fork: $!";
> }
>
This code is executed by both the parent and the first child. The
result is 4 processes. Is this what you wanted?
>
> # if I'm a child, do this, otherwise, I must be the parent.
> if ($kidpid == 0) {
> # fork returned 0, so this branch is the child
> sleep 1;
> exec("echo I'm the child process");
> # if the exec fails, fall through to the next statement
> die "can't exec echo: $!";
> } else {
> print "I'm the parent process waiting\n";
> wait;
> print "I'm the parent process finished waiting\n";
> }
>
> The output that I get is:
> I'm the parent process waiting
> I'm the parent process waiting
> I'm the child process
> I'm the child process
> I'm the parent process finished waiting
> I'm the parent process finished waiting
>
This output is consistent with 4 processes, 2 "parents" and 2
"children".
>
> What I expected to get was:
> I'm the parent process waiting
> I'm the child process
> I'm the child process
> I'm the parent process finished waiting
>
>
This is consistent with 1 parent, 2 children.
> What am I doing wrong here?
>
Simply make sure the second fork is only executed by one process.
It would be useful to have each echo also display process ID.
HTH HAND
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: Wed, 03 Jan 2001 21:16:34 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: What's wrong with this 2-child fork/wait?
Message-Id: <t575linso5f268@corp.supernews.com>
In article <O3L46.76576$sr6.13539144@typhoon.southeast.rr.com>,
David Sisk <davesisk@ipass.net> wrote:
: [code]
:
: The output that I get is:
: I'm the parent process waiting
: I'm the parent process waiting
: I'm the child process
: I'm the child process
: I'm the parent process finished waiting
: I'm the parent process finished waiting
:
: What I expected to get was:
: I'm the parent process waiting
: I'm the child process
: I'm the child process
: I'm the parent process finished waiting
:
: What am I doing wrong here?
First off, I'd like to (without condescending) point out how nicely
you laid out your problem. You gave a small, working example and
what you expected (which, in this case, is self-evidently different
from the output). If more poeple followed your example, this would
be a much more pleasant newsgroup for all.
What's wrong is your conceptual model. Watch what happens when we
add pids to the output:
6309: I'm the parent process waiting
13846: I'm the parent process waiting
5951: Im the child process
6309: I'm the parent process finished waiting
205: Im the child process
13846: I'm the parent process finished waiting
Notice that there are four processes (6309, 13846, 5951, and 205) at
work, not the three that you expected. The two parents come from the
first call to fork() and the two kids from the second. If you only
want three processes, change the second fork to
# fork 2nd child process
if ($kidpid) {
if (!defined($kidpid = fork())) {
# fork returned undef, so failed
die "$$: cannot fork: $!";
}
}
so it only runs in the parent. If this is a long-running process,
you need to add code to make sure you're waiting for all children
(your code doesn't) or you'll be overrun with zombies. See the
perlipc manpage.
You might also benefit from a reading of mjd's "Suffering from
Buffering" article: <URL:http://perl.plover.com/FAQs/Buffering.html>.
Greg
--
In Christianity neither morality nor religion come into contact with reality
at any point.
-- Nietzsche
------------------------------
Date: 04 Jan 2001 08:19:29 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: What's wrong with this 2-child fork/wait?
Message-Id: <m17l4bmgry.fsf@halfdome.holdit.com>
>>>>> "David" == David Sisk <davesisk@ipass.net> writes:
David> #!/usr/bin/perl -w
Starting in process 1...
David> # fork 1st child process
David> if (!defined($kidpid = fork())) {
David> # fork returned undef, so failed
David> die "cannot fork: $!";
David> }
Now we have process 1 and 2 running here.
David> # fork 2nd child process
David> if (!defined($kidpid = fork())) {
David> # fork returned undef, so failed
David> die "cannot fork: $!";
David> }
Now process 1 begat 3. And 2 begat 4. Did you really want
4 processes?
David> # if I'm a child, do this, otherwise, I must be the parent.
David> if ($kidpid == 0) {
So processes 2 and 4 run this...
David> # fork returned 0, so this branch is the child
David> sleep 1;
David> exec("echo I'm the child process");
David> # if the exec fails, fall through to the next statement
David> die "can't exec echo: $!";
David> } else {
David> print "I'm the parent process waiting\n";
And processes 1 and 3 run this...
David> wait;
David> print "I'm the parent process finished waiting\n";
David> }
Does that explain it?
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 3 Jan 2001 11:58:47 +0000
From: Matt Venn <matt@cipherdesign.com>
Subject: where do I post an ad for a job?
Message-Id: <n54v29.c6f.ln@server.localnet>
I want to post a job description that requires *NIX/perl/apache. I was
told there was a perl.jobs.announce newsgroup but I can't find it
(probably because my provider doesn't provide it). Can someone tell me the
exact name of the newsgroup so I can ask my provider to sort it out.
Thanks, Matt
--
#!/usr/bin/perl
open(S,$0);while(<S>){if(/l(.*?$l)/x){
print chr($ Al+ $A+10*(length $1) +(length
>39?86:77));$l= $ l?'\$':'\(';}}print"\n";
------------------------------
Date: Wed, 3 Jan 2001 23:47:55 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: where do I post an ad for a job?
Message-Id: <slrn9567rr.edk.mgjv@martien.heliotrope.home>
On Wed, 3 Jan 2001 11:58:47 +0000,
Matt Venn <matt@cipherdesign.com> wrote:
> I want to post a job description that requires *NIX/perl/apache. I was
> told there was a perl.jobs.announce newsgroup but I can't find it
> (probably because my provider doesn't provide it). Can someone tell me the
> exact name of the newsgroup so I can ask my provider to sort it out.
http://www.duke.edu/~mg/usenet/newsgroups.html
(At least one link is out of date, and should be
ftp://ftp.uu.net/archive/networking/news/config/active.gz)
[Warning: Horrible long URL wrapped]
http://dir.yahoo.com/Computers_and_Internet/internet/
chats_and_forums/usenet/newsgroup_directories/
Martien
--
Martien Verbruggen |
Interactive Media Division | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd. | you come to the end; then stop.
NSW, Australia |
------------------------------
Date: Wed, 03 Jan 2001 22:23:11 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Why are multiple zeroes true?
Message-Id: <jDN46.54$Yp6.59479@news.pacbell.net>
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "DD" == Darren Dunham <ddunham@redwood.taos.com> writes:
> DD> 1) If it's not reasonable, and we want to specify a different line,
> DD> where do we draw it? Which of the following should be false? Every
> DD> one of them is false when compared numerically.
> comparing numerically is not the same as boolean context in perl.
Hmm. I must not have been clear.
I was trying to give a list of strings that someone *could* argue should
be regarded as 'false' in boolean context. At the moment, all but '0'
are false, but some have argued that '00' should be also. I was
wondering for someone that argues for truth for '00', where do you draw
the line?
> $foo == 1 is not a boolean context but it generates a boolean value (see
> tom's much earlier post for a subtle nicety of that value).
I'm using if ($string) for my examples.
> DD> '0'
> false
> DD> '00'
> DD> '0000000'
> DD> '000000.000000'
> DD> '0.0.0'
> DD> '0 ' (trailing/leading space within the string)
> all true
I wasn't asking which *are* true now. Every one of them is true in
boolean context. I was trying to give examples and find where someone
wants to draw the line (assuming that someone was arguing that '00'
should be false).
> DD> 2) Does this really bust folks much? Any time I think I might be
> DD> getting a string (because I'm reading a file rather than doing a
> DD> calculation), I'll put in an explicit ($i != 0) test.
> that is not a boolean context. you are explicitly checking against a
> numeric value of 0. this has nothing to do with the false values in
> perl.
Exactly what I intended (but poorly phrased). I am massaging it into
numeric context because I care about the *value* of the string. I don't
understand what evaluating a string in boolean context means. My idea
is that the empty string should be false and all other strings should be
true. It so happens that perl follows that rule except for the string
'0'.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< Please move on, ...nothing to see here, please disperse >
------------------------------
Date: Wed, 03 Jan 2001 04:07:45 GMT
From: "Bruce Bowden" <bruceypants@worldnet.att.net>
Subject: win32:netresource help
Message-Id: <lAx46.317$jO.25396@bgtnsc06-news.ops.worldnet.att.net>
anybody out there have a *real-world* example of using the win32:netresource
module to create a share on an NT server? The perl-in-a-nutshell book (as
well as many a website) has the basic syntax but I can't find any code where
anyone has really used it.
suppose I have something like:
%share_info = (
netname => "$name",
type => RESOURCETYPE_DISK,
remark => "",
permissions => "",
maxusers => "".
current-usersa => "",
path => "c:\\somepath",
passwd => ""
);
...are the empty strings allowed? Is the type set up correctly? I was
planning to use some XCACLS command redirection to set NTFS perms before or
after establishing the share. The NT util 'net share' works interactively
and does not give me what I want in my Perl script. Also, do I just execute
this with the NetShareAdd (\%share_info, $error, local) function and it is
done? Any tips on installing the module, other libraries that are required,
etc.?
Any help for the novice is greatly appreciated!
-bruce-
------------------------------
Date: Thu, 04 Jan 2001 08:25:28 +0800
From: miss <north@nmpm.com.my>
Subject: window NT and perl
Message-Id: <3A53C2F7.8E66B60E@nmpm.com.my>
Dear all;
Before this i using win98 for my perl program,it work fine.
now i would like to move my thing to window NT(as server)
I copy(copy,not install) the active perl to c directory in win NT,but
can't work.
Does anyone know how to do a web publishing in WINDOW NT ????
Thanks very much.
------------------------------
Date: 4 Jan 2001 04:09:37 GMT
From: dclxvi@best.com (Josh Geller)
Subject: Re: window NT and perl
Message-Id: <930t21$n5p$1@nntp1.ba.best.com>
In article <3A53C2F7.8E66B60E@nmpm.com.my>, miss <north@nmpm.com.my> wrote:
> Before this i using win98 for my perl program,it work fine.
> now i would like to move my thing to window NT(as server)
> I copy(copy,not install) the active perl to c directory in win NT,but
> can't work.
Is there a reason that you must do this?
Installing it works fine.
------------------------------
Date: Thu, 04 Jan 2001 09:19:22 GMT
From: "lvon" <lvon5150@hotmail.com>
Subject: Re: window NT and perl
Message-Id: <ueX46.132113$I5.3339896@news1.rdc1.sdca.home.com>
Win98 & WinNT are different, ie: C:\windows\system vs. C:\winnt\system32.
Because Perl has an install procedure, you'll need to 'install' on WinNT,
which
is no big deal [unless it's someone elses' server]...
You may copy your script, but just copying the Perl directory is doomed for
failure.
"miss" <north@nmpm.com.my> wrote in message
news:3A53C2F7.8E66B60E@nmpm.com.my...
> Dear all;
>
> Before this i using win98 for my perl program,it work fine.
> now i would like to move my thing to window NT(as server)
>
> I copy(copy,not install) the active perl to c directory in win NT,but
> can't work.
>
> Does anyone know how to do a web publishing in WINDOW NT ????
>
> Thanks very much.
>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5253
**************************************