Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-05-2006, 11:16 AM   #1
Registered: May 2006
Posts: 70

Rep: Reputation: 15
Place a timeout on a script?

How do you place a timeout on a script? Lets say ur using tail -f to follow a process but you want the process to end after 12hours nomatter what. or is it even possible?
Old 10-05-2006, 11:39 AM   #2
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 731

Rep: Reputation: 75

There are some limits that can imposed on processes, but I don't think that wall-clock time is one of them. I'd certainly like to hear if there is some such facility.
       ulimit [-SHacdflmnpstuv [limit]]
              Provides  control  over the resources available to the shell and
              to processes started by it, on systems that allow such  control.
  -- man bash builtin
Off the top of my head - if I were faced with this, I think I would write a script that calls another script that actually does the work, like the tail. The first script would then use the process ID of the second to pass into an at (and friends) command, which would then wake up at the specific time later, and kill the process.

I'd use either the tail or perhaps sleep for testing.

If you choose this, let us know how it works out. I suspect others may have some ideas as well ... cheers, makyo
Old 10-05-2006, 01:09 PM   #3
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 731

Rep: Reputation: 75

If you are not comfortable writing a script version, here's a manual procedure.

In one window, you run a command, say:
sleep 1000
So that's now running in the foreground in that window. In another window, you enter:
% ps -u makyo | grep sleep
substituting your name for makyo, the command you enter for sleep, etc. That produces:
23040 pts/2    00:00:00 sleep
That gives you the process ID, 23040. Now you enter the scheduling command and whatever time you like, for example:
% at now + 1 minute
which will prompt you for commands. You enter whatever
you wish, and terminate with ^D:
at> kill 23040
at> <EOT>
which will produce a message:
job 13 at 2006-10-05 12:54
The original process continues until the time you specified, then it runs your sequence of at commands, which, in this example, kills the sleep process 23040. The at command is very friendly with time options: minutes, hours, etc., see man at for more details ... cheers, makyo


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
where to place certiain commands inside shell script beeblequix Linux - Newbie 8 08-10-2006 11:12 AM
script 'prompting with timeout' question WindowBreaker Slackware 2 03-09-2006 12:44 PM
what script to place this command? fuzzhead85 Mandriva 1 03-23-2005 11:39 PM
Script for voice modem to place a call masterJ Linux - General 1 07-27-2004 04:23 AM
PHP script timeout J_Szucs Linux - Software 4 01-22-2004 04:10 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:31 PM.

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