How to avoid script from hanging eternally?
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]
Ctrl-C will terminate execution.
[edited by - falsk on September 10, 2003 1:23:05 PM]
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]
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[_]~~
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement