Module signal
POSIX Signals
Functions
| kill (pid[, sig]) | Kills a process by sending a signal. |
signal
| sigmask (sig[, cmd]) | Modifies signal mask for current task. |
| sigpending () | Checks current task pending signals. |
| sigstate (sig[, state]) | Checks signal state for current task. |
Functions
- kill (pid[, sig])
-
Kills a process by sending a signal.
By default, sends SIGKILL.
An optional second argument can specify a different signal
(either by number or by using the constants from
signal.flags).Parameters:
- pid integer Process ID to kill.
- sig
integer
Signal number to send (default:
signal.flags.KILL). (optional)
Returns:
-
boolean
trueif the signal was sent successfully.Raises:
Error string (e.g., "ESRCH", "EPERM") if the operation fails.Usage:
signal.kill(1234) -- Kill process 1234 with SIGKILL (default) signal.kill(1234, signal.flags.TERM) -- Kill process 1234 with SIGTERM
signal
- sigmask (sig[, cmd])
-
Modifies signal mask for current task.
Parameters:
- sig integer Signal number
- cmd integer 0=BLOCK (default), 1=UNBLOCK (optional)
Raises:
error string on failure (EINVAL, EPERM, etc.)Usage:
pcall(signal.sigmask, 15) -- Block SIGTERM pcall(signal.sigmask, 15, 1) -- Unblock SIGTERM
- sigpending ()
-
Checks current task pending signals.
Returns:
-
boolean
Usage:
signal.sigpending() - sigstate (sig[, state])
-
Checks signal state for current task.
Parameters:
- sig integer Signal number
- state string One of: "blocked", "pending", "allowed" (optional)
Returns:
-
boolean
Usage:
signal.sigstate(15) -- check if SIGTERM is blocked (default) signal.sigstate(signal.flags.TERM, "pending")