S Signal / Send Signal On Timeout
Send Signal On Timeout
Sends a signal to a command upon timeout.
timeout -s <INT|HUP|KILL|...> <5s> <sleep 10> timeout -s <INT|HUP|KILL|...> <5s> <sleep 10> #!/bin/bash
# Send Signal On Timeout
timeout {{[-s|--signal]}} {{INT|HUP|KILL|...}} {{5s}} {{sleep 10}} import subprocess
# Send Signal On Timeout
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"s---signal",
"-s",
"<INT|HUP|KILL|...>",
"<5s>",
"{{sleep",
"10}}"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: s---signal not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
During automation scripts needing precise control over processes in timed intervals
Pro Tip
Spectacularly useful with complex commands; avoid race conditions by testing signal handling behavior.
Command Builder
Tune the command before you copy it
timeout -s <INT|HUP|KILL|...> <5s> <sleep 10> Anatomy of Output
Understanding the result
Sending signal KILL to process 1234 after 5 seconds Signal Info Confirms the action taken on timeout.
Process terminated as expected; exit code 9 Exit Code Indicates successful termination of command.
No additional actions required Completion Note Final status on process handling.
Power User Variants
Optimized versions
s---signal TERM 10s sleep 10 Send SIGTERM instead of default on timeout.
s---signal HUP 15s my_command Send SIGHUP on timeout for resource cleanup.
Troubleshooting
Common pitfalls
timeout: unknown signal 'INVALID_SIGNAL'
Solution: Verify the signal name against valid options and retry.
timeout: command failed to execute
Solution: Check command syntax and execution environment.
timeout: failed to send signal to process
Solution: Ensure the target process is active before issuing the command.
Command Breakdown
What each part is doing
-
timeout - Base Command
- The executable that performs this operation. Here it runs S Signal before the shell applies any redirect operators.
-
-s - s| signal
- The value supplied for s| signal.
-
<INT|HUP|KILL|...> - INT|HUP|KILL|...
- The value supplied for INT|HUP|KILL|....
-
<5s> - 5s
- The value supplied for 5s.
-
<sleep 10> - sleep 10
- The value supplied for sleep 10.
-
-s - Command Option
- Tool-specific option used by this command invocation.
Alternative Approaches
Comparable commands in other tools
Alternative system operations tools for the same job.
killall -l Bitcoind / Start Bitcoin Core Daemon Specific Network bitcoind -chain=<main|test|signet|regtest> Systemctl / Send Specific Signal To Unit systemctl kill -s <signal_number|signal_name> <unit> Systemctl / Send Sighup Main Process systemctl kill -s SIGHUP --kill-whom main <unit> Systemctl / List Available Signals systemctl kill -s help