mq_notify usage
来源:互联网 发布:花王淘宝旗舰店真的吗 编辑:程序博客网 时间:2024/04/30 15:28
Forget where find the source code.
#include <pthread.h>
#include <mqueue.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#define handle_error(msg) /
do { perror(msg); exit(EXIT_FAILURE); } while (0)
static void /* Thread start function */
tfunc(union sigval sv)
{
struct mq_attr attr;
ssize_t nr;
void *buf;
mqd_t mqdes = *((mqd_t *) sv.sival_ptr);
/* Determine max. msg size; allocate buffer to receive msg */
if (mq_getattr(mqdes, &attr) == -1)
handle_error("mq_getattr");
buf = malloc(attr.mq_msgsize);
if (buf == NULL)
handle_error("malloc");
nr = mq_receive(mqdes, buf, attr.mq_msgsize, NULL);
if (nr == -1)
handle_error("mq_receive");
printf("Read %ld bytes from MQ/n", (long) nr);
free(buf);
exit(EXIT_SUCCESS); /* Terminate the process */
}
int
main(int argc, char *argv[])
{
mqd_t mqdes;
struct sigevent not;
//assert(argc == 2);
mqdes = mq_open("/yqueue",O_RDWR | O_EXCL, S_IRWXU | S_IRWXG, NULL);
if (mqdes == (mqd_t) -1)
handle_error("mq_open");
not.sigev_notify = SIGEV_THREAD;
not.sigev_notify_function = tfunc;
not.sigev_notify_attributes = NULL;
not.sigev_value.sival_ptr = &mqdes; /* Arg. to thread func. */
if (mq_notify(mqdes, ¬) == -1)
handle_error("mq_notify");
pause(); /* Process will be terminated by thread function */
}
- mq_notify usage
- usage
- Posix消息队列——mq_notify函数
- Posix消息队列——mq_notify函数
- Posix消息队列 异步通知 mq_notify函数
- WinDbg Usage
- cscope usage
- doxygen usage
- Maven Usage
- Vss usage
- CVS Usage
- NETLINK usage
- sdcard usage
- RMAN USAGE
- diff usage
- ifconfig usage
- Sendrecv Usage
- kthread usage
- CMM欺骗了中国的软件业
- 应用 Valgrind 发现 Linux 程序的内存问题
- spring加载多个配置文件
- DB2数据库命令简介
- 工信部部长李毅中:年底或明年初发放3G牌照
- mq_notify usage
- 关于正则表达式的递归匹配问题
- 利用NTP实现 系统的全网时钟同步
- 强大的SC工具
- 利用java实现一个简单的远程监控程序
- 管理 Active Directory 所需的工具或技术
- 也说Oracle High Water Mark
- Ubuntu Apache-PHP-MySQL Server
- 主题:MySQL数据库操作实战