1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <unistd.h>
#include <mqueue.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <stdlib.h>
int main(int argc, char ** argv){
int i=0;
mqd_t mq;
struct mq_attr attr;
struct mq_attr live_attr;
//struct sigaction sa;
attr.mq_maxmsg = 5;
attr.mq_msgsize = 30;
attr.mq_flags = 0;
attr.mq_curmsgs = 0;
char buff[100];
strcpy(buff, "TRANX");
int msgsize = 100;
if (mq = mq_open("/queue", O_CREAT | O_RDWR | O_EXCL, 0666, attr) == -1){
perror("Error : message queue ");
mq_unlink("/queue");
exit(1);
}
while(i!=10){
mq_send(mq, buff, msgsize, 1);
mq_getattr(mq, &attr);
printf("nbre msg : %d\n",attr.mq_curmsgs);
printf("max msg : %d\n",attr.mq_maxmsg);
printf("%d \n",i);
i++;
}
mq_unlink("/queue");
} |