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

I've been having this on-going debate with a friend who hosts a site for me. This site is centered on a single Perl script that relies heavily on CGI.pm and DBI::mysql. It is not running under mod_perl, as he hasn't figured out how to get it to work properly. He hosts a few sites on some uberhardware and can't get mod_perl to work.. its beyond me. ;-)

Anyway, back to the debate we've been having. About 70% of the time the script is launched, the process goes defunct and chews up a good bit of CPU for about a second. The script times itself with Time::HiRes, prints the time, disconnects from the DB, and exits immediately. It should be giving me a fairily accurate reading, but apparently the process doesn't actually exit. Instead, it hangs around and chews up cpu. I'm not liking this very much because I know the box admin doesn't like it either. He claims its my shoddy Perl programming (hah!) I keep telling him that it is his server configuration (RH 7.1, Apache) with the lack of mod_perl that is causing issues.

I posted something similar before and was told this was a kernel error, but the reply wasn't clear as to whether my script was at fault, or how it could be fixed.

Any insight at all would be appreciated. Thanks!

Replies are listed 'Best First'.
Re: Perl & CGI to cause Defunct?
by tstock (Curate) on Jan 02, 2002 at 08:33 UTC
    Any insight at all would be appreciated.
    - Regardless of the outcome, change hosting company, keep the friend.

    Really you don't give us much detail on the code that is causing this do you ?

    Tiago
      It seems the more lengthy the processing behind the code, the higher the chance of going defunct. My stuff runs in .2 seconds and defunts about 70% of the time. A "Hello, world" will defunct about 10% of the time. use CGI; also seems to add to the percentage, as well.
Re: Perl & CGI to cause Defunct?
by joealba (Hermit) on Jan 02, 2002 at 08:40 UTC
    What errors are getting sent to the Apache error log and to STDERR when the script pukes?

    Maybe you could put up some relevant code bits which you think might be causing the problem?

    Without either of these, we really can't help. You'll just have to pick one: 1 2
Re: Perl & CGI to cause Defunct?
by johanvdb (Beadle) on Jan 02, 2002 at 15:14 UTC
    Ahum, If you would be so kind to post the code fragment that looks like:
    while(1) { }
    Otherwise it will be difficult to help ..

    Seriously, can you give us some more details? Access and error log from apache, code snippets or the complete script?

    Johan
Re: Perl & CGI to cause Defunct?
by Stegalex (Chaplain) on Jan 02, 2002 at 22:46 UTC
    I had similar problems with Apache and Oracle 8i on Linux. What I experienced was that Oracle was mysteriously hanging onto open database cursors which would cause a process to chew up CPU time. Looks like it was a problem with my version of Oracle. At any rate, I had to resort to writing a script to wake up every few minutes and kill the offending process. Not an ideal solution, I know.

    To ensure that this is not happening to you, I advise to to close your database cursors, to undef them, and to do a disconnect at the end of processing just to reduce the chances that your code is causing the problem.

    However, the bigger issue is that your buddy really needs to get mod_perl working. If your friend is on RH7, he needs to make sure to install mod_perl version 1.2.4 or better (the one distributed with RH7 had problems).

    The benefit to installing mod_perl as I understand it is that it performs a task known as "connection pooling" for your database connections. Rather than actually connecting to the database when you say $dbh->connect(), mod_perl keeps a certain number of connections alive at all times so that you don't have to waste valuable time on the connect. You won't have to modify your code after mod_perl is in place, so go on, punch your buddy in the teeth and tell him to install mod_perl.

    and I like chicken.
Re: Perl & CGI to cause Defunct?
by santsu (Initiate) on Apr 01, 2002 at 01:03 UTC
    I am having a similar problem. It seems to have nothing to do with anything except perl itself, and farnkly it looks like a bug to me, or at least something that failed to reach the docs. The thing is that under certain conditions (perhaps something with while(1) ), scripts hang on ``, qx{} or open "command |". It doesn't matter which one i use, it always comes down to the same outcome: the child process finishes and goes defunct, and the calling script doesn't seem to notice that, it just keeps waiting for something... At the moment i have no idea why and how to fix this. The thing is, of course, that i want the child's output. I can do a simple workaround throwing the output into some file and sending a usr1 signal to the parent on exit, but that giving up isn't it...