Question about why a pipe doesn't block

G

grocery_stocker

When I run the bbs system on my computer, I get the following

m-net% bbs
YAPP 3.1.1 Copyright (c)1995 Armidale Software
Registered to: Arbornet

Welcome to the
February General Conference


fairwitness: jerryr

22 newresponse items and 3 brandnew items
First item 1, last 46

Ok:

And the cursor just hangs at the block until I type exit. Now, when I
run the 'bbs program' using the following perl script

m-net% more bbs.pl
#!/usr/bin/perl

use strict;
use warnings;

open my $out, '|-', 'bbs' or die "cannot open pipe to bbs: $!";

#print $out "browse\n";

#close $out or die "cannot close pipe to t.exe: $!";
m-net% ./bbs.pl

The program runs and just exits.

YAPP 3.1.1 Copyright (c)1995 Armidale Software
Registered to: Arbornet

Welcome to the
February General Conference


fairwitness: jerryr

22 newresponse items and 3 brandnew items
First item 1, last 46

Now leaving February General...
m-net%

What is causing the script to exit? Even when I uncomment out close ,
I still get the exact same behavior
 
X

xhoster

grocery_stocker said:
And the cursor just hangs at the block until I type exit. Now, when I
run the 'bbs program' using the following perl script

m-net% more bbs.pl
#!/usr/bin/perl

use strict;
use warnings;

open my $out, '|-', 'bbs' or die "cannot open pipe to bbs: $!";

#print $out "browse\n";

#close $out or die "cannot close pipe to t.exe: $!";
m-net% ./bbs.pl

The program runs and just exits.
....

What is causing the script to exit?

It ran out of code to execute. Why wouldn't it exit?
Even when I uncomment out close ,
I still get the exact same behavior

When perl runs out of code to execute, it starts doing the clean-up for
exit. As part of this, it closes the file handle, even if you didn't
explicitly request it. After doing so, it probably waits for the child to
exit, as it was a piped open. The bbs almost instantly sees that its input
has been closed, so it exits, satisfying Perl's wait so the wait blocks for
a teeny tiny time. Is this the blocking you were thinking of?

If not, what exactly did you think would block, and where and why do you
think it would do so?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
W

WANG Cong

grocery_stocker said:
m-net% more bbs.pl
#!/usr/bin/perl

use strict;
use warnings;

open my $out, '|-', 'bbs' or die "cannot open pipe to bbs: $!";

#print $out "browse\n";

#close $out or die "cannot close pipe to t.exe: $!";

What is causing the script to exit? Even when I uncomment out close ,
I still get the exact same behavior

Because your perl program is in the write end of a pipe, why
should it block?
 
K

K-mart Cashier

...












It ran out of code to execute. Why wouldn't it exit?


When perl runs out of code to execute, it starts doing the clean-up for
exit. As part of this, it closes the file handle, even if you didn't
explicitly request it. After doing so, it probably waits for the child to
exit, as it was a piped open. The bbs almost instantly sees that its input
has been closed, so it exits, satisfying Perl's wait so the wait blocks for
a teeny tiny time. Is this the blocking you were thinking of?

If not, what exactly did you think would block, and where and why do you
think it would do so?

Wait. I forgot why I asked this question. I'm serious. I was going
through some kind of weird sleep deprivation when I did this post.
Later on today, I might remember what I was tryinging to ask, and then
post a followup question.
 
R

Rainer Weikusat

WANG Cong said:
Because your perl program is in the write end of a pipe, why
should it block?

Waiting for buffer space. But since the program isn't doing anything
except createing a pipe, how can it possibly wait for something to
become available? It will immediately exit, causing the BBS to
receive an EOF indication on its standard input and to subsequently
exit, too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top