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

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


Category

  김영대(2003-03-17 02:29:11, Hit : 8504, Vote : 1588
 [POSIX IPC] mq_send() function - 메세지큐

/***************************************************
*--------------------------------------------------
*   posix ipc message queue를 사용한다.
*--------------------------------------------------
*   Creat  : 2001. 02. 10  (programed by Cori-Young )
*   Site: http://www.byoneself.co.kr
*   Update :
*--------------------------------------------------
*   Compile : cc -o send send.c -lrt
*--------------------------------------------------
* Machine hardware:   sun4u
* OS version:         5.7
* Processor type:     sparc
* Hardware:           SUNW,Ultra-60
***************************************************/

#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <time.h>
#include <sched.h>
#include <sys/mman.h>
#include <sys/fcntl.h>
#include <signal.h>
#include <mqueue.h>
#include <errno.h>

#define PMODE 0666

extern int errno;
const char *myname = "/qid";
mqd_t mqfd;

void signalCatcher(int sig);

int main()
{
        int i;
        int status = 0;
        
        char msg_buffer[256];
        struct mq_attr attr;
        int open_flags = 0;
        int priority_of_msg;
        int count=1;
                
        (void)signal(SIGPIPE, signalCatcher);
        (void)signal(SIGINT, signalCatcher);
        
        printf("START OF TEST_SEND n");
                
        attr.mq_maxmsg = 20;
        attr.mq_msgsize = sizeof(msg_buffer);;
        attr.mq_flags   = 0;
        
        open_flags = O_WRONLY|O_CREAT;
        
        mqfd = mq_open(myname,open_flags,PMODE,&attr);
        if (mqfd == -1)
        {
                    perror("mq_open failure from main,");
                    exit(0);
        };
        
        priority_of_msg = 1;
        
        while(1)
        {
                memset(msg_buffer, 0x00, sizeof(msg_buffer));
                sprintf(msg_buffer, "%s:%d", "posix message queue test : ", count);
                
                status = mq_send(mqfd, msg_buffer, sizeof(msg_buffer), priority_of_msg);
                    if (status == -1)
                        perror("mq_send failure on mqfd");
                    else
                        printf("successful mq_send, count = %dn",count);
              count++;
                sleep(1);
        }
                
}

void signalCatcher(int sig)
{
        if (mq_close(mqfd) == -1)
                perror("mq_close failure on mqfd");
        
        printf("n===>signal catch end program <===n");
        sleep(1);
        
        exit(1);        
}





62   [Unix/Linux] [강좌] 인텔 센트리노 무선랜 카드: ndiswrapper  김영대 2004/06/27 11299 2022
61   [Unix/Linux] [Thread] pthread_cond_timedwait() function  김영대 2003/03/17 5953 1770
60   [Unix/Linux] [Thread] pthread_setschedparam() function  김영대 2003/03/17 9793 1693
59   [Unix/Linux] [Thread] pthread_cancel() function  김영대 2003/03/17 5880 1684
58   [Unix/Linux] [System V IPC] shmget() function - 공유메모리  김영대 2003/03/17 9888 1676
57   [Unix/Linux] [POSIX IPC] mq_receive() function - 메세지큐  김영대 2003/03/17 6907 1669
56   [Unix/Linux] [System V IPC] msgrcv() function - 메세지큐  김영대 2003/03/17 6319 1624
55   [Unix/Linux] [Thread] pthread_cond() function  김영대 2003/03/17 6034 1607
54   [Unix/Linux] [System V IPC] shmctl() function - 공유메모리  김영대 2003/03/17 7649 1606
  [Unix/Linux] [POSIX IPC] mq_send() function - 메세지큐  김영대 2003/03/17 8504 1588
52   [Unix/Linux] [Thread] pthread_mutexattr_init() function  김영대 2003/03/17 5745 1570
51   [Unix/Linux] [System V IPC] semget() function - 세마포어  김영대 2003/03/17 5888 1569
50   [Unix/Linux] [Thread] pthread_attr_getinheritsched() function  김영대 2003/03/17 4979 1551
49   [Unix/Linux] [System V IPC] msgsnd() function - 메세지큐  김영대 2003/03/17 7634 1549
48   [Unix/Linux] [POSIX IPC] 생산자/소비자 - 세마포어  김영대 2003/03/17 7290 1534
47   [Unix/Linux] [Thread] pthread_once() function  김영대 2003/03/17 5606 1529
46   [Unix/Linux] [Thread] pthread_attr_setdetachstate() function  김영대 2003/03/17 5315 1524
45   [Unix/Linux] [Thread] pthread_cond_init() function  김영대 2003/03/17 5462 1505
44   [Unix/Linux] [Thread] pthread_attr_destroy() function  김영대 2003/03/17 5443 1492
43   [Unix/Linux] [System V IPC] msgget() function - 메세지큐  김영대 2003/03/17 5795 1489

1 [2][3][4]
 

Copyright 1999-2019 Zeroboard / skin by zero