⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectpipe.c

📁 unix高级编程源代码.<<unix高级编程>>
💻 C
字号:
#include	<sys/types.h>
#include	<sys/time.h>
#include	"ourhdr.h"

int
main(void)
{
	int				i, n, fd[2];
	fd_set			writeset;
	struct timeval	tv;

	if (pipe(fd) < 0)
		err_sys("pipe error");
	FD_ZERO(&writeset);

	for (n = 0; ; n++) { /* write 1 byte at a time until pipe is full */
		FD_SET(fd[1], &writeset);
		tv.tv_sec = tv.tv_usec = 0;		/* don't wait at all */
		if ( (i = select(fd[1]+1, NULL, &writeset, NULL, &tv)) < 0)
			err_sys("select 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -