diff --git a/os/mingw.c b/os/mingw.c index 4dcfeef9..30ad2f34 100644 --- a/os/mingw.c +++ b/os/mingw.c @@ -3157,6 +3157,15 @@ pid_t os_spawn(char** argv, int* stdout_read_int, int* stderr_read_int, const ch return (intptr_t)pi.hProcess; } +uint64_t os_display_pid(pid_t pid) +{ + if (pid <= 0) + return 0; + + HANDLE h = (void*)pid; + return (uint64_t)GetProcessId(h); +} + pid_t os_wait(pid_t pid, int* status) { HANDLE h = (void*)pid; diff --git a/os/os.h b/os/os.h index 3bd6d211..08ecf290 100644 --- a/os/os.h +++ b/os/os.h @@ -121,10 +121,19 @@ int os_pclose(OS_FILE* stream); * \param stdout_read_fd Pointer to store file descriptor for stdout, or NULL to redirect to /dev/null. * \param stderr_read_fd Pointer to store file descriptor for stderr, or NULL to redirect to /dev/null. * \param run_as_user User to run script as (NULL for current user). - * \return Process ID of spawned process, or -1 on failure. + * \return Process reference of spawned process, or -1 on failure. */ pid_t os_spawn(char** argv, int* stdout_read_fd, int* stderr_read_fd, const char* run_as_user); +/** + * Get the operating system process ID suitable for display. + * On Unix the process reference is already the PID. + * On Windows the process reference is a HANDLE and the actual PID is obtained with GetProcessId(). + * \param pid Process reference returned by os_spawn(). + * \return Operating system process ID, or 0 if unavailable. + */ +uint64_t os_display_pid(pid_t pid); + /** * Wait for the child process to terminate. * This function does not release the process reference returned by os_spawn(). diff --git a/os/unix.c b/os/unix.c index 360cec2d..734a6aef 100644 --- a/os/unix.c +++ b/os/unix.c @@ -1507,6 +1507,14 @@ pid_t os_spawn(char** argv, int* stdout_read_fd, int* stderr_read_fd, const char return pid; } +uint64_t os_display_pid(pid_t pid) +{ + if (pid <= 0) + return 0; + + return (uint64_t)pid; +} + pid_t os_wait(pid_t pid, int* status) { pid_t ret;