process

// jda::process — Process management

Constants

SYS_READ      =  0
SYS_WRITE     =  1
SYS_OPEN      =  2
SYS_CLOSE     =  3
SYS_STAT      =  4
SYS_MMAP      =  9
SYS_RT_SIGACTION   = 13
SYS_RT_SIGPROCMASK = 14
SYS_RT_SIGRETURN   = 15
SYS_IOCTL     = 16
SYS_PIPE      = 22
SYS_DUP       = 32
SYS_DUP2      = 33
SYS_GETPID    = 39
SYS_CLONE     = 56
SYS_FORK      = 57
SYS_VFORK     = 58
SYS_EXECVE    = 59
SYS_EXIT      = 60
SYS_WAIT4     = 61
SYS_KILL      = 62
SYS_GETPPID   = 110
SYS_GETUID    = 102
SYS_GETGID    = 104
SYS_GETEUID   = 107
SYS_GETEGID   = 108
SYS_SIGALTSTACK= 131
SYS_PRCTL     = 157
SYS_SETPGID   = 109
SYS_GETPGID   = 121
SYS_SETSID    = 112
SYS_ENVIRON   = -1   // accessed via auxv, not a syscall
SIGHUP    =  1    // hangup
SIGINT    =  2    // interrupt (Ctrl-C)
SIGQUIT   =  3    // quit
SIGILL    =  4    // illegal instruction
SIGTRAP   =  5    // trace / breakpoint
SIGABRT   =  6    // abort
SIGBUS    =  7    // bus error
SIGFPE    =  8    // floating-point exception
SIGKILL   =  9    // kill (cannot be caught)
SIGUSR1   = 10    // user-defined 1
SIGSEGV   = 11    // segfault
SIGUSR2   = 12    // user-defined 2
SIGPIPE   = 13    // broken pipe
SIGALRM   = 14    // alarm clock
SIGTERM   = 15    // termination
SIGCHLD   = 17    // child stopped or exited
SIGCONT   = 18    // continue
SIGSTOP   = 19    // stop (cannot be caught)
SIGTSTP   = 20    // terminal stop (Ctrl-Z)
SIGTTIN   = 21    // background read from tty
SIGTTOU   = 22    // background write to tty
SIGURG    = 23    // urgent data on socket
SIGWINCH  = 28    // terminal resize
SIG_DFL   = 0     // default action
SIG_IGN   = 1     // ignore signal
WNOHANG   = 1     // non-blocking waitpid
PR_SET_NAME   = 15
PR_GET_NAME   = 16
PR_SET_DUMPABLE = 4
PR_GET_DUMPABLE = 3
PR_SET_PDEATHSIG = 1   // signal sent to child when parent dies

Structs

SigAction

struct SigAction {
    handler:  i64      // fn pointer or SIG_DFL / SIG_IGN
    flags:    i64      // SA_* flags
    restorer: i64      // signal trampoline (kernel sets this)
    mask:     u64[2]   // signal mask (128 bits)
}

ProcInfo

struct ProcInfo {
    pid:      i32
    ppid:     i32
    uid:      i32
    gid:      i32
    euid:     i32
    egid:     i32
    pgid:     i32
    sid:      i32
}

SpawnOpts

struct SpawnOpts {
    stdin_fd:  i32   // -1 = inherit
    stdout_fd: i32   // -1 = inherit
    stderr_fd: i32   // -1 = inherit
    cwd:       &i8   // null = inherit
    env:       &&i8  // null = inherit current environ
    detach:    i32   // 1 = new session (setsid)
}

ChildProc

struct ChildProc {
    pid:    i32
    stdin:  i32   // write end of stdin pipe  (-1 if not piped)
    stdout: i32   // read  end of stdout pipe (-1 if not piped)
    stderr: i32   // read  end of stderr pipe (-1 if not piped)
}

WaitResult

struct WaitResult {
    pid:    i32
    status: i32
    exited: i32
    code:   i32     // exit code if exited
    signal: i32     // signal if killed by signal
}

Pipe

struct Pipe {
    read_fd:  i32
    write_fd: i32
}

Functions

FunctionDescription
wifexited
wexitstatus
wifsignaled
wtermsig
wifstopped
wstopsig
getpid
getppid
getuid
getgid
exit
abort
fork
execve
exec_argv
waitpid
wait_any
run
pipe2
dup2
close_fd
spawn
spawn_output
kill
killpg
raise_sig
signal
signal_ignore
signal_default
signal_block
signal_unblock
environ
process_init
getenv
setenv
unsetenv
proc_info
pipe_open
pipe_write
pipe_read
pipe_close_write
pipe_close_read
daemonize
set_process_name
get_process_name
set_pdeathsig
disable_coredump

Details

wifexited

fn wifexited(status: i32) -> i32  

wexitstatus

fn wexitstatus(status: i32) -> i32

wifsignaled

fn wifsignaled(status: i32) -> i32

wtermsig

fn wtermsig(status: i32) -> i32   

wifstopped

fn wifstopped(status: i32) -> i32 

wstopsig

fn wstopsig(status: i32) -> i32   

getpid

fn getpid() -> i32

getppid

fn getppid() -> i32

getuid

fn getuid() -> i32

getgid

fn getgid() -> i32

exit

fn exit(code: i32)

abort

fn abort()

fork

fn fork() -> i32

execve

fn execve(path: &i8, argv: &&i8, envp: &&i8) -> i32

exec_argv

fn exec_argv(path: &i8, argv: &&i8) -> i32

waitpid

fn waitpid(pid: i32, status: &i32, options: i32) -> i32

wait_any

fn wait_any(opts: i32) -> WaitResult

run

fn run(path: &i8, argv: &&i8) -> i32

pipe2

fn pipe2(fds: &i32) -> i32

dup2

fn dup2(old_fd: i32, new_fd: i32) -> i32

close_fd

fn close_fd(fd: i32)

spawn

fn spawn(path: &i8, argv: &&i8, opts: &SpawnOpts) -> ChildProc

spawn_output

fn spawn_output(path: &i8, argv: &&i8, out: &i8, cap: i64) -> i64

kill

fn kill(pid: i32, sig: i32) -> i32

killpg

fn killpg(pgid: i32, sig: i32) -> i32

raise_sig

fn raise_sig(sig: i32)

signal

fn signal(sig: i32, handler: i64) -> i32

signal_ignore

fn signal_ignore(sig: i32)

signal_default

fn signal_default(sig: i32)

signal_block

fn signal_block(sig: i32)

signal_unblock

fn signal_unblock(sig: i32)

environ

fn environ() -> &&i8

process_init

fn process_init(argc: i64, argv: &&i8)

getenv

fn getenv(name: &i8) -> &i8

setenv

fn setenv(name: &i8, value: &i8, overwrite: i32) -> i32

unsetenv

fn unsetenv(name: &i8) -> i32

proc_info

fn proc_info() -> ProcInfo

pipe_open

fn pipe_open() -> Pipe

pipe_write

fn pipe_write(p: &Pipe, data: &i8, len: i64) -> i64

pipe_read

fn pipe_read(p: &Pipe, buf: &i8, cap: i64) -> i64

pipe_close_write

fn pipe_close_write(p: &Pipe)

pipe_close_read

fn pipe_close_read(p: &Pipe) 

daemonize

fn daemonize() -> i32

set_process_name

fn set_process_name(name: &i8)

get_process_name

fn get_process_name(out: &i8)

set_pdeathsig

fn set_pdeathsig(sig: i32)

disable_coredump

fn disable_coredump()