I have two one liners:
In first. I've expected killing sh -c "..."
command after 5 seconds but it exists until the timeout exits (for 10 seconds)
timeout -k 5s 10s sh -c 'sleep 20s && echo "Long running command which is visible under: ps -elf | grep sleep during whole life (10s) time of timeout command"'
In second. I've expected that timeout will exit with return code 124 (because the sh -c "..."
command is still running) while the command sh -c "..."
will continue to run (because of kill option for timeout was not set)
timeout 10s sh -c 'sleep 20s && echo "Long running command which is visible under: ps -elf | grep sleep during whole life (10s) time of timeout command"'
It seems that argument passed to timeout runs for exact time as timeout command itself (it is not killed earlier nor survive timeout) what is the purpose of kill option then?
timeout is a command-line utility that runs a specified command and terminates it if it is still running after a given period of time. In other words, timeout allows you to run a command with a time limit.
Linux watch Command Overview By default, the watch command updates the output every two seconds. Press Ctrl+C to exit out of the command output.
The command kill sends the specified signal to the specified processes or process groups. If no signal is specified, the TERM signal is sent. The default action for this signal is to terminate the process.
The option -k
is to send KILL
signal after the specified seconds if the process couldn't be terminated after the timeout.
timeout
first sends the TERM
signal. If -k
is specified, then it'll also send KILL
signal, following the real timeout value.
For example
timeout -k 5 10 someCommand
timeout
sends TERM
signal after the 10 seconds. If someCommand
didn't respond to TERM
(e.g. it could block the TERM
signal) then timeout
sends KILL
signal after 5 more seconds (i.e. at the 15th second since the start of execution). The signal KILL
can't be blocked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With