|
Home > Archive > Unix Programming > January 2006 > How to detect that stdin was closed.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to detect that stdin was closed.
|
|
| Karl_Schmitt_1969@yahoo.com 2006-01-23, 7:52 am |
| 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
| |
| Rainer Temme 2006-01-23, 7:52 am |
| 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
| |
| Barry Margolin 2006-01-23, 8:49 pm |
| 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 ***
| |
| Hubble 2006-01-24, 7:51 am |
| >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
|
|
|
|
|