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 __processFunctions
function _exit(status: i32): voidPOSIX _exit; terminates without normal C cleanup.
function abort(): voidC abort; terminates abnormally.
function exit(status: i32): voidC exit; terminates the process after normal cleanup.
function getenv(name: *u8): *mut u8C getenv; returns host-owned environment storage or null.
function setenv(name: *u8, value: *u8, overwrite: i32): i32POSIX setenv; creates or replaces an environment variable.
function system(command: *u8): i32C system; runs a shell command and returns host status.
function unsetenv(name: *u8): i32POSIX unsetenv; removes an environment variable.
Constants
const EXIT_FAILURE: i32const EXIT_SUCCESS: i32namespace __signalFunctions
function kill(pid: i32, sig: i32): i32POSIX kill; sends a signal to a process id.
function raise(sig: i32): i32C raise; sends a signal to the current process.
Constants
const SIGINT: i32const SIGKILL: i32const SIGSEGV: i32const SIGTERM: i32namespace __unistd_procFunctions
function execvp(file: *u8, argv: *mut str): i32POSIX 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(): i32POSIX fork; duplicates the current process.
function getgid(): u32POSIX getgid; returns group id.
function getpid(): i32POSIX getpid; returns current process id.
function getppid(): i32POSIX getppid; returns parent process id.
function getuid(): u32POSIX getuid; returns user id.
function pipe(pipefd: *mut i32): i32POSIX pipe; creates a pipe fd pair.
function sleep(seconds: u32): u32POSIX sleep; sleeps for whole seconds.
function usleep(usec: u32): i32POSIX usleep; sleeps for microseconds.
namespace __waitFunctions
function wait(wstatus: *mut i32): i32POSIX wait; waits for any child process.
function waitpid(pid: i32, wstatus: *mut i32, options: i32): i32POSIX waitpid; waits for a selected child process.
namespace ProcessProcess control (stdlib.h, unistd.h)
namespace SignalsSignals (signal.h) — POSIX only.
namespace WaitWait (sys/wait.h) — POSIX only.
Functions
function _exit(status: i32): voidTerminates the process immediately without running atexit handlers.
function abort(): voidTerminates the process abnormally. Does not return.
function execvp(file: *u8, argv: *mut str): i32Replaces 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): voidTerminates the process with status. Does not return.
function fork(): i32Creates 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 u8Returns the value of environment variable name, or null if unset.
function getgid(): u32Returns the real group ID of the calling process.
function getpid(): i32Returns the process ID of the calling process.
function getppid(): i32Returns the parent process ID.
function getuid(): u32Returns the real user ID of the calling process.
function kill(pid: i32, sig: i32): i32Sends signal sig to process pid.
function pipe(pipefd: *mut i32): i32Creates a unidirectional pipe. pipefd[0] is the read end,
pipefd[1] is the write end.
function raise(sig: i32): i32Sends signal sig to the calling process.
function setenv(name: *u8, value: *u8, overwrite: i32): i32Sets or replaces an environment variable in the current process.
function sleep(seconds: u32): u32Suspends execution for seconds seconds.
Returns 0 on success, or the remaining seconds if interrupted.
function system(command: *u8): i32Executes command via the system shell. Returns the exit status.
function unsetenv(name: *u8): i32Removes an environment variable from the current process.
function usleep(usec: u32): i32Suspends execution for usec microseconds.
function wait(wstatus: *mut i32): i32Waits 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): i32Waits for a specific child process pid to change state.
options can be 0 or a combination of WNOHANG/WUNTRACED.
Constants
const EXIT_FAILURE: i32const EXIT_SUCCESS: i32const SIGINT: i32const SIGKILL: i32const SIGSEGV: i32const SIGTERM: i32