Expose real operating system process IDs on Windows via os_display_pid()
Some checks failed
Build / build-mac (push) Has been cancelled
Build / build-linux (push) Has been cancelled
Build / build-arm32 (push) Has been cancelled
Build / build-win (push) Has been cancelled
Build / build-freebsd (push) Has been cancelled
Build / build-musl (push) Has been cancelled
CodeQL Advanced / Analyze (c-cpp) (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled

This commit is contained in:
Andrea Mazzoleni 2026-09-05 11:42:01 +02:00
parent be3957f939
commit a0c7d69067
3 changed files with 27 additions and 1 deletions

View file

@ -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;

11
os/os.h
View file

@ -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().

View file

@ -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;