pollpipe.c

来自「APUE(第二版)的随书源代码,与第一版的代码相比增加了一些章节的代码(详见第二」· C语言 代码 · 共 31 行

C
31
字号
#include	<sys/types.h>#include	<poll.h>#include	<stdio.h>#include	<stdlib.h>#include	<stropts.h>#include	<unistd.h>#include	"ourhdr.h"intmain(void){	int				i, n, fd[2];	struct pollfd	fdarr[1];	if (pipe(fd) < 0)		err_sys("pipe error");	for (n = 0; ; n++) {		fdarr[0].fd = fd[1];		fdarr[0].events = POLLOUT;		if ( (i = poll(fdarr, 1, 0)) < 0)			err_sys("poll error");		else if (i == 0)			break;		if (write(fd[1], "a", 1) != 1)			err_sys("write error");	}	printf("pipe capacity = %d\n", n);	exit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?