authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-11-07 23:17:55+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-11-07 23:17:55+01:00
logbf15c791faa7bf5a029ec58432b3e8e16c691dff
treeb9e60b460f80a9223dc43fe72d622b4d7c6f79d4
parent852a1f718a306aa0a540c527a0c23d50b9f0db08
parentf4159eff9253bb701bacfa14e37bdb80e8dff7da
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #25820 from GiuseppeCesarano/process

Child.start_suspended ported to posix

3 files changed, 29 insertions(+), 2 deletions(-)

lib/std/posix.zig+8
......@@ -1699,6 +1699,14 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
16991699 }
17001700}
17011701
1702pub fn getpid() pid_t {
1703 return system.getpid();
1704}
1705
1706pub fn getppid() pid_t {
1707 return system.getppid();
1708}
1709
17021710pub const ExecveError = error{
17031711 SystemResources,
17041712 AccessDenied,
lib/std/posix/test.zig+15
......@@ -621,6 +621,21 @@ test "dup & dup2" {
621621 try testing.expectEqualStrings("dupdup2", try tmp.dir.readFile("os_dup_test", &buffer));
622622}
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
624639test "writev longer than IOV_MAX" {
625640 if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
626641
lib/std/process/Child.zig+6-2
......@@ -85,8 +85,8 @@ expand_arg0: Arg0Expand,
8585/// Darwin-only. Disable ASLR for the child process.
8686disable_aslr: bool = false,
8787
88/// Darwin and Windows only. Start child process in suspended state. For Darwin it's started
89/// as if SIGSTOP was sent.
88/// Start child process in suspended state.
89/// For Posix systems it's started as if SIGSTOP was sent.
9090start_suspended: bool = false,
9191
9292/// Windows-only. Sets the CREATE_NO_WINDOW flag in CreateProcess.
......@@ -669,6 +669,10 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
669669 posix.setpgid(0, pid) catch |err| forkChildErrReport(err_pipe[1], err);
670670 }
671671
672 if (self.start_suspended) {
673 posix.kill(posix.getpid(), .STOP) catch |err| forkChildErrReport(err_pipe[1], err);
674 }
675
672676 const err = switch (self.expand_arg0) {
673677 .expand => posix.execvpeZ_expandArg0(.expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),
674678 .no_expand => posix.execvpeZ_expandArg0(.no_expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),