Disponible uniquement en anglais
Sysquake Pro – Table of Contents
Sysquake for LaTeX – Table of Contents
Extension - Signals
This section describes functions which offer support for POSIX signals, i.e. a way for LME to be interrupted asynchronously from another process. They map directly to the kill and signal POSIX functions; therefore, they can interoperate with programs which call them directly.
These functions are available only on Posix systems, such as macOS.
Functions
getpid
Get the current process ID.
Syntax
pid = getpid
Description
getpid gives the ID of the current process.
See also
kill
Send a signal to another process.
Syntax
kill(pid) kill(pid, sig)
Description
kill(pid) sends signal 2 (SIGINT) to process pid. kill(pid,sig) sends signal sig given as a number between 1 and 31 or as a name in a string (see signal for a list).
See also
signal
Install a signal action.
Syntax
signal(sig, fun) signal(sig)
Description
signal(sig,fun) installs function fun as the action for signal sig. fun can be a function name in a string, a function reference, or an inline function with neither input nor output argument; sig is the number of the signal between 1 and 31, or its name as a string. The following names are recognized (standard POSIX names compatible with the program or shell command kill and C header file signal.h); case is not significant, and names can be prefixed with 'sig'.
Name | Number | Name | Number |
---|---|---|---|
'hup' | 1 | 'stop' | 17 |
'int' | 2 | 'tstp' | 18 |
'quit' | 3 | 'cont' | 19 |
'ill' | 4 | 'chld' | 20 |
'trap' | 5 | 'ttin' | 21 |
'abrt' | 6 | 'ttou' | 22 |
'emt' | 7 | 'io' | 23 |
'fpe' | 8 | 'xcpu' | 24 |
'kill' | 9 | 'xfsz' | 25 |
'bus' | 10 | 'vtalrm' | 26 |
'segv' | 11 | 'prof' | 27 |
'sys' | 12 | 'winch' | 28 |
'pipe' | 13 | 'info' | 29 |
'alrm' | 14 | 'usr1' | 30 |
'term' | 15 | 'usr2' | 31 |
'urg' | 16 |
Note that signals 9 and 17 cannot be caught. Once a signal action has been installed, if the specified signal is sent to the LME application (typically with the LME or POSIX function kill), the function fun is executed as soon as possible, at a time when it does not corrupt the LME execution data. It can exchange information with the normal execution of LME via global variables; but semaphores cannot be used to guarantee exclusive access, because the signal action is not executed in a separate thread and locked semaphores could not be unlocked by the main thread.
Example
Install a signal action which is triggered by signal usr1:
fun = inline('function f;fprintf(''Got signal usr1\n'');'); signal('usr1', fun);
Get process ID (the number is likely to be different):
getpid 22716
From another shell, use the program or shell command kill to send a signal to LME:
kill -SIGUSR1 22716