The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
signal.h
Go to the documentation of this file.
1#pragma once
2
3#include <sys/types.h>
4
5/**
6 * @file signal.h
7 * @brief signals: kill, sigaction, masks.
8 *
9 * the numbers, flags and the kernel's sigaction layout are ABI and must
10 * match src/kernel/signal/signal.h exactly.
11 */
12
13typedef unsigned int sigset_t;
14typedef int sig_atomic_t;
15
16#define SIGHUP 1
17#define SIGINT 2
18#define SIGQUIT 3
19#define SIGILL 4
20#define SIGTRAP 5
21#define SIGABRT 6
22#define SIGBUS 7
23#define SIGFPE 8
24#define SIGKILL 9
25#define SIGUSR1 10
26#define SIGSEGV 11
27#define SIGUSR2 12
28#define SIGPIPE 13
29#define SIGALRM 14
30#define SIGTERM 15
31#define SIGCHLD 17
32#define SIGCONT 18
33#define SIGSTOP 19
34#define SIGTSTP 20
35#define SIGTTIN 21
36#define SIGTTOU 22
37#define SIGURG 23 // urgent data on a socket (ignored by default)
38#define SIGVTALRM 26 // a virtual timer ran out (no such timers yet)
39#define SIGPROF 27 // a profiling timer ran out (no such timers yet)
40#define SIGWINCH 28 // the terminal's window size changed (ignored by default)
41#define NSIG 32
42
43typedef void (*sighandler_t)(int);
44
45#define SIG_DFL ((sighandler_t)0)
46#define SIG_IGN ((sighandler_t)1)
47#define SIG_ERR ((sighandler_t)-1)
48
49// sa_flags
50#define SA_NOCLDSTOP 0x00000001
51#define SA_RESTORER 0x04000000 // set by the libc
52#define SA_RESTART 0x10000000
53#define SA_NODEFER 0x40000000
54#define SA_RESETHAND 0x80000000
55
56// sigprocmask how
57#define SIG_BLOCK 0
58#define SIG_UNBLOCK 1
59#define SIG_SETMASK 2
60
62{
63 sighandler_t sa_handler; // SIG_DFL, SIG_IGN or a function
64 int sa_flags; // SA_*
65 void (*sa_restorer)(void); // filled in by sigaction()
66 sigset_t sa_mask; // signals blocked while the handler runs
67};
68
69/**
70 * read and change what the process does with a signal.
71 * @return 0, or -1 (errno set; EINVAL for SIGKILL and SIGSTOP).
72 */
73int sigaction(int sig, const struct sigaction *act, struct sigaction *oldact);
74
75/**
76 * set a handler (with SA_RESTART, as BSD signal() does).
77 * @return the old handler, or SIG_ERR.
78 */
80
81/**
82 * send a signal to a process (pid > 0) or every process but init (-1).
83 * @return 0, or -1 (errno set).
84 */
85int kill(pid_t pid, int sig);
86
87/**
88 * send a signal to the calling process.
89 */
90int raise(int sig);
91
92/**
93 * read and change the blocked mask.
94 */
95int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
96
97/**
98 * the signals that are blocked and pending.
99 */
101
102/**
103 * wait for a signal with a temporary mask. always returns -1 with EINTR.
104 */
105int sigsuspend(const sigset_t *mask);
106
109int sigaddset(sigset_t *set, int sig);
110int sigdelset(sigset_t *set, int sig);
111int sigismember(const sigset_t *set, int sig);
int raise(int sig)
send a signal to the calling process.
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
read and change the blocked mask.
int sigdelset(sigset_t *set, int sig)
unsigned int sigset_t
Definition signal.h:13
int kill(pid_t pid, int sig)
send a signal to a process (pid > 0) or every process but init (-1).
int sigemptyset(sigset_t *set)
sighandler_t signal(int sig, sighandler_t handler)
set a handler (with SA_RESTART, as BSD signal() does).
int sig_atomic_t
Definition signal.h:14
int sigismember(const sigset_t *set, int sig)
int sigpending(sigset_t *set)
the signals that are blocked and pending.
int sigfillset(sigset_t *set)
void(*) sighandler_t(int)
Definition signal.h:43
int sigaddset(sigset_t *set, int sig)
int sigsuspend(const sigset_t *mask)
wait for a signal with a temporary mask.
Definition signal.h:62
sighandler_t sa_handler
Definition signal.h:63
void(*) sa_restorer(void)
Definition signal.h:65
sigset_t sa_mask
Definition signal.h:66
int sa_flags
Definition signal.h:64
basic system types.
int pid_t
Definition types.h:16