1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-19 01:37:40 +00:00

Add os/getpid

This commit is contained in:
Calvin Rose
2025-04-05 16:20:17 -05:00
parent b12dfd784e
commit a9ff8b388f
2 changed files with 14 additions and 1 deletions

View File

@@ -813,6 +813,18 @@ JANET_CORE_FN(os_proc_close,
#endif
}
JANET_CORE_FN(os_proc_getpid,
"(os/getpid)",
"Get the process ID of the current process.") {
janet_fixarity(argc, 0);
(void) argv;
#ifdef JANET_WINDOWS
return janet_wrap_number((double) _getpid());
#else
return janet_wrap_number((double) getpid());
#endif
}
static void swap_handles(JanetHandle *handles) {
JanetHandle temp = handles[0];
handles[0] = handles[1];
@@ -2797,6 +2809,7 @@ void janet_lib_os(JanetTable *env) {
JANET_CORE_REG("os/proc-wait", os_proc_wait),
JANET_CORE_REG("os/proc-kill", os_proc_kill),
JANET_CORE_REG("os/proc-close", os_proc_close),
JANET_CORE_REG("os/getpid", os_proc_getpid),
#endif
/* high resolution timers */