mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-23 18:19:39 +00:00
test: pipes -- Add a second pipe
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
46083e9e00
commit
8ea8d4eee5
1 changed files with 31 additions and 8 deletions
|
|
@ -16,13 +16,14 @@ static void *map;
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int pipefd[2];
|
||||
int pipefd1[2];
|
||||
int pipefd2[2];
|
||||
pid_t pid;
|
||||
|
||||
printf("%s pid %d\n", argv[0], getpid());
|
||||
|
||||
if (pipe(pipefd)) {
|
||||
perror("Can't create pipe");
|
||||
if (pipe(pipefd1)) {
|
||||
perror("Can't create pipe1");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -32,15 +33,37 @@ int main(int argc, char *argv[])
|
|||
return 1;
|
||||
} else if (pid == 0) {
|
||||
long buf;
|
||||
while (read(pipefd[0], &buf, sizeof(buf)) > 0) {
|
||||
printf("pipe-r: %08lx\n", buf);
|
||||
sleep(2);
|
||||
|
||||
if (pipe(pipefd2)) {
|
||||
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 {
|
||||
long buf = 0;
|
||||
while (1) {
|
||||
printf("pipe-w: %08lx\n", buf);
|
||||
write(pipefd[1], &buf, sizeof(buf));
|
||||
printf("pipe1-w: %08lx\n", buf);
|
||||
write(pipefd1[1], &buf, sizeof(buf));
|
||||
sleep(1);
|
||||
buf++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue