[SOLVED] How to handle a broken pipe exception (SIGPIPE) in FIFO pipe?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
How to handle a broken pipe exception (SIGPIPE) in FIFO pipe?
I've written a simple server in linux used fork to create a FIFO pipe.The server create two FIFO pipe.One for server read data from client and write data to client.Then another pipe for client read data from server and write data to server.
When the server read data from a client used server-pipe and then write data to client.But ,if the client no read open the pipe,the server side write will be crashed because of a broken-pipe SIGPIPE.
How to check whether the read side is opened?Or,how to catch the SIGPIPE,and then my server will still execute on,not crashed!!
Thank you very much!I'm on line waiting for your answer!Thanks!
You should check for errors after write or fflush; if errno isn't either EINTR or EAGAIN you should generally stop writing to the pipe for good. EPIPE is one of those errors, which you get if SIGPIPE doesn't terminate the process.
You can also use send instead of write to write to a socket. If you use the MSG_NOSIGNAL flag for send, the SIGPIPE signal will not be sent: the call will just return (ssize_t)-1 with errno set to EPIPE.
halon1301 's method is ok,can used to solve this problem.But I used signal(SIGPIPE,SIG_IGN) to ignore the SIGPIPE exception when occured write to a closed read pipe in the other side.
I use FIFO pipe in block style,so have this problem that when to write first to chek read is or not opend yet.Otherwise wite will SIGPIPE.But I think there is some good way to solved this issue.
I used (SIGPIPE,SIG_IGN),then is no problem.
Thank you very muchu to all helped me!Thank you!!!