From 209060885addd5d1e09b05a8936273854eccba4f Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Mon, 29 Jul 2024 13:07:19 -0500 Subject: [PATCH] Add getppid to std.c and std.os.linux. The std lib is missing getppid, this patch adds it. --- lib/std/c.zig | 1 + lib/std/os/linux.zig | 4 ++++ lib/std/os/linux/test.zig | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/lib/std/c.zig b/lib/std/c.zig index ff2c7dbd85bc..af2883a7901a 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -9351,6 +9351,7 @@ pub extern "c" fn setlogmask(maskpri: c_int) c_int; pub extern "c" fn if_nametoindex([*:0]const u8) c_int; pub extern "c" fn getpid() pid_t; +pub extern "c" fn getppid() pid_t; /// These are implementation defined but share identical values in at least musl and glibc: /// - https://git.musl-libc.org/cgit/musl/tree/include/locale.h?id=ab31e9d6a0fa7c5c408856c89df2dfb12c344039#n18 diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 12083bd5da4a..24d41e33e710 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1579,6 +1579,10 @@ pub fn getpid() pid_t { return @bitCast(@as(u32, @truncate(syscall0(.getpid)))); } +pub fn getppid() pid_t { + return @bitCast(@as(u32, @truncate(syscall0(.getppid)))); +} + pub fn gettid() pid_t { return @bitCast(@as(u32, @truncate(syscall0(.gettid)))); } diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig index 0f1349af2028..9be351368b4f 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -32,6 +32,10 @@ test "getpid" { try expect(linux.getpid() != 0); } +test "getppid" { + try expect(linux.getppid() != 0); +} + test "timer" { const epoll_fd = linux.epoll_create(); var err: linux.E = linux.E.init(epoll_fd);