class::sys::Signal

class sys::Signal
  : public api::WorkObject

This class is for sending POSIX style signals between processes and threads.

If you are brand new to Signals you can read the basics on wikipedia.

Basically, a signal can be sent from one process to another. Within a process a signal can be sent to a thread.

The operating system will pre-empt the receiving process to deliver the signal. If the receiving process has registerd a signal handler (see SignalHandler), the signal handler will be executed. Otherwise, the default handler will be executed.

The signal contains a signal number and an optional signal value.

The send() methods are used to send just the signal number. The queue() method sends the signal number as well as the signal value.

The SignalHandler class allows the receiving thread to create a handler for received signals. It can use a simple handler which will just look at the signal number or it can use a more sophisticated handler that will accept the signal number and signal value.

This code shows how to send a signal to another process.

int sigvalue = 100;
Signal sig(Signal::USR1, sigvalue);

pid_t another_process_pid;

sig.send(another_process_pid); //just sends USR1
sig.queue(another_process_pid); //send USR1 and sigvalue

The receiving process and handle the signals like this:

void signal_only_handler(int a){
  //handles just the signal number a = Signal::USR1
}

void signal_action_handler(int a, siginfo_t * info, void * context){
 //a = Signal::USR1 info->si_value.sival_int = 100, context is always NULL
}

SignalHandler my_signal_action_handler(signal_action_handler);

//this will tell the process to register signal_action_handler() to handle USR1
Signal incoming_signal(Signal::USR1);
incoming_signal.set_handler(my_handler);

This class handles Signal’s created by sofware. The hal::DeviceSignal class can be used to have the OS send a signal to a thread or process when a hardware event happens (such as a when a GPIO interrupt happens).

Summary

[Signal](#classsys_1_1_signal_1ab9c052a3999e9e6d4d10388d7381c232)(  

enum signal_number signo,
const arg::SignalValueInteger sigvalue
)

[Signal](#classsys_1_1_signal_1a4b77db9960e33f200599d537b1e7a3f6)(  

enum signal_number signo,
const arg::SignalValuePointer sigvalue
)

ev::Event event()

Signal & operator<<(

const SignalHandler & handler
)

int queue(

const arg::Pid pid
) const

int send(

const arg::Pid pid
) const

int send(

const arg::ThreadId t
) const

int send() const

int set_handler(

const SignalHandler & handler
) const

int signo() const

void * sigptr() const

int sigvalue() const

enum signal_number

Members

Signal(

enum signal_number signo,
const arg::SignalValueInteger sigvalue
)

Constructs an event based on a signal number.

Parameters

  • signo The signal number

  • sigvalue The signal value


Signal(

enum signal_number signo,
const arg::SignalValuePointer sigvalue
)

Constructs an event based on a signal number.

Parameters

  • signo The signal number

  • sigptr The signal value as a pointer


ev::Event event()

Returns a UI Event based on this signal event.


Signal & operator<<(

const SignalHandler & handler
)

Assigns the handler to the event.

Parameters

  • handler A reference to the SignalHandler

    void handle_abort(int a){
    
    }
    
    Signal abort_signal(Signal::ABRT);
    abort_signal << SignalHandler(handle_abort);
    
    //code is all set up to execute handle_abort() when SIGABRT fires
    abort_signal.send(); //send abort to self
    

int queue(

const arg::Pid pid
) const

Sends a signal and associated sigvalue to a process.

Parameters

  • pid The process ID of the receiving signal

Returns

Zero on success

This method sends this signal to the specified PID. It uses the POSIX sigqueue() function meaning the the signal will be sent along with signo and sigvalue.


int send(

const arg::Pid pid
) const

Sends a signal to a process.

Parameters

  • pid The process ID of the receiving signal

Returns

Zero on success

This method sends this signal to the specified PID. It uses the POSIX kill() function.


int send(

const arg::ThreadId t
) const

Sends a signal to a thread within a process.

Parameters

  • t The thread ID

Returns

Zero on success


int send() const

Triggers the event on the current thread.


int set_handler(

const SignalHandler & handler
) const

Sets the event handler.

Parameters

Returns

Zero on success


int signo() const

Returns the signal number.


void * sigptr() const

Returns the signal pointer.


int sigvalue() const

Returns the signal value.


enum signal_number
  • ABRT Abort signal, default action is to abort
  • FPE FPE signal, default action is to abort
  • INT Interrupt signal, default action is to terminate
  • ILL Illegal signal, default action is to abort
  • SEGV Segmentation signal, default action is to abort
  • TERM Terminal signal, default action is to terminate
  • ALRM Alarm signal, default action is to terminate
  • BUS Bus signal, default action is to abort
  • CHLD Child signal, default action is to ignore
  • CONT Continue signal, default action is to continue
  • HUP Hangup signal, default action is to terminate
  • KILL Kill signal, default action is to terminate (cannot be caught or ignored)
  • PIPE Pipe signal, default action is to terminate
  • QUIT Quit signal, default action is to abort
  • STOP Stop signal, default action is to stop (cannot be caught or ignored)
  • TSTP TSTP signal, default action is to stop
  • TTIN TTIN signal, default action is to stop
  • TTOU TTOU signal, default action is to stop
  • USR1 User signal, default action is to terminate
  • USR2 User signal, default action is to terminate
  • PROF PROF signal, default action is to terminate
  • SYS System signal, default action is to abort
  • TRAP Trap signal, default action is to abort
  • URG URG signal, default action is to ignore
  • TALRM TALRM signal, default action is to terminate
  • XCPU XCPU signal, default action is to abort
  • XFSZ XFSZ signal, default action is to abort
  • POLL Poll signal, default action is to terminate
  • RTMIN Real time signal, default action is to ignore
  • RT Real time signal, default action is to ignore
  • RTMAX Real time signal, default action is to ignore

X

Thanks for Coming!

Subscribe to news and updates