Question

I have a perl file (test.pl).

It will work in recurring manner. The purpose of the file is send emails from DB

Following is the code in test.pl

sub send_mail{

$db->connect();

# Some DB operations #
# Send mail #

$db->disconnect();
sleep(5);

send_mail();

}

send_mail();

Iam executing 5 instance of this file ,like as below

perl test.pl  >> /var/www/html/emailerrorlog/error1.log 2>&1 &
perl test.pl  >> /var/www/html/emailerrorlog/error2.log 2>&1 &
perl test.pl  >> /var/www/html/emailerrorlog/error3.log 2>&1 &
perl test.pl  >> /var/www/html/emailerrorlog/error4.log 2>&1 &
perl test.pl  >> /var/www/html/emailerrorlog/error5.log 2>&1 &

if i execute the command ps -ef | grep perl | grep -v grep

I can see 5 instances of above mentioned perl file

That file will work perfectly for some days

But after some days, the perl processes will start to disappear one by one .

After some days all process will disappear. Now. if i execute the command ps -ef | grep perl | grep -v grep ,I can't see any process,

I can't see any error log in the log files.

So, what may be the chances for disappearing the perl processes?

How can i debugg it ?

Where can i see the perl error log?

It has the same issue in Centos and Red Hat Linux

Any one have idea?

Was it helpful?

Solution

I'm not 100% sure if that is the problem but it would probably help if you avoid recursion in a permanently executing process... That slowly increases the stack use and will eventually kill the process when the stack size limit is reached.

try something like this instead:

sub send_mail{

   $db->connect();

   # Some DB operations #
   # Send mail #

   $db->disconnect();

}

while (1) {
   send_mail();
   sleep(5);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top