Advertisement

How to avoid script from hanging eternally?

Started by September 09, 2003 09:53 PM
4 comments, last by -vic- 21 years, 1 month ago
Hello folks, i''m writing a shell script here, and there''s a command this script executes that not always works fine. I mean, sometimes this command just hangs there, and so the script hangs waiting for the command finish its execution. How can i interrupt a program''s execution (just like what we do with Ctrl+C) if it hangs for some time (so that the script may continue its execution...)? Victor.
c[_]~~
Ctrl-Z will suspend execution.
Ctrl-C will terminate execution.

[edited by - falsk on September 10, 2003 1:23:05 PM]
Advertisement
Have you tried using the kill command on the script?
If I understand you, you want the script to be able to recover if it hangs?

You could probably run it as a background task with &.


#!/bin/bash

/your/command/here &
printf "Ran Your Command\n"
...
...
...
printf "Script complete\n"

If you want to build in some logic to check if the task is hung, you'll need to grab its PID or validate the program task with some other external means (status file, log message, etc).

Int.

[edited by - Interim on September 10, 2003 11:30:29 AM]
quote: Original post by Interim
If I understand you, you want the script to be able to recover if it hangs?


Yup, you got it right

quote:

You could probably run it as a background task with &.


#!/bin/bash

/your/command/here &
printf "Ran Your Command\n"
...
...
...
printf "Script complete\n"

If you want to build in some logic to check if the task is hung, you''ll need to grab its PID or validate the program task with some other external means (status file, log message, etc).

Int.

[edited by - Interim on September 10, 2003 11:30:29 AM]


Hmm... ok... isn''t there any command to do that automatically? I mean, there could be some kind of command like:

avoidhanging -t 60 foo_program

And then avoidhanging would only let the "foo_program" run for 60 seconds

Ok, ok, i''m lazy huh? Alright, gonna implement that...

Thanks anyway,
Victor.

c[_]~~
check out the "limit" command.

How appropriate. You fight like a cow.

This topic is closed to new replies.

Advertisement