VisezTrance

  • April 30, 2010 10:40 PM

    Timing out

    By Daniel
    I was running a rake task that launched a third party proprietary binary that handled some files. The process was usually fast, lasting about two or three seconds per file although sometimes it would just lock up and become unresponsive while still pegging the cpu at 100%.
    While I love a good challenge, there are times when a battle proven solution is preferable.
    Fortunetly for me, there was a *nix command named timeout, that did exactly what I was looking for.

    The following would kill a running command with signal 9 (the equivalent of powering off the computer) if it runs longer than 30 seconds:

    timeout --signal=9 30s /some/command

    Suffice to say, that I was so pleased of this solution that I'm going to use it everytime I can.
    A slight warning - the timeout command is provided by the coreutils package. While it was avaiable in Fedora, it wasn't on the staging machine I deployed it to, running CentOS. I did managed to get it working (without any problems) using the binary from my desktop machine.

    Tags:

    • defensive programming,
    • timeout
  • Monthly Archives

    • October 2013 (2)
    • May 2012 (1)
    • October 2011 (1)
    • September 2011 (2)
    • March 2011 (3)
    • February 2011 (1)
    • January 2011 (1)
    • September 2010 (1)
    • August 2010 (1)
    • June 2010 (1)
    • April 2010 (1)
    • December 2009 (1)
    • October 2009 (1)
    • September 2009 (1)
    • August 2009 (1)
    • July 2009 (2)
    • April 2009 (2)
    • February 2009 (1)
    • January 2009 (2)
    • December 2008 (1)
    • October 2008 (1)
  • Pages

    • About / Contact

2008, © Daniel Mircea