/* Message Queues: server. */ #include #include #include #include #include #include #include #include "common.h" struct inf_msgbuf { long mtype; struct inf_t data; }; static int msg_id = 0; void free_msg( int i ) { msgctl(msg_id, IPC_RMID, NULL); _exit(-1); } int main( int argc, char* argv[] ) { struct inf_msgbuf msg; key_t key; time_t start = time(NULL); key = getuid() + 6662; massert((msg_id = msgget( key, 0600 | IPC_CREAT )) < 0, "msgget"); signal( SIGINT, free_msg ); set_id(&msg.data); msg.mtype = 1; while( 1 ) { update_inf( &msg.data, start ); if( msgsnd(msg_id, &msg, sizeof(struct inf_msgbuf), 0) < 0 ) perror("msgsnd"); sleep(1); } return 0; }