/***************************************************************************** ¸®´ª½º ÇÁ·Î±×·¡¸Ó¸¦ À§ÇÑ °¡À̵å - 6Àå ¿¡¼ ¹ßÃé (C)opyright 1994-1995, Scott Burkett ***************************************************************************** MODULE: semstat.c ***************************************************************************** semtool ÆÐÅ°Áö¸¦ À§ÇÑ µ¿·á ¸í·É¾î ¶óÀÎ Åø. semstat´Â semtool¿¡ ÀÇÇØ ¸¸µé¾îÁø ÁýÇÕ³»ÀÇ °¢ ¼¼¸¶ÆÛÀÇ ÇöÀç °ªÀ» Ç¥½ÃÇÑ´Ù. *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> int get_sem_count(int sid); void show_sem_usage(int sid); int get_sem_count(int sid); void dispval(int sid); int main(int argc, char *argv[]) { key_t key; int semset_id; /* ftok() È£ÃâÀ» °æÀ¯ÇÏ¿© À¯ÀÏÇÑ Å°¸¦ ¸¸µç´Ù. */ key = ftok(".", 's'); /* ¼¼¸¶ÆÛ ÁýÇÕÀ» ¿¬´Ù - ¸¸µå´Â °ÍÀÌ ¾Æ´Ï´Ù! */ if((semset_id = semget(key, 1, 0666)) == -1) { printf("Semaphore set does not exist\n"); exit(1); } show_sem_usage(semset_id); return(0); } void show_sem_usage(int sid) { int cntr=0, maxsems, semval; maxsems = get_sem_count(sid); while(cntr < maxsems) { semval = semctl(sid, cntr, GETVAL, 0); printf("Semaphore #%d: --> %d\n", cntr, semval); cntr++; } } int get_sem_count(int sid) { int rc; struct semid_ds mysemds; union semun semopts; /* ³»ºÎ ÀÚ·á ±¸Á¶ÀÇ ÇöÀç °ªÀ» ¾ò´Â´Ù */ semopts.buf = &mysemds; if((rc = semctl(sid, 0, IPC_STAT, semopts)) == -1) { perror("semctl"); exit(1); } /* ÁýÇÕ¾ÈÀÇ ¼¼¸¶ÆÛÀÇ ¹øÈ£¸¦ ¹ÝȯÇÑ´Ù */ return(semopts.buf->sem_nsems); } void dispval(int sid) { int semval; semval = semctl(sid, 0, GETVAL, 0); printf("semval is %d\n", semval); }
Copyright (c) 1996,1997 by Euibeom.Hwang & SangEun.Oh All Rights Reserved
Email To:Webmaster ,
Another address
LAST UPDATE Nov 26,1997
Created Nov 26,1997