Home  |  Linux  | Mysql  | PHP  | XML
From:Javier Terceiro Date:Wed Jun 11 07:26:58 2008
Subject:Memory usage
Hello list,

I am designed a new software. I am using threads. The operation is
correct, but memory consumption is excessive. The system is using 100
MB and when the software is working, 500 Mb. The memory is not
released, why?

The source code is:

-----------------------------------------------------------------------------

#!/usr/bin/perl -w

use strict;
use warnings;
use AnyData;
use Sys::Syslog;
use Sys::Syslog qw(:DEFAULT setlogsock);
use Sys::Syslog qw(:standard :macros);
use POSIX qw(setsid);
use threads;
use threads::shared;

sub mail
{
        print ("The mail thread\n");
        return 0;
}

sub mf
{
        print ("The mf thread\n");
        return 0;
}

sub scan_files
{
        while(1)
        {
                foreach (readdir(DIRHANDLE))
                {
                        if (!-d $_)
                        {
                                my $opt =
choose_file_option("workq/",$_,"Delivered");
                                switch ($opt)
                                {
                                        case "mail"
                                        {
                                                threads->new(\&mail, $_);
                                        }
                                        case "mf"
                                        {
                                                threads->new(\&mf, $_);
                                        }
                                        else
                                        {
                                                syslog ('daemon|info',
"Send mail. Failure detected");
                                        }
                                }
                        }
                }
                sleep(60);
        }
}

sub daemon
{
        chdir "/";
        open STDIN, '/dev/null';
        open STDOUT, '>/dev/null';
        open STDERR, '>/dev/null';
        fork && exit;
        setsid();
        if (open PID, '>', '/var/run/program.pid')
        {
                print PID "$$\n";
                close PID;
        }
}

setlogmask( LOG_MASK($Fax::Config::param{'log_info'}) );
openlog 'faxqr', 'pid', LOG_DAEMON;
daemon();

$SIG{"TERM"} = \&notify_exit;

scan_files();

-----------------------------------------------------------------------------

Any idea that there is a very high consumption of memory.

-- 
A greeting,

Javier.
Navigate in group perl.ithreads at sever nntp.perl.org
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants