[英]named pipe terminating session
我正在编写一个轮询命名管道缓冲区的简短程序。 为了进行测试,我将登录“ nobody”并回显到管道中。 挂起时,我从其他用户登录并运行读取缓冲区的程序。 运行该程序时,该程序不返回任何内容,并且另一个用户退出系统。 这是读取功能:
void ReadOut( char * buf )
{
ZERO_MEM( buffer, BUF_SIZE );
int pipe = open( buf, O_RDONLY | O_NONBLOCK );
if( pipe < 0 )
{
printf( "Error %d has occured.\n" , pipe );
return;
}
while( read( pipe, buffer, 2 ) > 0 ) printf( "%s \n" , buffer );
close( pipe );
return;
}
当我取出O_NONBLOCK时,此功能也有效
当您将文件描述符标记为非阻塞时,通常可以阻塞的所有操作(例如read(2)
和write(2)
)都将返回-1
并设置errno = EAGAIN
。
因此,在您的情况下, read
立即返回-1,表示“ 我现在尚未准备好,请稍后再试 ”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.