Commit 8ea8d4ee authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

test: pipes -- Add a second pipe

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 46083e9e
...@@ -16,13 +16,14 @@ static void *map; ...@@ -16,13 +16,14 @@ static void *map;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int pipefd[2]; int pipefd1[2];
int pipefd2[2];
pid_t pid; pid_t pid;
printf("%s pid %d\n", argv[0], getpid()); printf("%s pid %d\n", argv[0], getpid());
if (pipe(pipefd)) { if (pipe(pipefd1)) {
perror("Can't create pipe"); perror("Can't create pipe1");
return -1; return -1;
} }
...@@ -32,15 +33,37 @@ int main(int argc, char *argv[]) ...@@ -32,15 +33,37 @@ int main(int argc, char *argv[])
return 1; return 1;
} else if (pid == 0) { } else if (pid == 0) {
long buf; long buf;
while (read(pipefd[0], &buf, sizeof(buf)) > 0) {
printf("pipe-r: %08lx\n", buf); if (pipe(pipefd2)) {
sleep(2); perror("Can't create pipe2");
return -1;
}
pid = fork();
if (pid == -1) {
printf("fork failed\n");
return 1;
} else if (pid == 0) {
while (1) {
long buf;
read(pipefd1[0], &buf, sizeof(buf));
printf("pipe2-r: %08lx\n", buf);
sleep(1);
}
}
while (1) {
read(pipefd1[0], &buf, sizeof(buf));
printf("pipe1-r: %08lx\n", buf);
printf("pipe2-w: %08lx\n", buf);
write(pipefd2[1], &buf, sizeof(buf));
sleep(1);
} }
} else { } else {
long buf = 0; long buf = 0;
while (1) { while (1) {
printf("pipe-w: %08lx\n", buf); printf("pipe1-w: %08lx\n", buf);
write(pipefd[1], &buf, sizeof(buf)); write(pipefd1[1], &buf, sizeof(buf));
sleep(1); sleep(1);
buf++; buf++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment