Module

std::libc::process

LibC Process

Process control, signals, and child process management.

Sub-namespaces

Namespace C Header Description
LibC::Process stdlib.h, unistd.h Process lifecycle, environment, IPC, exec
LibC::Signals signal.h raise, kill
LibC::Wait sys/wait.h wait, waitpid

Constants

Namespace Constant Description
LibC::Process EXIT_SUCCESS Successful exit status
LibC::Process EXIT_FAILURE Failure exit status
LibC::Signals SIGINT Interrupt from keyboard (Ctrl-C)
LibC::Signals SIGKILL Kill signal (cannot be caught)
LibC::Signals SIGSEGV Segmentation fault
LibC::Signals SIGTERM Termination signal

Process Functions

Function Description
fork Duplicate the current process
pipe Create a unidirectional file-descriptor pair
execvp Replace the process image using PATH lookup
setenv Set or replace a process environment variable
unsetenv Remove a process environment variable

Example

import LibC, CType from "std::libc";

function main(): i32 {
  let pid: CType::PidT = LibC::Process::getpid();
  let home: CType::CStr = LibC::Process::getenv("HOME");

  if home == null {
    LibC::Process::exit(LibC::Process::EXIT_FAILURE);
  }

  return 0;
}
namespace __process

Functions

function _exit(status: i32): void

POSIX _exit; terminates without normal C cleanup.

function abort(): void

C abort; terminates abnormally.

function exit(status: i32): void

C exit; terminates the process after normal cleanup.

function getenv(name: *u8): *mut u8

C getenv; returns host-owned environment storage or null.

function setenv(name: *u8, value: *u8, overwrite: i32): i32

POSIX setenv; creates or replaces an environment variable.

function system(command: *u8): i32

C system; runs a shell command and returns host status.

function unsetenv(name: *u8): i32

POSIX unsetenv; removes an environment variable.

Constants

const EXIT_FAILURE: i32
const EXIT_SUCCESS: i32
namespace __signal

Functions

function kill(pid: i32, sig: i32): i32

POSIX kill; sends a signal to a process id.

function raise(sig: i32): i32

C raise; sends a signal to the current process.

Constants

const SIGINT: i32
const SIGKILL: i32
const SIGSEGV: i32
const SIGTERM: i32
namespace __unistd_proc

Functions

function execvp(file: *u8, argv: *mut str): i32

POSIX execvp; replaces the current process image using PATH lookup.

argv must be a null-terminated vector of null-terminated strings. On success this call does not return; on failure it returns -1 and sets errno.

function fork(): i32

POSIX fork; duplicates the current process.

function getgid(): u32

POSIX getgid; returns group id.

function getpid(): i32

POSIX getpid; returns current process id.

function getppid(): i32

POSIX getppid; returns parent process id.

function getuid(): u32

POSIX getuid; returns user id.

function pipe(pipefd: *mut i32): i32

POSIX pipe; creates a pipe fd pair.

function sleep(seconds: u32): u32

POSIX sleep; sleeps for whole seconds.

function usleep(usec: u32): i32

POSIX usleep; sleeps for microseconds.

namespace __wait

Functions

function wait(wstatus: *mut i32): i32

POSIX wait; waits for any child process.

function waitpid(pid: i32, wstatus: *mut i32, options: i32): i32

POSIX waitpid; waits for a selected child process.

namespace Process

Process control (stdlib.h, unistd.h)

namespace Signals

Signals (signal.h) — POSIX only.

namespace Wait

Wait (sys/wait.h) — POSIX only.

Functions

function _exit(status: i32): void

Terminates the process immediately without running atexit handlers.

function abort(): void

Terminates the process abnormally. Does not return.

function execvp(file: *u8, argv: *mut str): i32

Replaces the current process image using PATH lookup.

argv must be null-terminated and conventionally starts with file as argv[0]. Returns only on error, with -1 and errno set by the host.

function exit(status: i32): void

Terminates the process with status. Does not return.

function fork(): i32

Creates a new process by duplicating the calling process.

Returns the child PID to the parent, 0 to the child, or -1 on error.

function getenv(name: *u8): *mut u8

Returns the value of environment variable name, or null if unset.

function getgid(): u32

Returns the real group ID of the calling process.

function getpid(): i32

Returns the process ID of the calling process.

function getppid(): i32

Returns the parent process ID.

function getuid(): u32

Returns the real user ID of the calling process.

function kill(pid: i32, sig: i32): i32

Sends signal sig to process pid.

function pipe(pipefd: *mut i32): i32

Creates a unidirectional pipe. pipefd[0] is the read end, pipefd[1] is the write end.

function raise(sig: i32): i32

Sends signal sig to the calling process.

function setenv(name: *u8, value: *u8, overwrite: i32): i32

Sets or replaces an environment variable in the current process.

function sleep(seconds: u32): u32

Suspends execution for seconds seconds.

Returns 0 on success, or the remaining seconds if interrupted.

function system(command: *u8): i32

Executes command via the system shell. Returns the exit status.

function unsetenv(name: *u8): i32

Removes an environment variable from the current process.

function usleep(usec: u32): i32

Suspends execution for usec microseconds.

function wait(wstatus: *mut i32): i32

Waits for any child process to change state.

Stores the status in wstatus. Returns the child PID.

function waitpid(pid: i32, wstatus: *mut i32, options: i32): i32

Waits for a specific child process pid to change state.

options can be 0 or a combination of WNOHANG/WUNTRACED.

Constants

const EXIT_FAILURE: i32
const EXIT_SUCCESS: i32
const SIGINT: i32
const SIGKILL: i32
const SIGSEGV: i32
const SIGTERM: i32