OSDN Git Service

(split) Fixed #25191 (typo in fenv.3).
[linuxjm/LDP_man-pages.git] / release / man3 / mq_notify.3
1 '\" t
2 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\"
4 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
27 .\" Translated 2006-07-31, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
28 .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24
29 .\" Updated 2010-10-27, Akihiro Motoki, LDP v3.29
30 .\"
31 .TH MQ_NOTIFY 3 2010-10-04 "Linux" "Linux Programmer's Manual"
32 .SH Ì¾Á°
33 mq_notify \- ¥á¥Ã¥»¡¼¥¸ÅþÃå»þ¤ËÄÌÃΤò¹Ô¤¦¤è¤¦ÅÐÏ¿¤¹¤ë
34 .SH ½ñ¼°
35 .nf
36 .B #include <mqueue.h>
37 .sp
38 .BI "int mq_notify(mqd_t " mqdes ", const struct sigevent *" notification );
39 .fi
40 .sp
41 \fI\-lrt\fP ¤Ç¥ê¥ó¥¯¤¹¤ë¡£
42 .SH ÀâÌÀ
43 .BR mq_notify ()
44 ¤ò»È¤¦¤È¡¢¥Ç¥£¥¹¥¯¥ê¥×¥¿
45 .I mqdes
46 ¤Ç»²¾È¤µ¤ì¤ë¶õ¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤Ë¿·¤·¤¯¥á¥Ã¥»¡¼¥¸¤¬ÅþÃ夷¤¿»þ¤Ë
47 ÈóƱ´ü¤ÎÄÌÃΠ(notification) ¤ÎÇÛÁ÷¤¬¹Ô¤ï¤ì¤ë¤è¤¦¤ËÅÐÏ¿¤·¤¿¤ê¡¢
48 ¤½¤Î²ò½ü¤ò¹Ô¤Ã¤¿¤ê¤Ç¤­¤ë¡£
49
50 .I sevp
51 °ú¤­¿ô¤Ï
52 .I sigevent
53 ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
54 ¤³¤Î¹½Â¤ÂΤÎÄêµÁ¤È°ìÈÌŪ¤Ê¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï
55 .BR sigevent (7)
56 ¤ò»²¾È¡£
57 .PP
58 .I sevp
59 ¤¬ NULL ¤Ç¤Ê¤¤¥Ý¥¤¥ó¥¿¤Ç¤¢¤ì¤Ð¡¢
60 .BR mq_notify ()
61 ¤Ï¥á¥Ã¥»¡¼¥¸ÄÌÃΤò¼õ¤±¼è¤ë¤è¤¦¤Ë¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤òÅÐÏ¿¤¹¤ë¡£
62 .I sevp
63 ¤¬»Ø¤¹
64 .I sigevent
65 ¹½Â¤ÂΤÎ
66 .I sigev_notify
67 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¤É¤Î¤è¤¦¤ÊÄÌÃΤò¹Ô¤¦¤Î¤«¤ò»ØÄꤹ¤ë¡£
68 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ï°Ê²¼¤ÎÃͤΤ¤¤º¤ì¤«¤ò»ý¤Ä¡£
69 .TP
70 .B SIGEV_NONE
71 ¡Ö¶õ¤Î (null)¡×¤ÎÄÌÃÎ: ¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤òÄÌÃΤΰ¸Àè¤È¤·¤ÆÅÐÏ¿¤¹¤ë¤¬¡¢
72 ¼ÂºÝ¤Ë¤Ï¥á¥Ã¥»¡¼¥¸¤¬ÅþÃ夷¤¿»þ¤ËÄÌÃΤÏÁ÷¤é¤ì¤Ê¤¤¡£
73 .\" When is SIGEV_NONE useful?
74 .TP
75 .B SIGEV_SIGNAL
76 .I sigev_signo
77 ¤Ç»ØÄꤵ¤ì¤¿¥·¥°¥Ê¥ë¤òÁ÷¤Ã¤Æ¡¢¥×¥í¥»¥¹¤ËÄÌÃΤ¹¤ë¡£
78 °ìÈÌŪ¤Ê¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï
79 .BR sigevent (7)
80 ¤ò»²¾È¡£
81 .I siginfo_t
82 ¹½Â¤ÂΤÎ
83 .I si_code
84 ¥Õ¥£¡¼¥ë¥É¤Ë¤Ï
85 .B SI_MESGQ
86 ¤¬ÀßÄꤵ¤ì¤ë¡£
87 .\" I don't know of other implementations that set
88 .\" si_pid and si_uid -- MTK
89 ¤µ¤é¤Ë¡¢
90 .I si_pid
91 ¤Ë¤Ï¥á¥Ã¥»¡¼¥¸¤òÁ÷¿®¤·¤¿¥×¥í¥»¥¹¤Î PID ¤¬¡¢
92 .I si_uid
93 ¤Ë¤ÏÁ÷¿®¥×¥í¥»¥¹¤Î¼Â¥æ¡¼¥¶ ID ¤¬ÀßÄꤵ¤ì¤ë¡£
94 .TP
95 .B SIGEV_THREAD
96 ¥á¥Ã¥»¡¼¥¸¤ÎÇÛÁ÷»þ¤Ë¤Ï¡¢
97 .I sigev_notify_function
98 ¤¬¤¢¤¿¤«¤â¿·¤·¤¤¥¹¥ì¥Ã¥É¤Î³«»Ï´Ø¿ô¤Ç¤¢¤ë¤«¤Î¤è¤¦¤Ëµ¯Æ°¤µ¤ì¤ë¡£
99 ¾ÜºÙ¤Ï
100 .BR sigevent (7)
101 ¤ò»²¾È¡£
102 .PP
103 °ì¤Ä¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤«¤éÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤ËÅÐÏ¿¤Ç¤­¤ë¥×¥í¥»¥¹¤Ï
104 °ì¤Ä¤À¤±¤Ç¤¢¤ë¡£
105
106 .I sevp
107 ¤¬ NULL ¤Ç¡¢¤«¤Ä¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤¬¤³¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤«¤é¤Î
108 ÄÌÃΤò¼õ¿®¤¹¤ë¤Ë¸½ºßÅÐÏ¿¤·¤Æ¤¤¤ë¾ì¹ç¡¢ÅÐÏ¿¤òºï½ü¤¹¤ë¡£
109 ¤³¤ì°Ê¹ß¡¢ÊÌ¤Î¥×¥í¥»¥¹¤¬¤³¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤«¤éÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤Ë
110 ÅÐÏ¿¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ë¡£
111
112 ¥á¥Ã¥»¡¼¥¸ÄÌÃΤϡ¢¤½¤ì¤Þ¤Ç¶õ¤Î¥­¥å¡¼¤Ë¿·¤·¤¤¥á¥Ã¥»¡¼¥¸¤¬ÅþÃ夷¤¿
113 ¾ì¹ç¤Ë¤Î¤ß¹Ô¤ï¤ì¤ë¡£
114 .BR mq_notify ()
115 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿»þ¤Ë¤½¤Î¥­¥å¡¼¤¬¶õ¤Ç¤Ê¤¤¾ì¹ç¡¢
116 ¤½¤Î¥­¥å¡¼¤¬¶õ¤Ë¤Ê¤ê¡¢¤½¤Î¸å¿·¤·¤¤¥á¥Ã¥»¡¼¥¸¤¬ÅþÃ夷¤¿»þ¤Ë
117 ½é¤á¤ÆÄÌÃΤ¬¹Ô¤ï¤ì¤ë¤³¤È¤Ë¤Ê¤ë¡£
118
119 ÊÌ¤Î¥×¥í¥»¥¹¤ä¥¹¥ì¥Ã¥É¤¬
120 .BR mq_receive (3)
121 ¤ò»È¤Ã¤Æ¡¢¶õ¤Î¥­¥å¡¼¤«¤é¥á¥Ã¥»¡¼¥¸¤ÎÆɤ߽Ф·¤òÂԤäƤ¤¤ë¾ì¹ç¡¢
122 ¥á¥Ã¥»¡¼¥¸ÄÌÃΤÎÅÐÏ¿¤ÏÁ´¤Æ̵»ë¤µ¤ì¤ë¡£
123 ¥á¥Ã¥»¡¼¥¸¤Ï
124 .BR mq_receive (3)
125 ¤ò¸Æ¤Ó½Ð¤·¤Æ¤¤¤ë¥×¥í¥»¥¹¤ä¥¹¥ì¥Ã¥É¤ËÇÛÁ÷¤µ¤ì¡¢
126 ¥á¥Ã¥»¡¼¥¸ÄÌÃΤÎÅÐÏ¿¤Ï¸úÎϤò»ý¤Ã¤¿¤Þ¤Þ¤È¤Ê¤ë¡£
127
128 ÄÌÃΤϰìÅÙ¤À¤±¹Ô¤ï¤ì¤ë¡£ÄÌÃΤ¬Á÷¤é¤ì¤¿¸å¤Ï¡¢ÄÌÃÎÍ×µá¤ÎÅÐÏ¿¤Ïºï½ü¤µ¤ì¡¢
129 ÊÌ¤Î¥×¥í¥»¥¹¤¬¥á¥Ã¥»¡¼¥¸ÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤ËÅÐÏ¿¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ë¡£
130 ÄÌÃΤò¼õ¤±¤¿¥×¥í¥»¥¹¤¬¼¡¤ÎÄÌÃΤâ¼õ¿®¤·¤¿¤¤¾ì¹ç¤Ï¡¢
131 .BR mq_notify ()
132 ¤ò»È¤Ã¤Æ¤½¤Î¸å¤ÎÄÌÃΤâ¼õ¤±¤ë¤è¤¦¤ËÍ׵᤹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
133 .BR mq_notify ()
134 ¤òºÆÅٸƤӽФ¹¤Î¤Ï¡¢Æɤ߽Ф·¤Æ¤¤¤Ê¤¤¥á¥Ã¥»¡¼¥¸¤òÁ´ÉôÆɤ߽Ф·¤Æ
135 ¥­¥å¡¼¤¬¶õ¤Ë¤Ê¤ëÁ°¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë
136 (¥­¥å¡¼¤«¤é¤Î¥á¥Ã¥»¡¼¥¸Æɤ߽Ф·¤ò¥­¥å¡¼¤¬¶õ¤Ë¤Ê¤Ã¤¿»þ¤Ë
137 Ää»ß (block) ¤»¤º¤Ë¹Ô¤¦¤Ë¤Ï¡¢¥­¥å¡¼¤òÈóÄä»ß¥â¡¼¥É (non-blocking mode)
138 ¤ËÀßÄꤷ¤Æ¤ª¤¯¤È¤è¤¤)¡£
139 .SH ÊÖ¤êÃÍ
140 À®¸ù¤¹¤ë¤È¡¢
141 .BR mq_notify ()
142 ¤Ï 0 ¤òÊÖ¤¹¡£¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
143 .I errno
144 ¤ò¥¨¥é¡¼¤ò¼¨¤¹ÃͤËÀßÄꤹ¤ë¡£
145 .SH ¥¨¥é¡¼
146 .TP
147 .B EBADF
148 .I mqdes
149 ¤Ë»ØÄꤵ¤ì¤¿¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬ÉÔÀµ¤Ç¤¢¤ë¡£
150 .TP
151 .B EBUSY
152 ÊÌ¤Î¥×¥í¥»¥¹¤¬¤¹¤Ç¤Ë
153 ¤³¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤ËÂФ¹¤ëÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤ËÅÐÏ¿¤·¤Æ¤¤¤ë¡£
154 .TP
155 .B EINVAL
156 .I sevp\->sigev_notify
157 ¤¬µö²Ä¤µ¤ì¤¿ÃͤΤ¤¤º¤ì¤Ç¤â¤Ê¤¤¡£¤â¤·¤¯¤Ï
158 .I sevp\->sigev_notify
159 ¤¬
160 .B SIGEV_SIGNAL
161 ¤À¤¬
162 .I sevp\->sigev_signo
163 ¤¬Í­¸ú¤Ê¥·¥°¥Ê¥ëÈÖ¹æ¤Ç¤Ï¤Ê¤¤¡£
164 .TP
165 .B ENOMEM
166 ɬÍפʥá¥â¥ê¤¬¤Ê¤«¤Ã¤¿¡£
167 .PP
168 POSIX.1-2008 ¤Ç¤Ï¡¢
169 .I sevp
170 ¤¬ NULL ¤Ç¡¢¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤¬¥­¥å¡¼
171 .I mqdes
172 ¤Ë´Ø¤¹¤ëÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢¥¨¥é¡¼
173 .B EINVAL
174 ¤òÀ¸À®¤¹¤ë¤è¤¦¤Ê¼ÂÁõ¤ò¹Ô¤Ã¤Æ¤â¡Ö¤è¤¤¡×¤³¤È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
175 .\" Linux ¤Î¼ÂÁõ¤Ç¤Ï EINVAL ¤ÏÀ¸À®¤µ¤ì¤Ê¤¤
176 .SH ½àµò
177 POSIX.1-2001.
178 .SH Îã
179 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢
180 ¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ç»ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤Ø¤Î
181 ÄÌÃÎÍ×µá¤òÅÐÏ¿¤·¡¢ÄÌÃΤϥ¹¥ì¥Ã¥É¤ÎºîÀ®¤Ë¤è¤Ã¤Æ¹Ô¤ï¤ì¤ë¡£
182 ¤½¤Î¥¹¥ì¥Ã¥É¤Ï¡¢¤½¤Î¥­¥å¡¼¤«¤é¥á¥Ã¥»¡¼¥¸¤ò°ì¤ÄÆɤ߽Ф·¤Æ¤«¤é¡¢
183 ¥×¥í¥»¥¹¤ò½ªÎ»¤¹¤ë´Ø¿ô¤ò¼Â¹Ô¤¹¤ë¡£
184 .nf
185
186 #include <pthread.h>
187 #include <mqueue.h>
188 #include <stdio.h>
189 #include <stdlib.h>
190 #include <unistd.h>
191
192 #define handle_error(msg) \\
193     do { perror(msg); exit(EXIT_FAILURE); } while (0)
194
195 static void                     /* ¥¹¥ì¥Ã¥É³«»Ï´Ø¿ô */
196 tfunc(union sigval sv)
197 {
198     struct mq_attr attr;
199     ssize_t nr;
200     void *buf;
201     mqd_t mqdes = *((mqd_t *) sv.sival_ptr);
202
203     /* ºÇÂç¥á¥Ã¥»¡¼¥¸¥µ¥¤¥º¤ò·èÄꤷ¡¢
204        ¥á¥Ã¥»¡¼¥¸¼õ¿®ÍѤΥХåե¡¤ò³ÎÊݤ¹¤ë */
205
206     if (mq_getattr(mqdes, &attr) == \-1)
207         handle_error("mq_getattr");
208     buf = malloc(attr.mq_msgsize);
209     if (buf == NULL)
210         handle_error("malloc");
211
212     nr = mq_receive(mqdes, buf, attr.mq_msgsize, NULL);
213     if (nr == \-1)
214         handle_error("mq_receive");
215
216     printf("Read %ld bytes from MQ\\n", (long) nr);
217     free(buf);
218     exit(EXIT_SUCCESS);         /* ¥×¥í¥»¥¹¤ò½ªÎ»¤¹¤ë */
219 }
220
221 int
222 main(int argc, char *argv[])
223 {
224     mqd_t mqdes;
225     struct sigevent sev;
226
227     if (argc != 2) {
228         fprintf(stderr, "Usage: %s <mq-name>\\n", argv[0]);
229         exit(EXIT_FAILURE);
230     }
231
232     mqdes = mq_open(argv[1], O_RDONLY);
233     if (mqdes == (mqd_t) \-1)
234         handle_error("mq_open");
235
236     sev.sigev_notify = SIGEV_THREAD;
237     sev.sigev_notify_function = tfunc;
238     sev.sigev_notify_attributes = NULL;
239     sev.sigev_value.sival_ptr = &mqdes;   /* ¥¹¥ì¥Ã¥É´Ø¿ô¤ËÅϤ¹°ú¤­¿ô */
240     if (mq_notify(mqdes, &sev) == \-1)
241         handle_error("mq_notify");
242
243     pause();    /* ¥×¥í¥»¥¹¤Ï¥¹¥ì¥Ã¥É´Ø¿ô¤Ë¤è¤ê½ªÎ»¤µ¤ì¤ë */
244 }
245 .fi
246 .SH ´ØÏ¢¹àÌÜ
247 .BR mq_close (3),
248 .BR mq_getattr (3),
249 .BR mq_open (3),
250 .BR mq_receive (3),
251 .BR mq_send (3),
252 .BR mq_unlink (3),
253 .BR mq_overview (7),
254 .BR sigevent (7)