/* * shmstat.c * Gets statistics for a shared memory segment. */ #include #include #include #include #include #include #include #include int main(int argc, char **argv) { key_t key; int shm; struct shmid_ds shmstat; if((key=ftok("sharedmem",'a'))==-1) { fprintf(stdout,"failed to get key for shared memory segment %d, %s\n",errno,strerror(errno)); fflush(stdout); return -1; } if((shm=shmget(key,0, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | IPC_CREAT))==-1) { fprintf(stdout,"failed to allocate shared memory segment %d, %s\n",errno,strerror(errno)); fflush(stdout); return -1; } if(shmctl(shm,IPC_STAT,&shmstat)==-1) { fprintf(stdout,"failed to destroy shared memory segment %d, %s\n",errno,strerror(errno)); fflush(stdout); return -1; } fprintf(stdout,"shared memory segment stats:\n\tsize: %10d\n\tattached: %s\tdetached: %s\tchanged: %s\t#attached: %10d\n", shmstat.shm_segsz,ctime(&shmstat.shm_atime),ctime(&shmstat.shm_dtime),ctime(&shmstat.shm_ctime),(int)shmstat.shm_nattch); return 0; }