LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Place a timeout on a script? (https://www.linuxquestions.org/questions/linux-newbie-8/place-a-timeout-on-a-script-489710/)

meniscus 10-05-2006 11:16 AM

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?

makyo 10-05-2006 11:39 AM

Hi.

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.
Code:

      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

makyo 10-05-2006 01:09 PM

Hi.

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

In one window, you run a command, say:
Code:

sleep 1000
So that's now running in the foreground in that window. In another window, you enter:
Code:

% ps -u makyo | grep sleep
substituting your name for makyo, the command you enter for sleep, etc. That produces:
Code:

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:
Code:

% at now + 1 minute
which will prompt you for commands. You enter whatever
you wish, and terminate with ^D:
Code:

at> kill 23040
at> <EOT>

which will produce a message:
Code:

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


All times are GMT -5. The time now is 03:38 AM.