Skip to content

std (posix): lower getpid and getppid into std.posix #24027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

QSmally
Copy link

@QSmally QSmally commented May 29, 2025

Simply puts getpid() and getppid() into std.posix by making use of posix.system if available. Removes a tiny bit of boilerplate when making cross-Darwin-Linux platform stuff by not referencing std.c or std.os.linux directly.

Also adds a proper test for getppid(). Kind of depends on fork() and waitpid() but I'm not sure what the policy of inter-dependent tests are.

if (native_os == .wasi) return error.SkipZigTest;
if (native_os == .windows) return error.SkipZigTest;
if (native_os == .plan9 and !builtin.link_libc) return error.SkipZigTest; // No `getppid()`.
if ((builtin.cpu.arch == .riscv32 or builtin.cpu.arch.isLoongArch()) and builtin.os.tag == .linux and !builtin.link_libc) return error.SkipZigTest; // No `getppid()`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No getppid? That seems unlikely?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riscv does return an error mentioning the missing syscall without linking libc (or at least a mapping to it). I'm not all too familiar with riscv or the syscall interfaces in Zig yet, though

Copy link
Member

@alexrp alexrp May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at lib/std/os/linux/syscalls.zig, RISC-V definitely has the syscall number. (And this file is generated from kernel sources.)

@alexrp alexrp self-assigned this Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants