Commit 5e5cb3b3 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

test: Add test-pipe-async test

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 22f89869
......@@ -2,6 +2,7 @@ SRCS += test-counter.c
SRCS += test-rnd-from-file.c
SRCS += test-shmem-async.c
SRCS += test-shmem-three-async.c
SRCS += test-pipe-async.c
OBJS := $(patsubst %.c,%.o,$(SRCS))
PROGS := $(patsubst %.c,%,$(SRCS))
......
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sched.h>
static void *map;
int main(int argc, char *argv[])
{
int pipefd[2];
pid_t pid;
printf("%s pid %d\n", argv[0], getpid());
if (pipe(pipefd)) {
perror("Can't create pipe");
return -1;
}
pid = fork();
if (pid == -1) {
printf("fork failed\n");
return 1;
} else if (pid == 0) {
long buf;
while (read(pipefd[0], &buf, sizeof(buf)) > 0) {
printf("pipe-r: %08lx\n", buf);
sleep(2);
}
} else {
long buf = 0;
while (1) {
printf("pipe-w: %08lx\n", buf);
write(pipefd[1], &buf, sizeof(buf));
sleep(1);
buf++;
}
}
return 0;
}
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