Current location: Hot Scripts Forums » Programming Languages » Perl » Long Executed Perl Script not terminating till completion !


Long Executed Perl Script not terminating till completion !

Reply
  #1 (permalink)  
Old 08-01-05, 04:44 AM
learner learner is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down Long Executed Perl Script not terminating till completion !

Hello There:

Server / OS : Red Hat Linux 7.3

I have a system (lots of perl PODS with a main .pl script) that uses this concept from

www.stonehenge.com/merlyn/LinuxMag/col39.html

The long cgi script can take at least 15 hrs to complete. I start the script using the

exec "$command"

format from the browser using above url concept. However I have notice that the script started via exec does not at times complete to the end. I am not sure why the process eventually dies. Is this a buffering issue as explained from

perl.plover.com/FAQs/Buffering.html

If I start the script from a command line session (in the same way as I do it with exec). The script always runs to completion. I just let it run overnight leaving the telnet session.

I have also tried starting the script via a cron job as per I would from the command line and exec, and I also notice this problem that the script does not finish to completion.

Does anyone with experience with long executed script knows why this would happen ?

How can I debug something like this ?

I have logging on in a text file which uses hot filehandle concept as per buffering issue with perl when I use both
  1. exec "$command" from the browser script that activates it and regularly queries it, or;
  2. cron job perl execution.

However I am unable to know why the process has died without completion from the logs. I just know it did not finish as an email is sent at the end and from the logs I know this did not happen.

I appreciate any feedback on this issue.

Please help.

Thank You
Reply With Quote
  #2 (permalink)  
Old 08-02-05, 02:15 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
I would have thought that the browser timed it out but if it happens in a cron job I'm not sure. This is pretty tuff to troubleshoot unfortunately. Have you tried to detach the job from the shell (exec "$command &" )? That won't let you monitor it though.

~Charlie
Reply With Quote
  #3 (permalink)  
Old 08-02-05, 06:23 PM
learner learner is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Have you tried to detach the job from the shell (exec "$command &" )
No I have not. But I will try and see.

From a telnet session from the command line, if I do :

bash# $command

The script runs to completion and I get the prompt back at the end. One thing I have not tried from the command line is:

bash# $command &

So I will try your suggestion from the browser, and also the other way. But I really want the browser to start the long time script.

The time of execution is a factor in this I am sure. If I reduced the processing from the amount of data (which is looped) to a lesser number I do not experience this loss in PID of the perl script.

Does Perl have a time constraint for real lengthy script that can be changed ?

The issue may not even be related to Perl but may be the server is the issue.

I am just not sure on how to really study a PID and why it just detaches itself completely.
Reply With Quote
  #4 (permalink)  
Old 08-27-05, 04:49 AM
learner learner is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Question

Quote:
shell> $command &
I have tried this and the script actually does not release the shell and runs to completion as expected.

I have also ported the Perl system to another server RHE 4.0 on apache 2.0. I also experience this issue as well with the script stopping (thinking it has completed) without any errors.

I have checked /var/log, and grep for the PID with no luck on any error that may have occured.

Two different servers get same behaviour. This points that it is related to Perl but what

Is there anything in perl that will make it finish before reaching an exit command

Any Perl gurus please help

Thank You
Reply With Quote
  #5 (permalink)  
Old 08-27-05, 08:07 PM
learner learner is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy

Quote:
Two different servers get same behaviour. This points that it is related to Perl but what
I now suspect the issue is with Perl and the system. I can reproduce the issue as it appears to be happening and I will elaborate below. But I am unsure why it does this.

As I said before there are may POD(s) files, and a main file that has the necessary 'require' to call the necessary subroutines.

In the main file I call a sample subroutine from another POD as follows initially:

Quote:
etc...
&some_function();
etc ...
&somefunction depending on the no. of data I get it to process varies over time. &some_function calls other routines in it's PODs.

What I have noticed is that as I increase the no. of data to process, although "&some_function()" gets executed, once it completes to the end, Perl does not seem to know who the caller is anymore and stops there. Through adding debug statements I saw this.

I made changes as follows:

Quote:
sub some_function {

etc ...
etc ...

print "finished routine\n";
return "pass"; /* added this time to see if control goes back to caller */

}

Main routine POD

sub main {

my $result = &some_function(); /* added $result */
print "Control back to main\n";
&some_other_function();
etc ...
exit;

}
The print statement in &some_function(); gets executed but the print statement in &main is not executed as is everything else after (&some_other_function() etc ...)

As I said if I reduce the no. of data, the issue is not seen and Perl knows where to send control back. Why does this happen and how can I deal with this ?

I am no Perl guru but hopefully I have given enough information to get some help.

I will try few other things but anyone who has a clue please let me know .

Thank You
Reply With Quote
  #6 (permalink)  
Old 08-28-05, 02:57 AM
learner learner is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

I have been able to deal with the issue at hand from the main POD routine. Here is what I did in main:

Quote:
sub main {

etc ...
etc ...
my $pid;
if (defined($pid = fork)) {
if ($pid) { # parent
print "Parent: forked child ($pid) !\n";
wait;
print "Parent: Completed";
}
else { # child
$ result = &some_function();
print "Child: Completed";
exit;
}
}

}
This works without any issues even with large chunk of data that is processed by "&some_function()" .

I will test via cron as well and see how things goes.

All routine that takes time to execute I will fork in this manner
Reply With Quote
  #7 (permalink)  
Old 09-03-05, 07:52 PM
learner learner is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Angry To My Surprise - Why

While doing more testing on two server boxes, the problem is still there with the script process terminating for no reason over time on the red hat 7.3, apache 1.3 box.

The code fix I added below has fixed the issue on the red hat enterprise 4.0, apache 2.0 as the script always completes when started from either browser (using exec command line call), browser GET method (although apache timeouts on browser, but script continues) or command line.

Can anyone give me some input on this

Thank You.
Reply With Quote
  #8 (permalink)  
Old 09-04-05, 12:39 AM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Can you post the code (or a link to it) so that I can look at it? It really looks like a bug in the code. Make sure you are checking all of your open (and other) statements for success. I'm guessing that you have something like a failed open on a filehandle somewhere without a die "$!";.

~Charlie
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with my largest perl script. Grabbing data from a file. Sunnmann Perl 2 04-23-08 03:27 AM
converting perl script to php help!! macruddace Perl 1 04-14-05 02:38 PM
php executed in a perl script? -[OnTarget]- PHP 5 04-10-05 07:05 AM
need a systex to show first 50 words from a variable loeddie PHP 14 03-24-05 12:38 AM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM


All times are GMT -5. The time now is 04:04 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.