From 195c42b9fb825d2ed82b9a0d85d79142fcc240dc Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Thu, 11 Jan 2024 15:25:28 +0100 Subject: [PATCH] added os.getpid() --- doc/quickjs.texi | 3 +++ quickjs-libc.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/doc/quickjs.texi b/doc/quickjs.texi index 055825a..b064e7d 100644 --- a/doc/quickjs.texi +++ b/doc/quickjs.texi @@ -757,6 +757,9 @@ object containing optional parameters: @end table +@item getpid() +Return the current process ID. + @item waitpid(pid, options) @code{waitpid} Unix system call. Return the array @code{[ret, status]}. @code{ret} contains @code{-errno} in case of error. diff --git a/quickjs-libc.c b/quickjs-libc.c index ea73ee8..d4f4d67 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -3088,6 +3088,13 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, goto done; } +/* getpid() -> pid */ +static JSValue js_os_getpid(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) +{ + return JS_NewInt32(ctx, getpid()); +} + /* waitpid(pid, block) -> [pid, status] */ static JSValue js_os_waitpid(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -3714,6 +3721,7 @@ static const JSCFunctionListEntry js_os_funcs[] = { JS_CFUNC_DEF("symlink", 2, js_os_symlink ), JS_CFUNC_DEF("readlink", 1, js_os_readlink ), JS_CFUNC_DEF("exec", 1, js_os_exec ), + JS_CFUNC_DEF("getpid", 0, js_os_getpid ), JS_CFUNC_DEF("waitpid", 2, js_os_waitpid ), OS_FLAG(WNOHANG), JS_CFUNC_DEF("pipe", 0, js_os_pipe ),