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

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


Category

  김영대(2003-03-17 02:37:24, Hit : 5787, Vote : 1356
 [System V IPC] msgctl() 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/msg.h>
#include   <time.h>

static void do_msgctl();
extern void exit();
extern void perror();
static char warning_message[] = "If you remove read permissionfor  yourself, this program will fail frequently!";

main()
{
        struct msqid_ds buf;
        int    cmd;
        int    msqid;        
        
        (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 the msqid and cmd arguments for the msgctl() call. */
        
        (void) fprintf(stderr,  "Please enter arguments for msgctls() as requested.");        
        (void) fprintf(stderr, "nEnter the msqid: ");
        (void) scanf("%i", &msqid);
        (void) fprintf(stderr, "tIPC_RMID = %dn", IPC_RMID);
        (void) fprintf(stderr, "tIPC_SET = %dn", IPC_SET);
        (void) fprintf(stderr, "tIPC_STAT = %dn", IPC_STAT);
        (void) fprintf(stderr, "nEnter the value for the command: ");
        (void) scanf("%i", &cmd);
                
        switch (cmd) {

                case IPC_SET:
                        /* Modify settings in the message queue control structure.*/                        
                        /* Get a copy of the current message queue control structure and show it to the user. */        
                                
                        do_msgctl(msqid, IPC_STAT, &buf);
                                
                                
                                
                        (void) fprintf(stderr,  "msg_perm.uid = %dn", buf.msg_perm.uid);                        
                        (void) fprintf(stderr,  "msg_perm.gid = %dn", buf.msg_perm.gid);                                
                        (void) fprintf(stderr,  "msg_perm.cuid = %dn", buf.msg_perm.cuid);                                
                        (void) fprintf(stderr,  "msg_perm.cgid = %dn", buf.msg_perm.cgid);                        
                        (void) fprintf(stderr, "msg_perm.mode = %#o, ",      buf.msg_perm.mode);                                
                        (void) fprintf(stderr, "access permissions = %#on", buf.msg_perm.mode & 0777);                        
                        (void) fprintf(stderr, "msg_cbytes = %dn",       buf.msg_cbytes);                                
                        (void) fprintf(stderr, "msg_qbytes = %dn",       buf.msg_qbytes);                                
                        (void) fprintf(stderr, "msg_qnum = %dn", buf.msg_qnum);                                
                        (void) fprintf(stderr, "msg_lspid = %dn",       buf.msg_lspid);                                
                        (void) fprintf(stderr, "msg_lrpid = %dn",       buf.msg_lrpid);                                
                        (void) fprintf(stderr, "msg_stime = %s", buf.msg_stime ? ctime(&buf.msg_stime) : "Not Setn");                                
                        (void) fprintf(stderr, "msg_rtime = %s", buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not Setn");                                
                        (void) fprintf(stderr, "msg_ctime = %s",       ctime(&buf.msg_ctime));
                
                        if (cmd == IPC_STAT)
                                break;
                                
                        /*  Now continue with IPC_SET. */                                                                       
                        (void) fprintf(stderr, "Enter msg_perm.uid: ");
                        (void) scanf ("%hi", &buf.msg_perm.uid);
                        (void) fprintf(stderr, "Enter msg_perm.gid: ");
                        (void) scanf("%hi", &buf.msg_perm.gid);
                        (void) fprintf(stderr, "%sn", warning_message);
                        (void) fprintf(stderr, "Enter msg_perm.mode: ");
                        (void) scanf("%hi", &buf.msg_perm.mode);
                        (void) fprintf(stderr, "Enter msg_qbytes: ");
                                
                        (void) scanf("%hi", &buf.msg_qbytes);
                                
                        do_msgctl(msqid, IPC_SET, &buf);
                        break;
                        
                case IPC_RMID:
                default:
                        do_msgctl(msqid, cmd, (struct msqid_ds *)NULL);
                        break;
        }
        exit(0);
}



static void do_msgctl(msqid, cmd, buf)
struct msqid_ds    *buf;
int    cmd, msqid;
{

        register int rtrn;
        (void) fprintf(stderr, "nmsgctl: Calling msgctl(%d, %d,%s)n",  msqid, cmd, buf ? "&buf" : "(struct msqid_ds *)NULL");
        
        rtrn = msgctl(msqid, cmd, buf);

        if (rtrn == -1) {
                perror("msgctl: msgctl failed");
                exit(1);
        }
        else {
                (void) fprintf(stderr, "msgctl: msgctl returned %dn",      rtrn);
        }
}





62   [Unix/Linux] [강좌] 인텔 센트리노 무선랜 카드: ndiswrapper  김영대 2004/06/27 11040 1991
61   [Unix/Linux] [소스] top for System V Release 4, Intel or Sparc CPU  김영대 2004/02/20 7269 1174
60   [Unix/Linux] [소스] top for SunOS 5.x (Solaris 2.x)  김영대 2004/02/20 8953 1210
59   [Unix/Linux] [소스] String 해쉬(hash) 함수  김영대 2003/07/29 6365 1428
58   [Unix/Linux] [강좌] 웹로그분석을 위한 Webalizer + GDlib + PNGlib + Zlib 설치  김영대 2003/05/04 7192 1391
57   [Unix/Linux] [강좌] Apache + MySQL + PHP4 + Zend Optimizer 설치  김영대 2003/04/15 6239 1361
56   [Unix/Linux] [System V IPC] shmop() function - 공유메모리  김영대 2003/03/17 5807 1432
55   [Unix/Linux] [System V IPC] shmctl() function - 공유메모리  김영대 2003/03/17 5805 1563
54   [Unix/Linux] [System V IPC] shmget() function - 공유메모리  김영대 2003/03/17 9759 1549
53   [Unix/Linux] [System V IPC] semop() function - 세마포어  김영대 2003/03/17 5014 1322
52   [Unix/Linux] [System V IPC] semctl() function - 세마포어  김영대 2003/03/17 4712 1289
51   [Unix/Linux] [System V IPC] semget() function - 세마포어  김영대 2003/03/17 5780 1541
50   [Unix/Linux] [System V IPC] msgget() function - 메세지큐  김영대 2003/03/17 5693 1465
  [Unix/Linux] [System V IPC] msgctl() function - 메세지큐  김영대 2003/03/17 5787 1356
48   [Unix/Linux] [System V IPC] msgrcv() function - 메세지큐  김영대 2003/03/17 6214 1597
47   [Unix/Linux] [System V IPC] msgsnd() function - 메세지큐  김영대 2003/03/17 7529 1522
46   [Unix/Linux] [POSIX IPC] 생산자/소비자 - 세마포어  김영대 2003/03/17 7161 1497
45   [Unix/Linux] [POSIX IPC] mq_receive() function - 메세지큐  김영대 2003/03/17 6657 1629
44   [Unix/Linux] [POSIX IPC] mq_send() function - 메세지큐  김영대 2003/03/17 7801 1550
43   [Unix/Linux] [Thread] pthread_cond() function  김영대 2003/03/17 5928 1582

1 [2][3][4]
 

Copyright 1999-2018 Zeroboard / skin by zero