Managing and measuring process footprint under Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I'm writing a simple daemon, and even in stripped down form (trivial app, no
functionality)
it is consuming 2.3Meg of memory (440K resident, rest virtual).

I'm fairly new to gcc, and I'm used to getting this kind of info out of a
linker:

     Code    RO Data    RW Data    ZI Data      Debug   Object Name
      2028          0          0          0       1036   opec_std.o
      1344         40          0        484        268   storage.obj
      5448          0          0       1076       1012   socket.obj
    ------------------------------------------------------------------------
     35332       2626        295      23152      13892   Object Totals
    ------------------------------------------------------------------------

But I have not been able to get anything similar out of ld, the map file
contains
a lot of info but the sizes aren't there, or I'm not understanding what is
there.

How do I find out what is eating up so much memory in a trivial app?

I have experimented with setrlimit without any success.

What do I need to do to get memory consumption to a reasonable level? I'm
working
on a simple fork/exec server, and the memory overhead is a bit of a problem
since
it takes only a few hundred processes to start locking up the whole swap
file unnecessarily.

I'm including the code of the test daemon and the makefile below.

Regards,
Nic

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

# --------------------------------------------
Test_Daemon: Test_Daemon.o 
	gcc -O3 -Wl,-Map=Test_Daemon.map -Wl,-s -Wl,-S -Wl,--cref -o
Test_Daemon Test_Daemon.o 

Test_Daemon.o: Test_Daemon.c
	gcc -O3 -c Test_Daemon.c 

# --------------------------------------------


#include <sys/types.h>
#include <signal.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/syslog.h>


//**************************************************************************
********
void cleanup ( void )
{
syslog(LOG_INFO,"Test daemon cleanup");
}
//**************************************************************************
********
void signalhd(int signal)
{
exit(-1);
}
//**************************************************************************
********
void SetLimits ( void )
{
struct rlimit Limit;

Limit.rlim_cur = 64 * 1024; 
Limit.rlim_max = 64 * 1024; 
setrlimit( RLIMIT_DATA , &Limit );

Limit.rlim_cur = 64 * 1024; 
Limit.rlim_max = 64 * 1024; 
setrlimit( RLIMIT_STACK , &Limit );
} 
//**************************************************************************
********
void deamonize ( void )
{
pid_t pid;
pid_t sid;

pid = fork();

if (pid < 0) 
	exit(-1);

if (pid > 0) 
	exit(0);

sid = setsid();

if (sid < 0)
	exit(-1);

close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
}
//**************************************************************************
********
int main(void)
{
fd_set Read_FDS;
fd_set Write_FDS;
fd_set Error_FDS;
struct timeval TimeOut;
int FD_Max;
int RetVal;

deamonize();

SetLimits();

signal (SIGINT,signalhd);
signal (SIGHUP,signalhd);
signal (SIGQUIT,signalhd);
signal (SIGTERM,signalhd);
signal (SIGABRT,signalhd);
signal (SIGCHLD, SIG_IGN);

atexit (cleanup);

syslog(LOG_INFO,"Test daemon startup");

for ( ;; ) 
	{
	FD_Max = 0;

	FD_ZERO ( &Read_FDS );
	FD_ZERO ( &Write_FDS );
	FD_ZERO ( &Error_FDS );

	// Setup fd_sets for listen socket etc....
	
	if ( ( TimeOut.tv_sec == 0 ) && ( TimeOut.tv_usec == 0 ) )
		{
		TimeOut.tv_sec = 5;
		TimeOut.tv_usec = 0;
		}

	RetVal = select( FD_Max+1 , &Read_FDS , &Write_FDS , &Error_FDS ,
&TimeOut );

	if ( ( RetVal == 0 ) && ( TimeOut.tv_sec == 0 ) && ( TimeOut.tv_usec
== 0 ) )
		{
		syslog(LOG_INFO,"Test daemon tick");
		continue;
		}

	// Check fd_sets for listen socket etc....
	}
}
//**************************************************************************
********


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux