OSDN Git Service

4c8b9ac56da2c83790a646c14723bd36775f3c20
[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 .\"
30 .TH MQ_NOTIFY 3 2009-09-15 "Linux" "Linux Programmer's Manual"
31 .SH Ì¾Á°
32 mq_notify \- ¥á¥Ã¥»¡¼¥¸ÅþÃå»þ¤ËÄÌÃΤò¹Ô¤¦¤è¤¦ÅÐÏ¿¤¹¤ë
33 .SH ½ñ¼°
34 .nf
35 .B #include <mqueue.h>
36 .sp
37 .BI "mqd_t mq_notify(mqd_t " mqdes ", const struct sigevent *" notification );
38 .fi
39 .sp
40 \fI\-lrt\fP ¤Ç¥ê¥ó¥¯¤¹¤ë¡£
41 .SH ÀâÌÀ
42 .BR mq_notify ()
43 ¤ò»È¤¦¤È¡¢¥Ç¥£¥¹¥¯¥ê¥×¥¿
44 .I mqdes
45 ¤Ç»²¾È¤µ¤ì¤ë¶õ¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤Ë¿·¤·¤¯¥á¥Ã¥»¡¼¥¸¤¬ÅþÃ夷¤¿»þ¤Ë
46 ÈóƱ´ü¤ÎÄÌÃΠ(notification) ¤ÎÇÛÁ÷¤¬¹Ô¤ï¤ì¤ë¤è¤¦¤ËÅÐÏ¿¤·¤¿¤ê¡¢
47 ¤½¤Î²ò½ü¤ò¹Ô¤Ã¤¿¤ê¤Ç¤­¤ë¡£
48
49 .I notification
50 °ú¤­¿ô¤Ï
51 .I sigevent
52 ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
53 .I sigevent
54 ¹½Â¤ÂΤϰʲ¼¤Î¤è¤¦¤Ê´¶¤¸¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
55 .in +4n
56 .nf
57
58 union sigval {          /* Data passed with notification */
59     int     sival_int;         /* Integer value */
60     void   *sival_ptr;         /* Pointer value */
61 };
62
63 struct sigevent {
64     int          sigev_notify; /* Notification method */
65     int          sigev_signo;  /* Notification signal */
66     union sigval sigev_value;  /* Data passed with
67                                   notification */
68     void       (*sigev_notify_function) (union sigval);
69                                /* Function for thread
70                                   notification */
71     void        *sigev_notify_attributes;
72                                /* Thread function attributes */
73 };
74 .fi
75 .in
76 .PP
77 .I notification
78 ¤¬ NULL ¤Ç¤Ê¤¤¥Ý¥¤¥ó¥¿¤Ç¤¢¤ì¤Ð¡¢
79 .BR mq_notify ()
80 ¤Ï¥á¥Ã¥»¡¼¥¸ÄÌÃΤò¼õ¤±¼è¤ë¤è¤¦¤Ë¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤òÅÐÏ¿¤¹¤ë¡£
81 .I notification
82 ¤¬»Ø¤¹
83 .I sigevent
84 ¤Î
85 .I sigev_notify
86 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¤É¤Î¤è¤¦¤ÊÄÌÃΤò¹Ô¤¦¤Î¤«¤ò»ØÄꤹ¤ë¡£
87 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ï°Ê²¼¤ÎÃͤΤ¤¤º¤ì¤«¤ò»ý¤Ä¡£
88 .TP
89 .B SIGEV_NONE
90 ¡Ö¶õ¤Î (null)¡×¤ÎÄÌÃÎ: ¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤òÄÌÃΤΰ¸Àè¤È¤·¤ÆÅÐÏ¿¤¹¤ë¤¬¡¢
91 ¼ÂºÝ¤Ë¤Ï¥á¥Ã¥»¡¼¥¸¤¬ÅþÃ夷¤¿»þ¤ËÄÌÃΤÏÁ÷¤é¤ì¤Ê¤¤¡£
92 .\" When is SIGEV_NONE useful?
93 .TP
94 .B SIGEV_SIGNAL
95 .I sigev_signo
96 ¤Ç»ØÄꤵ¤ì¤¿¥·¥°¥Ê¥ë¤òÁ÷¤Ã¤Æ¡¢¥×¥í¥»¥¹¤ËÄÌÃΤ¹¤ë¡£
97 .BR sigaction (2)
98 ¤Î
99 .B SA_SIGINFO
100 ¥Õ¥é¥°¤Ç¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤òÅÐÏ¿¤·¤Æ¤¤¤ë¾ì¹ç¡¢
101 ¤½¤Î¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ç¥·¥°¥Ê¥ë¤¬Ê᪤µ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
102 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤ÎÂèÆó°ú¤­¿ô¤È¤·¤ÆÅϤµ¤ì¤ë
103 .I siginfo_t
104 ¹½Â¤ÂΤγƥե£¡¼¥ë¥É¤Ï°Ê²¼¤Î¤è¤¦¤ËÀßÄꤵ¤ì¤ë¡£
105 .I si_code
106 ¤Ë¤Ï
107 .B SI_MESGQ
108 ¤¬¡¢
109 .I si_signo
110 ¤Ë¤Ï¥·¥°¥Ê¥ëÈֹ椬¡¢
111 .I si_value
112 ¤Ë¤Ï
113 .I notification\->sigev_value
114 ¤Ç»ØÄꤷ¤¿Ãͤ¬ÀßÄꤵ¤ì¤ë¡£
115 .\" I don't know of other implementations that set
116 .\" si_pid and si_uid -- MTK
117 .I si_pid
118 ¤Ë¤Ï¥á¥Ã¥»¡¼¥¸¤òÁ÷¿®¤·¤¿¥×¥í¥»¥¹¤Î PID ¤¬¡¢
119 .I si_uid
120 ¤Ë¤ÏÁ÷¿®¥×¥í¥»¥¹¤Î¼Â¥æ¡¼¥¶ ID ¤¬ÀßÄꤵ¤ì¤ë¡£
121 .BR sigwaitinfo (2)
122 ¤ò»È¤Ã¤Æ¥·¥°¥Ê¥ë¤ò¼õ¿®¤¹¤ë¾ì¹ç¤â¡¢Æ±¤¸¾ðÊó¤¬ÆÀ¤é¤ì¤ë¡£
123 .TP
124 .B SIGEV_THREAD
125 ¿·¤·¤¤¥¹¥ì¥Ã¥É¤Î³«»Ï´Ø¿ô¤È¤·¤Æ
126 .I notification\->sigev_thread_function
127 ¤òµ¯Æ°¤¹¤ë¤³¤È¤ÇÄÌÃΤò¹Ô¤¦¡£
128 µ¯Æ°»þ¤Î´Ø¿ô¤Î°ú¤­¿ô¤È¤·¤Æ¤Ï
129 .I notification\->sigev_value
130 ¤À¤±¤¬ÅϤµ¤ì¤ë¡£
131 .I notification\->sigev_notify_attributes
132 ¤Ï¡¢NULL °Ê³°¤Î¾ì¹ç¡¢
133 ¤½¤Î¥¹¥ì¥Ã¥É¤Î°À­¤òÄêµÁ¤¹¤ë
134 .I pthread_attr_t
135 ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤È¤Ê¤Ã¤Æ¤¤¤ëɬÍפ¬¤¢¤ë
136 .RB ( pthread_attr_init (3)
137 »²¾È)¡£
138 .PP
139 °ì¤Ä¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤«¤éÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤ËÅÐÏ¿¤Ç¤­¤ë¥×¥í¥»¥¹¤Ï
140 °ì¤Ä¤À¤±¤Ç¤¢¤ë¡£
141
142 .I notification
143 ¤¬ NULL ¤Ç¡¢¤«¤Ä¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤¬¤³¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤«¤é¤Î
144 ÄÌÃΤò¼õ¿®¤¹¤ë¤Ë¸½ºßÅÐÏ¿¤·¤Æ¤¤¤ë¾ì¹ç¡¢ÅÐÏ¿¤òºï½ü¤¹¤ë¡£
145 ¤³¤ì°Ê¹ß¡¢ÊÌ¤Î¥×¥í¥»¥¹¤¬¤³¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤«¤éÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤Ë
146 ÅÐÏ¿¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ë¡£
147
148 ¥á¥Ã¥»¡¼¥¸ÄÌÃΤϡ¢¤½¤ì¤Þ¤Ç¶õ¤Î¥­¥å¡¼¤Ë¿·¤·¤¤¥á¥Ã¥»¡¼¥¸¤¬ÅþÃ夷¤¿
149 ¾ì¹ç¤Ë¤Î¤ß¹Ô¤ï¤ì¤ë¡£
150 .BR mq_notify ()
151 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿»þ¤Ë¤½¤Î¥­¥å¡¼¤¬¶õ¤Ç¤Ê¤¤¾ì¹ç¡¢
152 ¤½¤Î¥­¥å¡¼¤¬¶õ¤Ë¤Ê¤ê¡¢¤½¤Î¸å¿·¤·¤¤¥á¥Ã¥»¡¼¥¸¤¬ÅþÃ夷¤¿»þ¤Ë
153 ½é¤á¤ÆÄÌÃΤ¬¹Ô¤ï¤ì¤ë¤³¤È¤Ë¤Ê¤ë¡£
154
155 ÊÌ¤Î¥×¥í¥»¥¹¤ä¥¹¥ì¥Ã¥É¤¬
156 .BR mq_receive (3)
157 ¤ò»È¤Ã¤Æ¡¢¶õ¤Î¥­¥å¡¼¤«¤é¥á¥Ã¥»¡¼¥¸¤ÎÆɤ߽Ф·¤òÂԤäƤ¤¤ë¾ì¹ç¡¢
158 ¥á¥Ã¥»¡¼¥¸ÄÌÃΤÎÅÐÏ¿¤ÏÁ´¤Æ̵»ë¤µ¤ì¤ë¡£
159 ¥á¥Ã¥»¡¼¥¸¤Ï
160 .BR mq_receive (3)
161 ¤ò¸Æ¤Ó½Ð¤·¤Æ¤¤¤ë¥×¥í¥»¥¹¤ä¥¹¥ì¥Ã¥É¤ËÇÛÁ÷¤µ¤ì¡¢
162 ¥á¥Ã¥»¡¼¥¸ÄÌÃΤÎÅÐÏ¿¤Ï¸úÎϤò»ý¤Ã¤¿¤Þ¤Þ¤È¤Ê¤ë¡£
163
164 ÄÌÃΤϰìÅÙ¤À¤±¹Ô¤ï¤ì¤ë¡£ÄÌÃΤ¬Á÷¤é¤ì¤¿¸å¤Ï¡¢ÄÌÃÎÍ×µá¤ÎÅÐÏ¿¤Ïºï½ü¤µ¤ì¡¢
165 ÊÌ¤Î¥×¥í¥»¥¹¤¬¥á¥Ã¥»¡¼¥¸ÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤ËÅÐÏ¿¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ë¡£
166 ÄÌÃΤò¼õ¤±¤¿¥×¥í¥»¥¹¤¬¼¡¤ÎÄÌÃΤâ¼õ¿®¤·¤¿¤¤¾ì¹ç¤Ï¡¢
167 .BR mq_notify ()
168 ¤ò»È¤Ã¤Æ¤½¤Î¸å¤ÎÄÌÃΤâ¼õ¤±¤ë¤è¤¦¤ËÍ׵᤹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
169 .BR mq_notify ()
170 ¤òºÆÅٸƤӽФ¹¤Î¤Ï¡¢Æɤ߽Ф·¤Æ¤¤¤Ê¤¤¥á¥Ã¥»¡¼¥¸¤òÁ´ÉôÆɤ߽Ф·¤Æ
171 ¥­¥å¡¼¤¬¶õ¤Ë¤Ê¤ëÁ°¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë
172 (¥­¥å¡¼¤«¤é¤Î¥á¥Ã¥»¡¼¥¸Æɤ߽Ф·¤ò¥­¥å¡¼¤¬¶õ¤Ë¤Ê¤Ã¤¿»þ¤Ë
173 Ää»ß (block) ¤»¤º¤Ë¹Ô¤¦¤Ë¤Ï¡¢¥­¥å¡¼¤òÈóÄä»ß¥â¡¼¥É (non-blocking mode)
174 ¤ËÀßÄꤷ¤Æ¤ª¤¯¤È¤è¤¤)¡£
175 .SH ÊÖ¤êÃÍ
176 À®¸ù¤¹¤ë¤È¡¢
177 .BR mq_notify ()
178 ¤Ï 0 ¤òÊÖ¤¹¡£¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
179 .I errno
180 ¤ò¥¨¥é¡¼¤ò¼¨¤¹ÃͤËÀßÄꤹ¤ë¡£
181 .SH ¥¨¥é¡¼
182 .TP
183 .B EBADF
184 .I mqdes
185 ¤Ë»ØÄꤵ¤ì¤¿¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬ÉÔÀµ¤Ç¤¢¤ë¡£
186 .TP
187 .B EBUSY
188 ÊÌ¤Î¥×¥í¥»¥¹¤¬¤¹¤Ç¤Ë
189 ¤³¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤ËÂФ¹¤ëÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤ËÅÐÏ¿¤·¤Æ¤¤¤ë¡£
190 .TP
191 .B EINVAL
192 .I notification\->sigev_notify
193 ¤¬µö²Ä¤µ¤ì¤¿ÃͤΤ¤¤º¤ì¤Ç¤â¤Ê¤¤¡£¤â¤·¤¯¤Ï
194 .I notification\->sigev_notify
195 ¤¬
196 .B SIGEV_SIGNAL
197 ¤À¤¬
198 .I notification\->sigev_signo
199 ¤¬Í­¸ú¤Ê¥·¥°¥Ê¥ëÈÖ¹æ¤Ç¤Ï¤Ê¤¤¡£
200 .TP
201 .B ENOMEM
202 ɬÍפʥá¥â¥ê¤¬¤Ê¤«¤Ã¤¿¡£
203 .PP
204 POSIX.1-2008 ¤Ç¤Ï¡¢
205 .I notifications
206 ¤¬ NULL ¤Ç¡¢¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤¬¥­¥å¡¼
207 .I mqdes
208 ¤Ë´Ø¤¹¤ëÄÌÃΤò¼õ¿®¤¹¤ë¤è¤¦¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢¥¨¥é¡¼
209 .B EINVAL
210 ¤òÀ¸À®¤¹¤ë¤è¤¦¤Ê¼ÂÁõ¤ò¹Ô¤Ã¤Æ¤â¡Ö¤è¤¤¡×¤³¤È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
211 .\" Linux ¤Î¼ÂÁõ¤Ç¤Ï EINVAL ¤ÏÀ¸À®¤µ¤ì¤Ê¤¤
212 .SH ½àµò
213 POSIX.1-2001.
214 .SH Îã
215 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢
216 ¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ç»ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¤Ø¤Î
217 ÄÌÃÎÍ×µá¤òÅÐÏ¿¤·¡¢ÄÌÃΤϥ¹¥ì¥Ã¥É¤ÎºîÀ®¤Ë¤è¤Ã¤Æ¹Ô¤ï¤ì¤ë¡£
218 ¤½¤Î¥¹¥ì¥Ã¥É¤Ï¡¢¤½¤Î¥­¥å¡¼¤«¤é¥á¥Ã¥»¡¼¥¸¤ò°ì¤ÄÆɤ߽Ф·¤Æ¤«¤é¡¢
219 ¥×¥í¥»¥¹¤ò½ªÎ»¤¹¤ë´Ø¿ô¤ò¼Â¹Ô¤¹¤ë¡£
220 .nf
221
222 #include <pthread.h>
223 #include <mqueue.h>
224 #include <stdio.h>
225 #include <stdlib.h>
226 #include <unistd.h>
227
228 #define handle_error(msg) \\
229     do { perror(msg); exit(EXIT_FAILURE); } while (0)
230
231 static void                     /* ¥¹¥ì¥Ã¥É³«»Ï´Ø¿ô */
232 tfunc(union sigval sv)
233 {
234     struct mq_attr attr;
235     ssize_t nr;
236     void *buf;
237     mqd_t mqdes = *((mqd_t *) sv.sival_ptr);
238
239     /* ºÇÂç¥á¥Ã¥»¡¼¥¸¥µ¥¤¥º¤ò·èÄꤷ¡¢
240        ¥á¥Ã¥»¡¼¥¸¼õ¿®ÍѤΥХåե¡¤ò³ÎÊݤ¹¤ë */
241
242     if (mq_getattr(mqdes, &attr) == \-1)
243         handle_error("mq_getattr");
244     buf = malloc(attr.mq_msgsize);
245     if (buf == NULL)
246         handle_error("malloc");
247
248     nr = mq_receive(mqdes, buf, attr.mq_msgsize, NULL);
249     if (nr == \-1)
250         handle_error("mq_receive");
251
252     printf("Read %ld bytes from MQ\\n", (long) nr);
253     free(buf);
254     exit(EXIT_SUCCESS);         /* ¥×¥í¥»¥¹¤ò½ªÎ»¤¹¤ë */
255 }
256
257 int
258 main(int argc, char *argv[])
259 {
260     mqd_t mqdes;
261     struct sigevent not;
262
263     if (argc != 2) {
264         fprintf(stderr, "Usage: %s <mq-name>\\n", argv[0]);
265         exit(EXIT_FAILURE);
266     }
267
268     mqdes = mq_open(argv[1], O_RDONLY);
269     if (mqdes == (mqd_t) \-1)
270         handle_error("mq_open");
271
272     not.sigev_notify = SIGEV_THREAD;
273     not.sigev_notify_function = tfunc;
274     not.sigev_notify_attributes = NULL;
275     not.sigev_value.sival_ptr = &mqdes;   /* ¥¹¥ì¥Ã¥É´Ø¿ô¤ËÅϤ¹°ú¤­¿ô */
276     if (mq_notify(mqdes, &not) == \-1)
277         handle_error("mq_notify");
278
279     pause();    /* ¥×¥í¥»¥¹¤Ï¥¹¥ì¥Ã¥É´Ø¿ô¤Ë¤è¤ê½ªÎ»¤µ¤ì¤ë */
280 }
281 .fi
282 .SH ´ØÏ¢¹àÌÜ
283 .BR mq_close (3),
284 .BR mq_getattr (3),
285 .BR mq_open (3),
286 .BR mq_receive (3),
287 .BR mq_send (3),
288 .BR mq_unlink (3),
289 .BR mq_overview (7)