#include #include #include #include #include #include #include #include #define PIDPATH "/tmp" #define NAME argv[0] #define TIMER 30 #define SIZE 10000 int timer = TIMER; int counter = 0; void thread42( int *thr ) { int i; void* allocs[SIZE]; while (1) { for ( i = 0; i < SIZE; i++ ) allocs[i] = malloc(1500); syslog( LOG_INFO, "%i: %ld\n", *thr, time(NULL) ); for ( i = 0; i < SIZE; i++ ) free(allocs[i]); } } void reset_timer( int sig ) { /* temporarily ingnore interrupts */ signal( sig, SIG_IGN ); counter++; syslog( LOG_INFO, "%i HUP received, resetting timer (was %i)...", counter, timer ); timer = TIMER; /* reenable interrupt */ a_signal( sig, reset_timer ); } int main( int argc, char **argv ) { int pid = daemonize( PIDPATH, NAME ); int thr1 = 1; int thr2 = 2; /* register sighup handler for daemon */ a_signal( SIGHUP, reset_timer ); /* start two malloc threads */ thread( "thread42-1", &thread42, &thr1 ); thread( "thread42-2", &thread42, &thr2 ); /* daemon stuff */ syslog( LOG_INFO, "Working hard..." ); while ( timer > 0 ) { sleep(1); timer--; if ( timer < 5 ) syslog( LOG_INFO, "Dying in %i...", timer + 1 ); } /* cleanup, if ever get here */ syslog( LOG_INFO, "Exiting %s (%i)...", a_daemon_name, pid ); unlink( a_daemon_pidfile ); exit(EXIT_SUCCESS); }