⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

sys_wait

Function sys_wait 

Source
pub fn sys_wait(_pid: u64) -> SyscallResult<i32>
Expand description

Wait for a child process to exit and collect its exit status.

Blocks the calling process until the specified child process has terminated. Once the child exits, its exit code is returned and the child’s zombie entry is removed from the process table (reaped).

If the child has already exited before this call, the exit code is returned immediately without blocking (zombie reaping). If the specified PID does not correspond to a child of the calling process, an error is returned.

Future implementations may support WNOHANG-style behavior by passing special PID values:

  • pid > 0: Wait for the specific child with that PID.
  • pid == 0: Wait for any child in the same process group (future).
  • pid == u64::MAX: Wait for any child process (future).

§Arguments

  • pid - Process ID of the child to wait for. Must be a direct child of the calling process.

§Returns

  • Ok(exit_code) - The exit status code of the terminated child process. By convention, 0 indicates success and non-zero values indicate an error or signal termination.

§Errors

§Examples

use veridian_kernel::pkg::sdk::syscall_api::{sys_exit, sys_fork, sys_wait};

let child_pid = sys_fork().expect("fork failed");
if child_pid == 0 {
    // Child process work
    sys_exit(42);
} else {
    // Parent waits for child and retrieves exit code
    let exit_code = sys_wait(child_pid).expect("wait failed");
    // exit_code == 42
}