LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Time out for Linux commands (https://www.linuxquestions.org/questions/linux-newbie-8/time-out-for-linux-commands-4175542265/)

gaurav_s 05-11-2015 06:56 AM

Time out for Linux commands
 
I am calling lsof command in perl script,but due to node issue it's getting stucked .
Because of this script is unable to exit and finish execution. please help.

pan64 05-11-2015 06:59 AM

http://www.perlmonks.org/?node_id=324176

gaurav_s 05-11-2015 09:50 AM

Basically, i want timeout for individual command.

#lsof -a -p <pid> | wc -l

above command is taking too much time. so i want to put timeout for it and also kill it and also notify the script that command timed out.

jpollard 05-13-2015 07:08 AM

Don't use lsof... :)

It inherently takes time as some of the data can get paged out (depending on which process it is) and has to wait for it to be paged back in. And depending on the system activity, it can take quite a while.

What are you actually trying to do?

hgallo 05-13-2015 07:29 AM

Use the timeout command. For example
small script that lasts 10 seconds

#ten.sh
#!/bin/bash
for n in {1..10} ;do echo $n ; sleep 1 ; done


run it with the timeout at 2 seconds


[root@test ~]# timeout 2 /tmp/ten.sh
1
2
[root@test ~]#


All times are GMT -5. The time now is 07:58 AM.