Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Question on SIGTERM

Reply
Thread Tools

Question on SIGTERM

 
 
wing328hk@gmail.com
Guest
Posts: n/a
 
      01-16-2007
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

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      01-16-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
wing328hk@gmail.com
Guest
Posts: n/a
 
      01-17-2007
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


(E-Mail Removed) wrote:
> (E-Mail Removed) wrote:
> > 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
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB


 
Reply With Quote
 
comp.llang.perl.moderated
Guest
Posts: n/a
 
      01-17-2007

(E-Mail Removed) wrote:
> (E-Mail Removed) wrote:
> > (E-Mail Removed) wrote:
> > > 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?
> >


>
> 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.

--
Charles DeRykus

 
Reply With Quote
 
wing328hk@gmail.com
Guest
Posts: n/a
 
      01-17-2007

comp.llang.perl.moderated wrote:
> (E-Mail Removed) wrote:
> > (E-Mail Removed) wrote:
> > > (E-Mail Removed) wrote:
> > > > 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?
> > >

>
> >
> > 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.
>
> --
> Charles DeRykus


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

 
Reply With Quote
 
comp.llang.perl.moderated
Guest
Posts: n/a
 
      01-17-2007
(E-Mail Removed) wrote:
> comp.llang.perl.moderated wrote:
>>> ....
> > > 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.


>
> 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.

--
Charles DeRykus

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Child process does not exit after receiving SIGTERM Teresa C Programming 2 04-06-2004 01:26 AM
RE: Repost: Can't sys.exit() from SIGTERM handler? Andrew Athan Python 0 01-06-2004 02:35 AM
Repost: Can't sys.exit() from SIGTERM handler? Andrew Athan Python 0 01-06-2004 01:27 AM
popen3,4 and SIGTERM Zoran Bosnjak Python 0 10-15-2003 03:01 PM
robust clean-up with SIGTERM (was Re: Again, how to write a cleanup function for a module in C ) Jane Austine Python 2 08-16-2003 04:01 AM



Advertisments