How to detect that stdin was closed.
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > How to detect that stdin was closed.




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    How to detect that stdin was closed.  
Karl_Schmitt_1969@yahoo.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-06 12:52 PM

Dear Folks,

I am new to Unix/Linux pipe programming.
My application is started from a process
control agent, and this agent closes
his stdout which is my stdin. My application
is supposed to detect that the closing event
and has to respond with an exit.
How can I detect assynchronusly that this pipe
connection has closed on the other end?

Thanks in advance, Karl






[ Post a follow-up to this message ]



    Re: How to detect that stdin was closed.  
Rainer Temme


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-06 12:52 PM

Karl_Schmitt_1969@yahoo.com wrote:

> My application is started from a process
> control agent, and this agent closes
> his stdout which is my stdin. My application
> is supposed to detect that the closing event
> and has to respond with an exit.
> How can I detect assynchronusly that this pipe
> connection has closed on the other end?

Hi Karl,

This can be done with the help of poll()/select().
Remember, that the FILE "stdin" is associated with
the filedescriptor 0 (STDIN_FILENO).

Regards ... Rainer








[ Post a follow-up to this message ]



    Re: How to detect that stdin was closed.  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-06 01:49 AM

In article <1138023311.016999.265040@g49g2000cwa.googlegroups.com>,
Karl_Schmitt_1969@yahoo.com wrote:

> Dear Folks,
>
> I am new to Unix/Linux pipe programming.
> My application is started from a process
> control agent, and this agent closes
> his stdout which is my stdin. My application
> is supposed to detect that the closing event
> and has to respond with an exit.
> How can I detect assynchronusly that this pipe
> connection has closed on the other end?

If you enable signal-based I/O on the pipe, you'll get a SIGIO signal
when the agent closes the pipe.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***





[ Post a follow-up to this message ]



    Re: How to detect that stdin was closed.  
Hubble


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-06 12:51 PM

>How can I detect assynchronusly that this pipe
>connection has closed on the other end?

You can also fcntl stdin to O_NDELAY and use read(2). If there is data,
read will read it. If there is no data, read will return with <0 and
errno will contain EAGAIN. If the writer closes the pipe, read will
return 0 indicating EOF. Details depend on the type of your
Unix/Linux/BSD system. Ok, if there are data, you acutally read them,
but nobody cares but you.


Hubble






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:40 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register