#include #include #include #include #include #include #include #include #include "nya/common.h" #define PATH "/tmp/tmp_191944_s9/a" static int shm_id = 0; void free_shmem( int i ) { shmctl( shm_id, IPC_RMID, NULL); fputs("Exit\n", stderr); _exit(1); } int main( int argc, char* argv[] ) { struct inf_t *data; time_t start; key_t key; int shmflg; size_t size = sizeof(struct inf_t); start = time(NULL); massert((key = ftok( PATH, 'a' )) < 0, "ftok" ); shmflg = 0600 | IPC_CREAT; massert( (shm_id = shmget(key, size, shmflg)) < 0, "shmget" ); signal( SIGINT, free_shmem ); data = (struct inf_t*)shmat( shm_id, NULL, 0 ); if( data == (struct inf_t*)(-1)) { perror("shmat"); shmctl( shm_id, IPC_RMID, NULL); exit(-1); } memset(data, 0, size); set_id(data); while( 1 ) { if( update_inf( data, start ) < 0 ) perror("getloadavg"); sleep(1); } return 0; }