::: 강좌/소스/문서 :::

강좌/소스/문서 성격에 맞지 않는 광고,비방,질문의 글은 즉시 삭제하며
내용을 복사하여 사용할 경우 반드시 이곳(http://www.howto.pe.kr)을 출처로 명시하여 주세요


Category

  김영대(2003-03-17 02:42:47, Hit : 5659, Vote : 1526
 [System V IPC] shmctl() function - 공유메모리

/***************************************************
*   Creat  : 2001. 02. 10  (programed by Cori-Young)
*   Site: http://www.byoneself.co.kr
*   Update :
***************************************************/

#include   <stdio.h>
#include   <sys/types.h>
#include   <sys/ipc.h>
#include   <sys/shm.h>
#include   <time.h>

static void   do_shmctl();
extern void   exit();
extern void   perror();

main()
{

        int  cmd;
        int  shmid;
        struct shmid_ds  shmid_ds;
        
        (void) fprintf(stderr, "All numeric input is expected to follow C conventions:n");
        (void) fprintf(stderr, "t0x... is interpreted as hexadecimal,n");
        (void) fprintf(stderr, "t0... is interpreted as octal,n");
        (void) fprintf(stderr, "totherwise, decimal.n");
        
        /* Get shmid and cmd. */
        (void) fprintf(stderr,"Enter the shmid for the desired segment: ");
        (void) scanf("%i", &shmid);
        
        (void) fprintf(stderr, "Valid shmctl cmd values are:n");
        (void) fprintf(stderr, "tIPC_RMID =t%dn", IPC_RMID);
        (void) fprintf(stderr, "tIPC_SET =t%dn", IPC_SET);
        (void) fprintf(stderr, "tIPC_STAT =t%dn", IPC_STAT);
        (void) fprintf(stderr, "tSHM_LOCK =t%dn", SHM_LOCK);
        (void) fprintf(stderr, "tSHM_UNLOCK =t%dn", SHM_UNLOCK);
        (void) fprintf(stderr, "Enter the desired cmd value: ");
        
        (void) scanf("%i", &cmd);
        
        
        switch (cmd) {

                case IPC_STAT:
                
                             /* Get shared memory segment status. */
                             break;

                case IPC_SET:
                
                             /* Set owner UID and GID and permissions. */
                             /* Get and print current values. */
                             do_shmctl(shmid, IPC_STAT, &shmid_ds);
                
                             /* Set UID, GID, and permissions to be loaded. */
                             (void) fprintf(stderr, "nEnter shm_perm.uid: ");
                             (void) scanf("%hi", &shmid_ds.shm_perm.uid);
                             (void) fprintf(stderr, "Enter shm_perm.gid: ");
                             (void) scanf("%hi", &shmid_ds.shm_perm.gid);
                             (void) fprintf(stderr,"Note: Keep read permission for yourself.n");
                             (void) fprintf(stderr, "Enter shm_perm.mode: ");
                             (void) scanf("%hi", &shmid_ds.shm_perm.mode);
                
                             break;
                
                case IPC_RMID:
                             /* Remove the segment when the last attach point is  detached. */
                             break;
                
                case SHM_LOCK:
                
                             /* Lock the shared memory segment. */
                
                             break;
                
                case SHM_UNLOCK:
                
                             /* Unlock the shared memory segment. */
                
                             break;
                
                default:
                
                             /* Unknown command will be passed to shmctl. */
                
                             break;
                
        }

             do_shmctl(shmid, cmd, &shmid_ds);

             exit(0);

}



static void do_shmctl(shmid, cmd, buf)
int shmid;
int cmd;
struct shmid_ds   *buf;   /* pointer to shared memory data structure */
{
        register int    rtrn;  /* hold area */

        (void) fprintf(stderr, "shmctl Calling shmctl(%d, %d,buf)n",shmid, cmd);

        if (cmd == IPC_SET) {
        
                      (void) fprintf(stderr, "tbuf->shm_perm.uid == %dn", buf->shm_perm.uid);
        
                     (void) fprintf(stderr, "tbuf->shm_perm.gid == %dn", buf->shm_perm.gid);
        
                     (void) fprintf(stderr, "tbuf->shm_perm.mode == %#on",buf->shm_perm.mode);
        
        }
        
        if ((rtrn = shmctl(shmid, cmd, buf)) == -1) {
        
                      perror("shmctl: shmctl failed");
        
                     exit(1);
        
        }
        
        else {
        
                       (void) fprintf(stderr, "shmctl: shmctl returned %dn", rtrn);
        
        }
        
        
        
        if (cmd != IPC_STAT && cmd != IPC_SET)
        
                      return;
        
        
        
        /* Print the current status. */
        
        (void) fprintf(stderr, "nCurrent status:n");
        (void) fprintf(stderr, "tshm_perm.uid = %dn",buf->shm_perm.uid);
        (void) fprintf(stderr, "tshm_perm.gid = %dn",buf->shm_perm.gid);
        (void) fprintf(stderr, "tshm_perm.cuid = %dn",buf->shm_perm.cuid);
        (void) fprintf(stderr, "tshm_perm.cgid = %dn", buf->shm_perm.cgid);
        (void) fprintf(stderr, "tshm_perm.mode = %#on", buf->shm_perm.mode);
        (void) fprintf(stderr, "tshm_perm.key = %#xn", buf->shm_perm.key);
        (void) fprintf(stderr, "tshm_segsz = %dn", buf->shm_segsz);
        (void) fprintf(stderr, "tshm_lpid = %dn", buf->shm_lpid);
        (void) fprintf(stderr, "tshm_cpid = %dn", buf->shm_cpid);
        (void) fprintf(stderr, "tshm_nattch = %dn", buf->shm_nattch);
        (void) fprintf(stderr, "tshm_atime = %s",buf->shm_atime ? ctime(&buf->shm_atime) : "Not Setn");
        (void) fprintf(stderr, "tshm_dtime = %s",buf->shm_dtime ? ctime(&buf->shm_dtime) : "Not Setn");
        (void) fprintf(stderr, "tshm_ctime = %s",ctime(&buf->shm_ctime));
        
}





62   [Unix/Linux] [강좌] 인텔 센트리노 무선랜 카드: ndiswrapper  김영대 2004/06/27 10841 1932
61   [Unix/Linux] [소스] top for System V Release 4, Intel or Sparc CPU  김영대 2004/02/20 6483 1121
60   [Unix/Linux] [소스] top for SunOS 5.x (Solaris 2.x)  김영대 2004/02/20 8737 1166
59   [Unix/Linux] [소스] String 해쉬(hash) 함수  김영대 2003/07/29 6203 1383
58   [Unix/Linux] [강좌] 웹로그분석을 위한 Webalizer + GDlib + PNGlib + Zlib 설치  김영대 2003/05/04 7027 1344
57   [Unix/Linux] [강좌] Apache + MySQL + PHP4 + Zend Optimizer 설치  김영대 2003/04/15 6083 1320
56   [Unix/Linux] [System V IPC] shmop() function - 공유메모리  김영대 2003/03/17 5640 1376
  [Unix/Linux] [System V IPC] shmctl() function - 공유메모리  김영대 2003/03/17 5659 1526
54   [Unix/Linux] [System V IPC] shmget() function - 공유메모리  김영대 2003/03/17 5997 1504
53   [Unix/Linux] [System V IPC] semop() function - 세마포어  김영대 2003/03/17 4873 1286
52   [Unix/Linux] [System V IPC] semctl() function - 세마포어  김영대 2003/03/17 4545 1253
51   [Unix/Linux] [System V IPC] semget() function - 세마포어  김영대 2003/03/17 5636 1508
50   [Unix/Linux] [System V IPC] msgget() function - 메세지큐  김영대 2003/03/17 5550 1423
49   [Unix/Linux] [System V IPC] msgctl() function - 메세지큐  김영대 2003/03/17 5636 1319
48   [Unix/Linux] [System V IPC] msgrcv() function - 메세지큐  김영대 2003/03/17 6052 1550
47   [Unix/Linux] [System V IPC] msgsnd() function - 메세지큐  김영대 2003/03/17 7395 1489
46   [Unix/Linux] [POSIX IPC] 생산자/소비자 - 세마포어  김영대 2003/03/17 7017 1452
45   [Unix/Linux] [POSIX IPC] mq_receive() function - 메세지큐  김영대 2003/03/17 6499 1589
44   [Unix/Linux] [POSIX IPC] mq_send() function - 메세지큐  김영대 2003/03/17 7626 1507
43   [Unix/Linux] [Thread] pthread_cond() function  김영대 2003/03/17 5783 1544

1 [2][3][4]
 

Copyright 1999-2017 Zeroboard / skin by zero