- 论坛徽章:
- 0
|
我的系统是redhat-2.4.32,向一个对端未打开的FIFO进行写操作,不会引发SIGPIPE,但是man 4 fifo上面说这样做会引发SIGPIPE
- NOTES
- When a process tries to write to a FIFO that is not opened for read on
- the other side, the process is sent a SIGPIPE signal.
- FIFO special files can be created by mkfifo(3), and are specially indi-
- cated in ls -l.
- SEE ALSO
- mkfifo(3), mkfifo(1), pipe(2), socketpair(2), open(2), signal(2),
- sigaction(2)
- Linux Man Page 1999-06-20 FIFO(4)
- (END)
复制代码
在man 2 write 中对于EPIPE是这么描述的,不知道它所说的 "pipe or socket" 中的 pipe是否包含fifo( named pipe )
- EPIPE fd is connected to a pipe or socket whose reading end is closed.
- When this happens the writing process will also receive a SIG-
- PIPE signal. (Thus, the write return value is seen only if the
- program catches, blocks or ignores this signal.)
复制代码
疑惑中,测试代码
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <stdio.h>
- #include <string.h>
- #include <signal.h>
- void sigpipe( int )
- {
- printf( "caught signal\n" );
- }
- int main( int argc, char* argv[] )
- {
- const char* msg = "test";
- mkfifo( "fifo", 00777 );
- int fd = open( "fifo", O_RDWR );
- if( -1 == fd )
- {
- perror( "open" );
- return -1;
- }
- struct sigaction sigact;
- sigact.sa_handler = sigpipe;
- sigemptyset( &sigact.sa_mask );
- sigact.sa_flags = 0;
- if( -1 == sigaction( SIGPIPE, &sigact, NULL ) )
- {
- perror( "sigaction" );
- return -1;
- }
- while( 1 )
- {
- // should lead to caught SIGPIPE
- if( -1 == write( fd, msg, strlen( msg ) ) )
- {
- perror( "write" );
- return -2;
- }
- }
- return 0;
- }
复制代码 |
|