authorgravatar for PecoraInPannaCotta@gmail.comGiuseppe Cesarano <PecoraInPannaCotta@gmail.com> 2025-11-07 08:52:35+01:00
committergravatar for PecoraInPannaCotta@gmail.comGiuseppe Cesarano <PecoraInPannaCotta@gmail.com> 2025-11-07 08:52:35+01:00
log5c0309a9e59413048c97c2fbc7cde5676069c29f
tree3999fafd1e520f0f04709ee641c515f466eed185
parenta6d444c2714f24b7232895cf15282e2287fe445e
signaturelock-open Commit is signed but in an unrecognized format.

std.posix: implemented getpid and getppid


2 files changed, 23 insertions(+), 0 deletions(-)

lib/std/posix.zig+8
...@@ -1699,6 +1699,14 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {...@@ -1699,6 +1699,14 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
1699 }1699 }
1700}1700}
17011701
1702pub fn getpid() pid_t {
1703 return system.getpid();
1704}
1705
1706pub fn getppid() pid_t {
1707 return system.getppid();
1708}
1709
1702pub const ExecveError = error{1710pub const ExecveError = error{
1703 SystemResources,1711 SystemResources,
1704 AccessDenied,1712 AccessDenied,
lib/std/posix/test.zig+15
...@@ -621,6 +621,21 @@ test "dup & dup2" {...@@ -621,6 +621,21 @@ test "dup & dup2" {
621 try testing.expectEqualStrings("dupdup2", try tmp.dir.readFile("os_dup_test", &buffer));621 try testing.expectEqualStrings("dupdup2", try tmp.dir.readFile("os_dup_test", &buffer));
622}622}
623623
624test "getpid" {
625 if (native_os == .wasi) return error.SkipZigTest;
626 if (native_os == .windows) return error.SkipZigTest;
627
628 try expect(posix.getpid() != 0);
629}
630
631test "getppid" {
632 if (native_os == .wasi) return error.SkipZigTest;
633 if (native_os == .windows) return error.SkipZigTest;
634 if (native_os == .plan9 and !builtin.link_libc) return error.SkipZigTest;
635
636 try expect(posix.getppid() >= 0);
637}
638
624test "writev longer than IOV_MAX" {639test "writev longer than IOV_MAX" {
625 if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;640 if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
626641