Question on SIGTERM

W

wing328hk

Hi,

I need to pipe a data stream to STDIN and I'm only interesting in the
first line so I do

my $header = <STDIN>;

To read the rest of the data stream, I do

do {
my $buf = "";
1 while (read(STDIN, $buf, 1024));
};

Would I get SIGPIPE if I don't use the do loop to get the rest of the
message?

Basically, how can I discard the rest of the message from STDIN? The
data stream can be huge (30MB...) and that's why I don't want to waste
CPU time in reading something I don't need.

Would it make a different to above questions if the above code is part
of a child process and there will be several child processes running
simultaneously reading from different data stream from pipe??

Thanks,
wing328hk
 
X

xhoster

Hi,

I need to pipe a data stream to STDIN and I'm only interesting in the
first line so I do

my $header = <STDIN>;

To read the rest of the data stream, I do

do {
my $buf = "";
1 while (read(STDIN, $buf, 1024));
};

Would I get SIGPIPE if I don't use the do loop to get the rest of the
message?

"You" (i.e. the process (not) doing the reading) wouldn't get a SIGPIPE.
The process writing to "you" might get a SIGPIPE.
Basically, how can I discard the rest of the message from STDIN?

Don't read it. Either close the filehandle without reading the rest, or
just exit the program without reading the rest.
The
data stream can be huge (30MB...) and that's why I don't want to waste
CPU time in reading something I don't need.

Why waste time *writing* something you don't need? If you have control
over the writing process (which it seems you do, as you call the
reading process a child), fix it.
Would it make a different to above questions if the above code is part
of a child process and there will be several child processes running
simultaneously reading from different data stream from pipe??

Where do they get these different data streams from? Do you care whether
the writing process gets a SIGPIPE? If so, why?

Xho
 
W

wing328hk

Hi,

Thanks for the prompt reply. Sorry that I should have provided more
information about the scenario.

The data stream I was talking about is a mail pipe, so my question
becomes would the mail program gets the SIGPIPE? I think yes based on
the reply below.

My next question is would it be possible to close the data stream from
the client side (basicaly my script below that aims to read the first
line or the mail header only) without reading all the data and without
sending an SIGPIPE back to the mail program?

Thanks,
wing328hk
 
C

comp.llang.perl.moderated

Thanks for the prompt reply. Sorry that I should have provided more
information about the scenario.

The data stream I was talking about is a mail pipe, so my question
becomes would the mail program gets the SIGPIPE? I think yes based on
the reply below.

My next question is would it be possible to close the data stream from
the client side (basicaly my script below that aims to read the first
line or the mail header only) without reading all the data and without
sending an SIGPIPE back to the mail program?

You could cause the rest of the stream to be discarded:

my( $header ) = <STDIN>; # instead of: my $header = <STDIN>

this'll avoid the SIGPIPE.
 
W

wing328hk

comp.llang.perl.moderated said:
You could cause the rest of the stream to be discarded:

my( $header ) = <STDIN>; # instead of: my $header = <STDIN>

this'll avoid the SIGPIPE.

But using
my( $header ) = <STDIN>;
would still read all the data from the pipe, and then assign first line
to $header, right? or it has the intelligence to read only the first
line into $header and discard the rest.

I want to avoid reading all the data from the pipe, which can be huge
(~3MB). I'm only interested in email headers (ie the first few lines of
data).

Thanks,
wing328hk
 
C

comp.llang.perl.moderated

But using
my( $header ) = <STDIN>;
would still read all the data from the pipe, and then assign first line
to $header, right? or it has the intelligence to read only the first
line into $header and discard the rest.

I want to avoid reading all the data from the pipe, which can be huge
(~3MB). I'm only interested in email headers (ie the first few lines of
data).

Yes, then we've reached an impasse. You can just just continue
to read the first line of the stream and quit of course ... but then
the SIGPIPE occurs when the next line gets written to the pipe
upstream. Does your upstream process there terminate with
"Broken pipe"... What problem are you trying to solve...?

As Xho mentioned earlier, you'd have to handle this upstream
on the write end of the pipe if that's problematic. If you're able to
catch or ignore the signal from that end or, better yet, filter the
stream and write only the first line, then the problem is solvable.
It may be as easy as including a 'local $SIG{PIPE} = 'IGNORE'...
but it may be more complicated. More details about your program
are needed.
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top