Home Error using timeout command - invalid time interval
Reply: 1

Error using timeout command - invalid time interval

Hamid Reza
Hamid Reza Published in 2018-02-12 05:53:16Z

I want to kill a command after waiting for result for 2 seconds. If the command didn't come up with a result (took too long), the command should stop. I have gone through the documents and tested the following command:

timeout --kill-after=2 ls /mnt/ftp/;
echo $?;


timeout -k 2 ls /mnt/ftp/;
echo $?;

However, I am getting this error:

timeout: invalid time interval ‘ls’

Note: The command below stops after timeout period by doesn't kill the process:

timeout 2 ls /mnt/ftp/;
Inian Reply to 2018-02-12 06:15:44Z

The documentation for timeout is tricky in a way. If you refer it carefully it says

$ timeout --help
  or:  timeout [OPTION]
Start COMMAND, and kill it if still running after DURATION.

Here the option -k itself takes a value followed by a value needed for DURATION also, so your command should two values back to back when using -k as below. The error is thrown because DURATION is a mandatory argument to be used.

timeout --kill-after=2 2 ls /mnt/ftp/;

The first option --kill-after=2 is part of the OPTION flag to the command which takes value 2 and the DURATION itself takes a value 2 separately.

timeout -k 2 2 ls /mnt/ftp/;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.339221 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO