LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2012, 01:50 PM   #1
ajayyadavmca
LQ Newbie
 
Registered: Dec 2006
Posts: 28

Rep: Reputation: 0
running command with timeout


Hi, i have searched about this and i get many ways to implement timeout while running commands/script in shell.

what i am doing right now is:
Code:
command1 &
pid=$!
( sleep 60; kill $pid ) &
# other commands with same line as above 
command2..
i know many drawback of doing above.

but i have also heard new coreutils timeout command has improved way of achieving this. i have searched but nothing interesting i have got.
i am using centOS 6.2, if anybody know what is this new coreutils timeout. and how to use?
 
Old 05-16-2012, 01:57 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
so you searched.
for example here: http://www.gnu.org/software/ coreutils/?
or maybe here: http://www.gnu.org/software/coreutils /manual/html_node /timeout-invocation.html#timeout-invocation
 
Old 05-16-2012, 01:59 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Well, here is the official manual: http://www.gnu.org/software/coreutil...nvocation.html. Running it should be as simple as
Code:
timeout 60 command1 &
 
Old 05-19-2012, 03:17 AM   #4
ajayyadavmca
LQ Newbie
 
Registered: Dec 2006
Posts: 28

Original Poster
Rep: Reputation: 0
thanks for this

thanks for help.
yea i see i dont need another mechanism and i can use timeout.

just if anyone has tried it please let me know if this will work.

so i have several commands which i will run using timeout and redirect error and out to a file.
my question is: Will there be a problem if many threads are writing/appending to that file? if yes how can i achieve synchronization in shell script?
 
Old 05-19-2012, 06:02 AM   #5
ajayyadavmca
LQ Newbie
 
Registered: Dec 2006
Posts: 28

Original Poster
Rep: Reputation: 0
thanks

i got it , i can use locks, easy. thanks all.
 
  


Reply



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
Getting timeout when running snmpwalk against localhost exceed1 Linux - Software 5 02-01-2013 05:14 PM
running scripts in another script with timeout and return status ajayyadavmca Programming 3 04-27-2012 10:24 AM
Command Timeout on path chickenjoy Solaris / OpenSolaris 1 02-07-2010 08:40 PM
Rsync running on IPSEC VPN timeout or getting very slow speed Moaahk Linux - Hardware 0 06-11-2008 09:46 PM
How to test whether a command timeout? DriveMeCrazy Programming 3 01-11-2007 08:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:43 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
Open Source Consulting | Domain Registration