Uni/Signal#

Interface for Unix signal handling.

Info

To use declarations from this page, include the <essence/uni/signal.hpp> header.

enum class signals : i32#
enumerator hangup = SIGHUP#

Hangup.

enumerator interrupt = SIGINT#

Terminal interrupt signal.

enumerator quit = SIGQUIT#

Terminal quit signal.

enumerator illegal = SIGILL#

Illegal instruction encountered.

enumerator trap = SIGTRAP#

Trace/breakpoint trap.

enumerator abrt = SIGABRT#

Abort the process.

enumerator bus = SIGBUS#

Access to an undefined portion of a memory object.

enumerator fpe = SIGFPE#

Erroneous arithmetic operation.

enumerator kill = SIGKILL#

Kill, cannot be caught or ignored.

enumerator usr_one = SIGUSR1#

User-defined signal 1.

enumerator segv = SIGSEGV#

Invalid memory reference.

enumerator usr_two = SIGUSR2#

User-defined signal 2.

enumerator pipe = SIGPIPE#

Write on a pipe with no one to read it.

enumerator alrm = SIGALRM#

Alarm clock.

enumerator term = SIGTERM#

Termination signal.

enumerator chld = SIGCHLD#

Child process terminated.

enumerator cont = SIGCONT#

Continue executing if stopped.

enumerator stop = SIGSTOP#

Stop executing, cannot be caught or ignored.

enumerator tstp = SIGTSTP#

Terminal stop signal.

enumerator ttin = SIGTTIN#

Background process attempting read.

enumerator ttou = SIGTTOU#

Background process attempting write.

enumerator urg = SIGURG#

High bandwidth data is available at a socket.

enumerator xcpu = SIGXCPU#

CPU time limit exceeded.

enumerator xfsz = SIGXFSZ#

File size limit exceeded.

enumerator vtalrm = SIGVTALRM#

Virtual timer expired.

enumerator winch = SIGWINCH#

Terminal window size changed.

enumerator sys = SIGSYS#

Bad system call.

enumerator unknown = 65535#

Invalid/unknown signal.

std::string_view uni::signal_str(enum uni::signals s)#

Get a string representation of signal s.

Parameter s may also be an i32.

class signal#

A wrapper for a signal handler.

using handler = std::function<void(i32)>#

Function object used to handle a specific signal.

signal::signal(enum signals s, handler fn)#

Main constructor accepting a signals member and handler function.

const handler &get_handler() const#

Getter for the handler function.

signal &set_handler(handler new_handler)#

Setter for the handler function.

const struct sigaction &sa() const#

Getter for the internal sigaction struct.

signal &sa(struct sigaction &new_sa)#

Setter for the internal sigaction struct.

const enum signals sig() const#

Getter for the signals member.

signal &sig(enum signals s)#

Setter for the signals member.

void setup(i32 flags = 0)#

Register the signal handler.

Example

auto handle_sig = [] (i32 sig) -> void
{
   io::printn("Hello, I'm catching signal {}", uni::signal_str(sig));
};

uni::signal sigint(uni::signals::interrupt, handle_sig);
sigint.setup();