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

📄 test2.c

📁 这是unix网络编程一书的源代码希望能对大家的学习提供一种便利
💻 C
字号:
#include	"unpipc.h"

int
main(int argc, char **argv)
{
	int		fd[2], n;
	pid_t	childpid;
	fd_set	wset;

	Pipe(fd);
	if ( (childpid = Fork()) == 0) {		/* child */
		printf("child closing pipe read descriptor\n");
		Close(fd[0]);
		sleep(6);
		exit(0);
	}
		/* 4parent */
	Close(fd[0]);	/* in case of a full-duplex pipe */
	sleep(3);
	FD_ZERO(&wset);
	FD_SET(fd[1], &wset);
	n = select(fd[1] + 1, NULL, &wset, NULL, NULL);
	printf("select returned %d\n", n);

	if (FD_ISSET(fd[1], &wset)) {
		printf("fd[1] writable\n");
		Write(fd[1], "hello", 5);
	}

	exit(0);
}

⌨️ 快捷键说明

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