Forum Moderators: coopster & phranque

Message Too Old, No Replies

script making zombies and killing server

         

mikeseo

2:20 am on Feb 11, 2005 (gmt 0)

10+ Year Member



I am using a random text cgi script heavily on my webpages and it is creating zombie defunct processes, hundreds of them. They are lagging the server so bad I have to reboot. Is there a random script that can handle heavy usage and not create zombies? I think the zombies are happening when webpage is closed before script is done running?

moltar

2:29 am on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try exiting the script explicitly.

exit(0);

mikeseo

3:40 am on Feb 11, 2005 (gmt 0)

10+ Year Member



I replaced exit; with exit(0); but still got zombies. I read something about having to do double forking to avoid zombies?

mikeseo

4:03 am on Feb 11, 2005 (gmt 0)

10+ Year Member



found this code?

If you fork() without ever waiting on your children, you will accumulate zombies:

$SIG{CHLD} = sub { wait };

There's also the double-fork trick (error checking on fork() returns omitted);

unless ($pid = fork) {
unless (fork) {
exec "what you really wanna do";
die "no exec";
# ... or ...
## (some_perl_code_here)
exit 0;
}
exit 0;
}
waitpid($pid,0);

moltar

5:48 am on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



for random text you don't really need to fork anything. what is your exact setup? is the code long? can you post a sample?

mikeseo

6:02 am on Feb 11, 2005 (gmt 0)

10+ Year Member



#!/usr/bin/perl

######################################################################
# Necessary Variables: #
# The following variables should be set to define the locations #
# and URLs of various files, as explained in the documentation. #

#---Modification by Ron Perry aka ronzta
use CGI;
$cgi = new CGI;
my $RandomTextFile = $cgi->param('file');

#$RandomTextFile = "randomtext.txt";
# En: Path of Text file.
# Fr: Chemin du fichier de textes.
#----end of modified code------

$Delimiter = "\n--NEXT--\n*"; # En: Tags for Next Texte.
# Fr: Separateur de texte.

# Options:
$UseLog = 0; # Use Log File? 1 = YES; 0 = NO
$LogFile = "/Absolute/path/to/Random-Text-Log.txt";

# Nothing Below this line needs to be altered! #
######################################################################

srand(time);
open(LINKS,"$RandomTextFile") ¦¦ &Error("Cannot Open Links File : $RandomTextFile, Error $!\n");
@TextFile = <LINKS>;
close(LINKS);

$NbLines = @Text = split(/$Delimiter/, join('',@TextFile));
$Phrase = $Text[int rand $NbLines];

if ($UseLog) {
@date = localtime(time); $date[4]++; $date[5] += 1900;
$Time = "$date[4]/$date[3]/$date[5]";
open(LOG,">>$LogFile") ¦¦ &Error("Cannot Write Log File : $LogFile, Error $!\n");
print LOG "[$Time] - $ENV{'REMOTE_HOST'} -> $Url\n";
close(LOG);
}

print "Content-type: text/html\n\n";
print $Phrase."\n";

exit(0);
sub Error {
my($ErrorText) = @_;
print "Content-type: text/html\n\n";
print "Error: ".$ErrorText;
exit(0);
}

[edited by: jatar_k at 8:27 am (utc) on Feb. 11, 2005]
[edit reason] removed urls [/edit]

mikeseo

6:02 am on Feb 11, 2005 (gmt 0)

10+ Year Member



I am loading this 6 times per webpage and have a couple thousand webpages.

rocknbil

7:35 pm on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well I really don't have a clue, looks good from here, but if I were to debug I'd first revert to the hard-coded $RandomTextFile version you have commented out and see if it persists. If that doesn't work, turn the logging off, see if it persists. If THAT doesn't work, I'd eliminate the use CGI and put a small read/parse routine in it's place (You're only grabbing one key anyway.) It's not likely, but maybe it's the module that's causing the process.

Also srand doesn't really need a seed, but it shouldn't cause that either . . .

lexipixel

11:33 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month


If you are calling this CGI as an SSI from an HTML page, you can't pass a query to the script, ie-

This works:

<!--#exec cgi="/cgi-bin/randomx.cgi" -->

This doesn't:

<!--#exec cgi="/cgi-bin/randomx.cgi?file=abc.txt" -->

To use multiple input text files you'll need a script for each, hardcoded with the appropriate file name.

.

PhraSEOlogy

11:41 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



Just to add another angle on this problem.

I sometimes generate multiple templates of the same page with unique text on each copy. I then choose a random template for the page. You will need to read in the template (i/o overhead) but its better than getting zombies all over the place.

rocknbil

7:25 pm on Feb 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this doesn't

<!--#exec cgi="/cgi-bin/randomx.cgi?file=abc.txt" -->

lexipixel is that just on an exec? Because I have it working fine as an include

<!--#include virtual="cgi/ads.cgi?grp=2" -->

Of course, the script has to print out appropriate headers (or not) depending on how it's used.