how to autokill a hanging subprocess from a script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
how to autokill a hanging subprocess from a script
I have a perl script which launches a system command repeatedly from a looping control structure. Occasionally, one instance of that command will hang indefinitely until I manually kill it with 'pkill cmdname' from a shell. Then the loop will continue where it left off.
How can I execute a system command in perl, but autokill that command if it takes longer than 60 seconds to complete?
I'd be more inclined to discover why the script is hanging in the first place...
Good question. It's a compiled program called khtml2png2 used to gather screenshots. About 1 out of 20 times it will just hang for hours on end. I've compiled and ran the thing on multiple computers with different linux distro's - same problem.
Thanks to everyone for the responses. I ended up using perl's 'alarm' function. In the hopes that it will help somebody else, here's how I did it:
Ok, I see, it is someone else's poorly-written piece of software that hangs. Apparently, these issues have been around for a while with this software. You might want to report it to the author though.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.