mq_notify(3) Library Functions Manual mq_notify(3) mq_notify - (librt -lrt) #include #include /* Definition of SIGEV_* constants */ int mq_notify(mqd_t mqdes, const struct sigevent *sevp); mq_notify() mqdes. sevp sigevent. sigevent(3type). sevp mq_notify() . sigev_notify sigevent sevp . : SIGEV_NONE "": . SIGEV_SIGNAL sigev_signo. sigevent(3type) . si_code siginfo_t SI_MESGQ. si_pid PID si_uid . SIGEV_THREAD sigev_notify_function . sigevent(3type) . . sevp . . mq_notify() . mq_receive(3) : mq_receive(3) . : . mq_notify() . . ( .) mq_notify() 0 -1 errno . EBADF mqdes . EBUSY . EINVAL sevp->sigev_notify sevp->sigev_notify SIGEV_SIGNAL sevp->sigev_signo . ENOMEM . POSIX.1-2008 EINVAL sevp mqdes. attributes(7). +------------+------------------------------------+--------------------+ || | | +------------+------------------------------------+--------------------+ |mq_notify() | | MT-Safe | +------------+------------------------------------+--------------------+ C glibc mq_notify() . sevp SIGEV_THREAD . SIGEV_THREAD . ( POSIX C.) netlink(7) . POSIX.1-2008. POSIX.1-2001. . . . #include #include #include #include #include #include #include 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) err(EXIT_FAILURE, "mq_getattr"); buf = malloc(attr.mq_msgsize); if (buf == NULL) err(EXIT_FAILURE, "malloc"); nr = mq_receive(mqdes, buf, attr.mq_msgsize, NULL); if (nr == -1) err(EXIT_FAILURE, "mq_receive"); printf("Read %zd bytes from MQ\n", nr); free(buf); exit(EXIT_SUCCESS); /* Terminate the process */ } int main(int argc, char *argv[]) { mqd_t mqdes; struct sigevent sev; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } mqdes = mq_open(argv[1], O_RDONLY); if (mqdes == (mqd_t) -1) err(EXIT_FAILURE, "mq_open"); sev.sigev_notify = SIGEV_THREAD; sev.sigev_notify_function = tfunc; sev.sigev_notify_attributes = NULL; sev.sigev_value.sival_ptr = &mqdes; /* Arg. to thread func. */ if (mq_notify(mqdes, &sev) == -1) err(EXIT_FAILURE, "mq_notify"); pause(); /* Process will be terminated by thread function */ } mq_close(3), mq_getattr(3), mq_open(3), mq_receive(3), mq_send(3), mq_unlink(3), mq_overview(7), sigevent(3type) 3 . . : . 6.18 8 2026 mq_notify(3)