Search code examples
macostimeoutkilllaunchd

Automatic timeout for launchd jobs


I have a launchd job that I've configured to run my unit tests. Every now and then, the unit tests will hang (usually because of some bad code). I know that my test usually only take a couple minutes to run. When they do hang, I usually don't notice it for about an hour, at which point I have to pop open Activity Monitor and forcibly kill my tests manually. I want launchd to do this for me. How can I have launchd automatically kill my job (if it's still running) after a certain amount of time?

I've been looking over the launchd man page, and I've noticed a couple promising keys (like TimeOut and ExitTimeOut), but the wording on the descriptions seems like it's not quite what I'm looking for.


Solution

  • After playing with TimeOut and ExitTimeOut, I've concluded that there doesn't seem to be a way for launchd to kill processes after a certain time interval.

    I ended up adding the needed code to my program itself. (My program does more than just unit tests)