develooper Front page | perl.ithreads | Postings from June 2008

Memory usage

Thread Next
From:
Javier Terceiro
Date:
June 11, 2008 06:27
Subject:
Memory usage
Message ID:
602eb19e0806110626j8e4f7a4ted98b9f666a632fa@mail.gmail.com
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.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About