문제

I'm writing a program on Linux in C, and I'd like to wait (using select or poll) for a pipe file descriptor to become broken, e.g. I'd like to wait up to the point when a subsequent write(2) would return EPIPE (or SIGPIPE would be sent). Adding the file descriptor to the writefds or the exceptfds argument of select doesn't solve the problem. I know that I can solve this by creating multiple processes or threads, but in this question I'm only interested in single-process, single-thread solutions, preferably involving select and poll (because I want to wait on other file descriptor events as well). I cannot make any assumption about who are on the other end of the pipe -- the solution must work if those processes are far away in the process tree.

I'd prefer a solution which is portable across many Unix systems (not just Linux).

도움이 되었습니까?

해결책

Calling poll(2) with POLLHUP on the write-end of the pipe seems to have done trick on Linux.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top