summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2024-01-11 15:25:28 +0100
committerFabrice Bellard <fabrice@bellard.org>2024-01-11 15:25:28 +0100
commit195c42b9fb825d2ed82b9a0d85d79142fcc240dc (patch)
treec77bef281b82737e52970005c46d5842e462c8eb
parent10fc744ae4dfe59b685f5643b71530891cf0be3b (diff)
downloadquickjs-195c42b9fb825d2ed82b9a0d85d79142fcc240dc.tar.gz
quickjs-195c42b9fb825d2ed82b9a0d85d79142fcc240dc.zip
added os.getpid()
-rw-r--r--doc/quickjs.texi3
-rw-r--r--quickjs-libc.c8
2 files changed, 11 insertions, 0 deletions
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 ),