http://qs321.pair.com?node_id=10373

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a script (obviously) that isn't doing exactly what it is supposed to. The intent of the script is to act as a daemon, where every few seconds or minutes, it contacts a MySQL server to get information and processes that info. Now, for the problem. It dies. The script cannot last for an extended period of time. We need to have crontab trying to keep it alive. What kinds of things can kill it? (We trapped the signals so that we could figure out what signals were occuring, but none of the handlers were being called. So, the thing just "disappears" from memory without a trace. Ideas? Joe
  • Comment on script meant to act as daemon dies unexpectedly

Replies are listed 'Best First'.
Re: script meant to act as daemon dies unexpectedly
by plaid (Chaplain) on May 05, 2000 at 20:46 UTC
    The first thought that pops up (which assumes a unix system; if not skip this part) is that you're hitting some sort of resource limit on the system. If you are running this from the command line, check 'limit cputime' in csh/tcsh or 'ulimit -t' in bash/ksh. Also, if the problem is occurring when you log out, you'll need to 'nohup' your program, to prevent it from being sent SIGHUP when you log out.. it's run like 'nohup ./perl_program args'.

    If the above doesn't help, there are unfortunately several things that could be causing it outside of perl. As mentioned above, it could be MySQL with the problem. The best advice I can give is to do some verbose debugging in the script: write out to a logfile, check every return code from all system calls and MySQL calls, write success messages for every part that succeeds, etc. Try putting an END block in your perl code to trap the time that it's dying, and see if it's doing so at a regular interval.

    Hope this helps.

      That's definitely a possibility. On my personal linux machine, it never dies. On the web server, it is dying aproximately once every ten minutes or so. I will do some more research and see if that's the case, but that's what I am thinking. Thanks for the tips!
Re: script meant to act as daemon dies unexpectedly
by lhoward (Vicar) on May 05, 2000 at 19:51 UTC
    Does your script maintain a persistant connection to MySQL (or any other applications) or does it make a new connection every time? If it does have presistant connections it could be that the connection is breaking (from the other side) and that is killing your application. Have you tried running your application as a command line process (not a daemon) and seeing if it reports any errors when it dies?
      We've run it from the command line and even in the Windows environment to see if it behaves differently. It is not a persistent connection to the database, and on my personal linux box it hasn't died yet. It's just occuring on the actual server (which the sysadmins have restricted access to so that I can't run it as commandline there). There aren't any differences between the OS's, so I'm going to have to dig a little on it. Thanks...