Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

interrupted system call error when writing to a pipe

Tags:

unix

pipe

signals

In my user space Linux application, I have a thread which communicated to the main process through a pipe. Below is the code

static void _notify_main(int cond)
{
    int r;
    int tmp = cond;

    r = write( _nfy_fd, &tmp, sizeof(tmp) );
    ERROR( "write failed: %d. %s\n",  r, strerror(r) );
}

Pretty straight forward. It's been working fine for quite a while now. But recently, the write call will fail with "interrupted system call" error after the programme went under some stress test.

Strangely, the stuff actually went through the pipe no problem. Of course I'd still like to go to the bottom of the error message and get rid of it.

Thanks,

like image 693
lang2 Avatar asked Sep 03 '25 16:09

lang2


1 Answers

The write(2) man page mentions:

Conforming to SVr4, 4.3BSD, POSIX.1-2001.

Under SVr4 a write may be interrupted and return EINTR at any point, not just before any data is written.

I guess you were just lucky that it didn't occur so far.

If you google just for the "interrupted system call", you will find this thread which tells you to use siginterrupt() to auto-restart the write call.

like image 88
blubb Avatar answered Sep 05 '25 14:09

blubb