LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-11-2015, 07:56 AM   #1
gaurav_s
Member
 
Registered: Jul 2014
Posts: 43

Rep: Reputation: Disabled
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.
 
Old 05-11-2015, 07:59 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
http://www.perlmonks.org/?node_id=324176
 
Old 05-11-2015, 10:50 AM   #3
gaurav_s
Member
 
Registered: Jul 2014
Posts: 43

Original Poster
Rep: Reputation: Disabled
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.
 
Old 05-13-2015, 08:08 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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?
 
Old 05-13-2015, 08:29 AM   #5
hgallo
LQ Newbie
 
Registered: Apr 2011
Posts: 10

Rep: Reputation: 0
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 ~]#
 
  


Reply

Tags
command, script, timeout


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to Change the Linux Date and Time: Simple Commands LXer Syndicated Linux News 1 10-13-2012 01:07 PM
keyboard input time is more for typing commands in linux san_77 Linux - Newbie 3 08-16-2010 12:13 AM
Executing commands at a specified time Siva4Linux Linux - Wireless Networking 7 02-21-2007 06:49 AM
using sleep() and time() commands together in c++ totaljj Programming 1 02-14-2007 08:12 AM
Commands executed at boot time Johnburrell Linux From Scratch 3 09-18-2005 02:56 PM


All times are GMT -5. The time now is 10:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration