libcosmos
Linux C++ System Programming Library
Loading...
Searching...
No Matches
types.hxx File Reference
#include <iosfwd>
#include <string>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <cosmos/dso_export.h>
#include <cosmos/error/errno.hxx>
#include <cosmos/types.hxx>

Go to the source code of this file.

Classes

class  cosmos::Signal
 Represents a POSIX signal number and offers a minimal API around it. More...
 

Enumerations

enum class  cosmos::ProcessID : pid_t { INVALID = -1 , SELF = 0 , CHILD = 0 }
 
enum class  ProcessGroupID : pid_t { INVALID = -1 , SELF = 0 }
 
enum class  cosmos::ExitStatus : int { INVALID = -1 , SUCCESS = EXIT_SUCCESS , FAILURE = EXIT_FAILURE }
 Represents an exit status code from a child process. More...
 
enum class  cosmos::SignalNr : int {
  NONE = 0 , HANGUP = SIGHUP , INTERRUPT = SIGINT , QUIT = SIGQUIT ,
  ILL = SIGILL , TRAP = SIGTRAP , SYS_TRAP = SIGTRAP | 0x80 , ABORT = SIGABRT ,
  IOT = ABORT , BUS = SIGBUS , FPE = SIGFPE , KILL = SIGKILL ,
  USR1 = SIGUSR1 , SEGV = SIGSEGV , USR2 = SIGUSR2 , PIPE = SIGPIPE ,
  ALARM = SIGALRM , TERMINATE = SIGTERM , STACK_FAULT = SIGSTKFLT , CHILD = SIGCHLD ,
  CONT = SIGCONT , STOP = SIGSTOP , TERM_STOP = SIGTSTP , TERM_INPUT = SIGTTIN ,
  TERM_OUTPUT = SIGTTOU , URGENT = SIGURG , CPU_EXCEEDED = SIGXCPU , FS_EXCEEDED = SIGXFSZ ,
  VIRTUAL_ALARM = SIGVTALRM , PROFILING = SIGPROF , WIN_CHANGED = SIGWINCH , IO_EVENT = SIGIO ,
  POLL = IO_EVENT , POWER = SIGPWR , BAD_SYS = SIGSYS , MAXIMUM = _NSIG
}
 A primitive signal number specification. More...
 

Functions

COSMOS_API std::ostream & operator<< (std::ostream &o, const cosmos::Signal sig)
 Print a friendly name of the signal to the given output stream.
 
COSMOS_API std::ostream & operator<< (std::ostream &o, const cosmos::ExitStatus status)
 Outputs the strongly typed ExitStatus as an integer.
 

Detailed Description

Basic types used in process control and signaling.

Definition in file types.hxx.

Enumeration Type Documentation

◆ ExitStatus

enum class cosmos::ExitStatus : int
strong

Represents an exit status code from a child process.

The valid range of exit statuses is 0 .. 255 (the 8 lower bits of the si_status field in SigInfo).

Definition at line 43 of file types.hxx.

43 : int {
44 INVALID = -1,
45 SUCCESS = EXIT_SUCCESS,
46 FAILURE = EXIT_FAILURE,
47};

◆ ProcessGroupID

enum class cosmos::ProcessGroupID : pid_t
strong

Definition at line 33 of file types.hxx.

33 : pid_t {
34 INVALID = -1,
35 SELF = 0
36};
@ SELF
In a number of system calls zero refers to the calling thread.

◆ ProcessID

enum class cosmos::ProcessID : pid_t
strong
Enumerator
SELF 

In a number of system calls zero refers to the calling thread.

CHILD 

In fork/clone like system calls zero refers to the child context.

Definition at line 25 of file types.hxx.

25 : pid_t {
26 INVALID = -1,
28 SELF = 0,
30 CHILD = 0
31};

◆ SignalNr

enum class cosmos::SignalNr : int
strong

A primitive signal number specification.

Enumerator
HANGUP 

hangup on controlling process or controlling process died

INTERRUPT 

interrupt from keyboard

QUIT 

quit from keyboard

ILL 

illegal instruction

TRAP 

trace/breakpoint trap

SYS_TRAP 

system call trap report (only seen with ptrace(2), PTRACE_O_TRACESYSGOOD)

ABORT 

abort signal from abort()

IOT 

IOT trap, synonym for ABORT.

BUS 

