in reply to Kill process after X mins

In Proc::Watchdog, I read:

A separate daemon (watchd) included along with this module, is called from cron or another similar service to check on the path.

So, does watchd run on your system and does it work? Also, does it have the appropriate permissions to kill the process(es) you run?

The three simpler approaches would be:

  1. Configure your webserver to kill processes after a certain time
  2. Use alarm to make your program commit suicide
  3. Look at what ulimits your OS supports and maybe limit CPU or wallclock time for your processes

Replies are listed 'Best First'.
Re^2: Kill process after X mins
by pradeepprakhar (Initiate) on Apr 20, 2017 at 15:31 UTC

    Can you please let me know how can we start the 'watchd' daemon on Linux machine. -Pradeep

      Have you read the documentation of Proc::Watchdog?

      If you are asking about the included watchd daemon only, use whaterver system service management tool your Linux vendor supports. This is mostly a system administration question and I know little of Linux system administration.

        I had gone through the Watchdog documentation earlier and now but it is still not clear for me that where can I start the watchd daemon in Linux. As per document "daemon" is a Linux OS term which is equivalent to Windows OS services.

Re^2: Kill process after X mins
by Anonymous Monk on Jul 21, 2011 at 13:15 UTC

    Many thanks, Corion!

    alarm does exactly what I was looking for. Does it also work if the process hung? In my case, it's a "while" loop and it was killed at the specified time.

    I'm using a shared server and don't have control over (1) and (3).

      alarm is likely a feature supplied by your operating system, so whether alarm works for a "hung" process really depends on your operating system and what you consider "hung".

      On unixish operating systems, SIGALRM will interrupt almost any (system) call. Most recent versions of Perl will likely only process signals after system calls have returned ("safe signals"). If your program gets "hung" in an endless loop, the SIGALRM handler will stop your program. If your program gets "hung" in some system call, it will not necessarily get immediately stopped.

      Personally, I question the wisdom of the person administrating the "shared server" without hard ulimits and hard maximum request limits, but maybe they have reasons for not limiting the resources users can consume.