´ÙÀ½ À§·Î ÀÌÀü ¸ñÂ÷ ¸®´ª½º ÇÁ·Î±×·¡¸Ó¸¦ À§ÇÑ °¡À̵å

semstat:semtool µ¿·á ÇÁ·Î±×·¥ (A semtool companion program)

ºÎ¼öÀûÀÎ º¸³Ê½ºÃ³·³, semstat¶ó°í ºÒ¸®¿ì´Â µ¿·á ÇÁ·Î±×·¥ÀÇ ¼Ò½º°¡ ´ÙÀ½¿¡ Á¦°øµÈ´Ù. semstat ÇÁ·Î±×·¥Àº semtool¿¡ ÀÇÇØ ¸¸µé¾îÁø ÁýÇÕ¾ÈÀÇ °¢ ¼¼¸¶ÆÛÀÇ °ªÀ» Ç¥½ÃÇÑ´Ù.


/*****************************************************************************
 ¸®´ª½º ÇÁ·Î±×·¡¸Ó¸¦ À§ÇÑ °¡À̵å - 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);
}


ÀÌÀü:semtool:»óÈ£ÀÛ¿ë ¼¼¸¶ÆÛ Á¶Á¾ÀÚ ´ÙÀ½:6.4.4 °øÀ¯ ¸Þ¸ð¸® (Shared Memory)

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