bus error (bad memory access)

FPE 

floating point exception

KILL 

kill process (cannot be ignored)

USR1 

user defined signal 1

SEGV 

segmentation fault (invalid memory reference)

USR2 

user defined signal 2

PIPE 

broken pipe, write to pipe with no readers

ALARM 

timer signal from alarm()

TERMINATE 

termination request (cooperative)

STACK_FAULT 

stack fault on coprocessor (unused)

CHILD 

child stopped or terminated

CONT 

continue if stopped

STOP 

stop process, cannot be ignored

TERM_STOP 

stop typed at terminal

TERM_INPUT 

terminal input for background processes

TERM_OUTPUT 

terminal output for background processes

URGENT 

urgent condition on socket

CPU_EXCEEDED 

CPU time limit exceeded.

FS_EXCEEDED 

file size exceeded

VIRTUAL_ALARM 

virtual alarm clock

PROFILING 

profiling timer expired

WIN_CHANGED 

window resize signal (terminal)

IO_EVENT 

I/O now possible.

POLL 

pollable event, synonym for IO

POWER 

power failure

BAD_SYS 

bad system call

MAXIMUM 

largest signal number defined

Definition at line 50 of file types.hxx.

50 : int {
51 // using some longer identifiers here to avoid symbol clashes with C library preprocessor defines
52 // in some cases also for better readability
53 NONE = 0, // it's unclear from docs what a good invalid signal number might be, but 0 is not used ATM
54 HANGUP = SIGHUP,
55 INTERRUPT = SIGINT,
56 QUIT = SIGQUIT,
57 ILL = SIGILL,
58 TRAP = SIGTRAP,
59 SYS_TRAP = SIGTRAP | 0x80,
60 ABORT = SIGABRT,
61 IOT = ABORT,
62 BUS = SIGBUS,
63 FPE = SIGFPE,
64 KILL = SIGKILL,
65 USR1 = SIGUSR1,
66 SEGV = SIGSEGV,
67 USR2 = SIGUSR2,
68 PIPE = SIGPIPE,
69 ALARM = SIGALRM,
70 TERMINATE = SIGTERM,
71 STACK_FAULT = SIGSTKFLT,
72 CHILD = SIGCHLD,
73 CONT = SIGCONT,
74 STOP = SIGSTOP,
75 TERM_STOP = SIGTSTP,
76 TERM_INPUT = SIGTTIN,
77 TERM_OUTPUT = SIGTTOU,
78 URGENT = SIGURG,
79 CPU_EXCEEDED = SIGXCPU,
80 FS_EXCEEDED = SIGXFSZ,
81 VIRTUAL_ALARM = SIGVTALRM,
82 PROFILING = SIGPROF,
83 WIN_CHANGED = SIGWINCH,
84 IO_EVENT = SIGIO,
85 POLL = IO_EVENT,
86 POWER = SIGPWR,
87 BAD_SYS = SIGSYS,
88#if 0
89 LOST = SIGLOST,
90 EMT = SIGEMT,
91#endif
92 MAXIMUM = _NSIG
93};

Function Documentation

◆ operator<<() [1/2]

COSMOS_API std::ostream & operator<< ( std::ostream & o,
const cosmos::ExitStatus status )

Outputs the strongly typed ExitStatus as an integer.

this could be annotated with a special character so that it is clear right away that this is about an exit status

Definition at line 241 of file process.cxx.

241 {
244 o << cosmos::to_integral(status);
245 switch (status) {
246 case cosmos::ExitStatus::INVALID: o << " (INVALID)"; break;
247 case cosmos::ExitStatus::SUCCESS: o << " (SUCCESS)"; break;
248 case cosmos::ExitStatus::FAILURE: o << " (FAILURE)"; break;
249 default: o << " (other)"; break;
250 }
251 return o;
252}

◆ operator<<() [2/2]

COSMOS_API std::ostream & operator<< ( std::ostream & o,
const cosmos::Signal sig )

Print a friendly name of the signal to the given output stream.

Definition at line 25 of file types.cxx.

25 {
26 o << sig.name() << " (" << sig.raw() << ")";
27
28 return o;
29}
std::string name() const
Returns a human readable label for the currently stored signal number.
Definition types.cxx:16
SignalNr raw() const
Returns the primitive signal number stored in this object.
Definition types.hxx:115