Skip to content
CryoCryo home
Stdlibprocess

signal

import std::process::signal; · source

Signal

type struct Signal {
    value: SigNo;

    static new(value: SigNo) -> Signal;
    static from_i32(value: i32) -> Signal;
    as_i32(&this) -> i32;
    static hangup() -> Signal;
    static interrupt() -> Signal;
    static quit() -> Signal;
    static illegal() -> Signal;
    static trap() -> Signal;
    static abort() -> Signal;
    static bus() -> Signal;
    static floating_point() -> Signal;
    static kill() -> Signal;
    static user1() -> Signal;
    static segfault() -> Signal;
    static user2() -> Signal;
    static pipe() -> Signal;
    static alarm() -> Signal;
    static terminate() -> Signal;
    static child() -> Signal;
    static cont() -> Signal;
    static stop() -> Signal;
    static tty_stop() -> Signal;
}

Signal wraps a SigNo so the compiler catches passing a pid where a signal was expected. The common ones have named constructors, and arbitrary numbers go through from_i32.

SigNo

type enum SigNo : i32 {
    SIGHUP = 1;
    SIGINT = 2;
    SIGQUIT = 3;
    SIGILL = 4;
    SIGTRAP = 5;
    SIGABRT = 6;
    SIGBUS = 7;
    SIGFPE = 8;
    SIGKILL = 9;
    SIGUSR1 = 10;
    SIGSEGV = 11;
    SIGUSR2 = 12;
    SIGPIPE = 13;
    SIGALRM = 14;
    SIGTERM = 15;
    SIGCHLD = 17;
    SIGCONT = 18;
    SIGSTOP = 19;
    SIGTSTP = 20;
}

implement enum SigNo {
    static from_i32(value: i32) -> SigNo;
}

The signal numbers, matching Linux x86-64. from_i32 maps a raw number back onto the enum.

Signal handling — installing a handler with sigaction — is not modelled here. The moment a program installs handlers it crosses into async-signal safety, reentrant allocation, and interaction with every other stdlib primitive; that is a separate design problem.