|
|
1.1 root 1: /*
2: * IPC benchmark,
3: * read and reply using pipes.
4: *
5: * Process forks and exchanges messages
6: * over a pipe in a request-response fashion.
7: */
8:
9: main(argc, argv)
10: char *argv[];
11: {
12: char buf[512];
13: int fd[2], fd2[2], msgsize;
14: register int i, iter;
15:
16: if (argc < 3) {
17: printf("usage: %s iterations message-size\n", argv[0]);
18: exit(1);
19: }
20: argc--, argv++;
21: iter = atoi(*argv);
22: argc--, argv++;
23: msgsize = atoi(*argv);
24: if (msgsize > sizeof (buf) || msgsize <= 0) {
25: printf("%s: Bad message size.\n", *argv);
26: exit(2);
27: }
28: if (pipe(fd) < 0) {
29: perror("pipe");
30: exit(3);
31: }
32: if (pipe(fd2) < 0) {
33: perror("pipe");
34: exit(3);
35: }
36: if (fork() == 0)
37: for (i = 0; i < iter; i++) {
38: read(fd[0], buf, msgsize);
39: write(fd2[1], buf, msgsize);
40: }
41: else
42: for (i = 0; i < iter; i++) {
43: write(fd[1], buf, msgsize);
44: read(fd2[0], buf, msgsize);
45: }
46: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.