From 436d7592c731517cdae757c670450a006fbfb36d Mon Sep 17 00:00:00 2001 From: Justice Suh Date: Sat, 13 Jul 2019 22:18:54 -0400 Subject: [PATCH] os: fork() and wait() --- vlib/os/os.v | 10 ++++++++++ vlib/os/os_test.v | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/vlib/os/os.v b/vlib/os/os.v index 7dc3b96b9e..ef0f8007e6 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -652,6 +652,16 @@ pub fn signal(signum int, handler voidptr) { C.signal(signum, handler) } +pub fn fork() int { + pid := C.fork() + return pid +} + +pub fn wait() int { + pid := C.wait(0) + return pid +} + pub fn file_last_mod_unix(path string) int { attr := C.stat{} //# struct stat attr; diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index c1b3b69956..a50f48649e 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -33,3 +33,26 @@ fn test_write_and_read_string_to_file() { os.rm(filename) } + +//fn test_fork() { +// pid := os.fork() +// if pid == 0 { +// println('Child') +// } +// else { +// println('Parent') +// } +//} + +//fn test_wait() { +// pid := os.fork() +// if pid == 0 { +// println('Child') +// exit(0) +// } +// else { +// cpid := os.wait() +// println('Parent') +// println(cpid) +// } +//}