mq_notify(3) Library Functions Manual mq_notify(3) mq_notify - LIBRARY Real-time library (librt, -lrt) #include #include /* Definition of SIGEV_* constants */ int mq_notify(mqd_t mqdes, const struct sigevent *sevp); mq_notify() , mqdes. The sevp argument is a pointer to a sigevent structure. For the definition and general details of this structure, see sigevent(3type). sevp null, mq_notify() . sigev_notify sigevent, sevp, . : SIGEV_NONE <<>> : , . SIGEV_SIGNAL Notify the process by sending the signal specified in sigev_signo. See sigevent(3type) for general details. The si_code field of the siginfo_t structure will be set to SI_MESGQ. In addition, si_pid will be set to the PID of the process that sent the message, and si_uid will be set to the real user ID of the sending process. SIGEV_THREAD Upon message delivery, invoke sigev_notify_function as if it were the start function of a new thread. See sigevent(3type) for details. , . sevp NULL , ; . . 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 NULL, mqdes. attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |mq_notify() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ C glibc mq_notify() . sevp NULL SIGEV_THREAD, . SIGEV_THREAD , ( - , , , C POSIX). netlink(7) , . POSIX.1-2008. POSIX.1-2001. , . . , . #include #include #include #include #include #include #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 %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) handle_error("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) handle_error("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) aereiae , Alexey , Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , ITriskTI , Max Is , Yuri Kozlov , ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . mq_notify(3)