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

📄 pipeback.c

📁 早期freebsd实现
💻 C
字号:
/* * IPC benchmark, * read and reply using pipes. * * Process forks and exchanges messages * over a pipe in a request-response fashion. */main(argc, argv)	char *argv[];{	char buf[512];	int fd[2], fd2[2], msgsize;	register int i, iter;	if (argc < 3) {		printf("usage: %s iterations message-size\n", argv[0]);		exit(1);	}	argc--, argv++;	iter = atoi(*argv);	argc--, argv++;	msgsize = atoi(*argv);	if (msgsize > sizeof (buf) || msgsize <= 0) {		printf("%s: Bad message size.\n", *argv);		exit(2);	}	if (pipe(fd) < 0) {		perror("pipe");		exit(3);	}	if (pipe(fd2) < 0) {		perror("pipe");		exit(3);	}	if (fork() == 0)		for (i = 0; i < iter; i++) {			read(fd[0], buf, msgsize);			write(fd2[1], buf, msgsize);		}	else		for (i = 0; i < iter; i++) {			write(fd[1], buf, msgsize);			read(fd2[0], buf, msgsize);		}}

⌨️ 快捷键说明

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