I'm writing a script and at some point I call to "command1" which does not stop until it CTRL+C is invoked.
Thx!
The syntax for the timeout command is as follows: timeout [OPTIONS] DURATION COMMAND [ARG]… The DURATION can be a positive integer or a floating-point number, followed by an optional unit suffix: s - seconds (default)
The “timeout” command uses the “SIGTERM” to stop a process, but many processes ignore the “SIGTERM” signal. To forcefully terminate a process using the “SIGKILL” signal, cannot be ignored by any process. The “-k” option is being used to terminate the process.
Hold the Ctrl button and press the C key at the same time. It sends the SIGKILL signal to the running program to force quit the command.
You can use the timeout
command from GNU coreutils (you may need to install it first, but it comes in most, if not all, Linux distributions):
timeout [OPTION] DURATION COMMAND [ARG]...
For instance:
timeout 5 ./test.sh
will terminate the script after 5 seconds of execution. If you want to send a KILL signal (instead of TERM), use -k
flag.
Here you have the full description of the timeout
command.
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