]> git.kaiwu.me - quickjs.git/commitdiff
added os.getpid()
authorFabrice Bellard <fabrice@bellard.org>
Thu, 11 Jan 2024 14:25:28 +0000 (15:25 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Thu, 11 Jan 2024 14:25:28 +0000 (15:25 +0100)
doc/quickjs.texi
quickjs-libc.c

index 055825acdce22caa588b48398c0ac270f263a7b0..b064e7da5e13e38f06d585c90430031c5e07b52a 100644 (file)
@@ -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.
index ea73ee8e7f5d2adaf510088b8872bd3960c1cce3..d4f4d671165e400b4b7216fc97f5c76fb41d1695 100644 (file)
@@ -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 ),