toaruos/userspace/pipe_test.c
Kevin Lange 6c042aba53 Pipes
2012-01-24 18:40:25 -06:00

33 lines
602 B
C

/* vim: tabstop=4 shiftwidth=4 noexpandtab
* pipe test
*/
#include <stdio.h>
#include <stdint.h>
#include <syscall.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
DEFN_SYSCALL1(wait, 17, unsigned int);
DEFN_SYSCALL0(mkpipe, 21);
int main(int argc, char ** argv) {
int fd = syscall_mkpipe();
printf("%d <- pipe\n", fd);
int pid = getpid();
uint32_t f = fork();
if (getpid() != pid) {
char buf[512];
int r = read(fd, buf, 13);
printf("[%d] %s\n", r, buf);
return 0;
} else {
char * buf = "Hello world!";
write(fd, buf, strlen(buf) + 1);
return 0;
}
return 0;
}