From 88243e9deca2dffeb3a2c1f6cabc71bcc6de86b5 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 14 Oct 2024 23:09:54 +0200 Subject: [PATCH] Mon 14 Oct 23:09:15 CEST 2024 --- user/test/pipetest.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 user/test/pipetest.c diff --git a/user/test/pipetest.c b/user/test/pipetest.c new file mode 100644 index 0000000..bb2d926 --- /dev/null +++ b/user/test/pipetest.c @@ -0,0 +1,27 @@ +#include "library/syscalls.h" +#include "library/user-io.h" +#include "library/string.h" + +int main(int argc, char *argv[]) +{ + printf("%d: Running pipe test!\n", syscall_process_self()); + int w = syscall_open_pipe(); + syscall_object_set_blocking(w, 0); + int x = syscall_process_fork(); + if(x) { + printf("%d: Writing...\n", syscall_process_self()); + syscall_object_dup(w, KNO_STDOUT); + printf("Testing!\n"); + syscall_process_sleep(1000); + } else { + printf("%d: Reading...\n", syscall_process_self()); + int r; + char buf[10]; + while(!(r = syscall_object_read(w, buf, 10))) { + syscall_process_yield(); + } + printf("%d: I read %d chars from my brother\n", syscall_process_self(), r); + printf("%d: They are (%s)\n", syscall_process_self(), buf); + } + return 0; +}