1MQ_OPEN(3)                 Linux Programmer's Manual                MQ_OPEN(3)
2
3
4

NAME

6       mq_open - open a message queue
7

SYNOPSIS

9       #include <fcntl.h>           /* For O_* constants */
10       #include <sys/stat.h>        /* For mode constants */
11       #include <mqueue.h>
12
13       mqd_t mq_open(const char *name, int oflag);
14       mqd_t mq_open(const char *name, int oflag, mode_t mode,
15                     struct mq_attr *attr);
16
17       Link with -lrt.
18

DESCRIPTION

20       mq_open() creates a new POSIX message queue or opens an existing queue.
21       The queue is identified by name.  For details of  the  construction  of
22       name, see mq_overview(7).
23
24       The  oflag  argument  specifies flags that control the operation of the
25       call.  (Definitions of the flags values can be  obtained  by  including
26       <fcntl.h>.)  Exactly one of the following must be specified in oflag:
27
28       O_RDONLY
29              Open the queue to receive messages only.
30
31       O_WRONLY
32              Open the queue to send messages only.
33
34       O_RDWR Open the queue to both send and receive messages.
35
36       Zero or more of the following flags can additionally be ORed in oflag:
37
38       O_NONBLOCK
39              Open  the  queue  in  nonblocking  mode.  In circumstances where
40              mq_receive(3) and mq_send(3) would normally block,  these  func‐
41              tions instead fail with the error EAGAIN.
42
43       O_CREAT
44              Create  the message queue if it does not exist.  The owner (user
45              ID) of the message queue is set to the effective user ID of  the
46              calling  process.   The group ownership (group ID) is set to the
47              effective group ID of the calling process.
48
49       O_EXCL If O_CREAT was specified in oflag, and a queue  with  the  given
50              name already exists, then fail with the error EEXIST.
51
52       If O_CREAT is specified in oflag, then two additional arguments must be
53       supplied.  The mode argument specifies the permissions to be placed  on
54       the  new  queue, as for open(2).  (Symbolic definitions for the permis‐
55       sions bits can be obtained by including <sys/stat.h>.)  The permissions
56       settings are masked against the process umask.  The attr argument spec‐
57       ifies attributes for the queue.  See  mq_getattr(3)  for  details.   If
58       attr  is  NULL,  then  the queue is created with implementation-defined
59       default attributes.
60

RETURN VALUE

62       On success, mq_open() returns a message queue  descriptor  for  use  by
63       other message queue functions.  On error, mq_open() returns (mqd_t) -1,
64       with errno set to indicate the error.
65

ERRORS

67       EACCES The queue exists, but the caller does  not  have  permission  to
68              open it in the specified mode.
69
70       EACCES name contained more than one slash.
71
72       EEXIST Both  O_CREAT  and  O_EXCL  were specified in oflag, but a queue
73              with this name already exists.
74
75       EINVAL O_CREAT was specified in oflag,  and  attr  was  not  NULL,  but
76              attr->mq_maxmsg  or attr->mq_msqsize was invalid.  Both of these
77              fields must be greater than zero.  In a process that is unprivi‐
78              leged   (does   not   have   the  CAP_SYS_RESOURCE  capability),
79              attr->mq_maxmsg must be less than or equal to the msg_max limit,
80              and  attr->mq_msgsize  must  be  less  than or equal to the msg‐
81              size_max limit.  In addition,  even  in  a  privileged  process,
82              attr->mq_maxmsg cannot exceed the HARD_MAX limit.  (See mq_over‐
83              view(7) for details of these limits.)
84
85       EMFILE The process already has the maximum number of files and  message
86              queues open.
87
88       ENAMETOOLONG
89              name was too long.
90
91       ENFILE The  system  limit on the total number of open files and message
92              queues has been reached.
93
94       ENOENT The O_CREAT flag was not specified in oflag, and no  queue  with
95              this name exists.
96
97       ENOENT name was just "/" followed by no other characters.
98
99       ENOMEM Insufficient memory.
100
101       ENOSPC Insufficient  space  for  the  creation  of a new message queue.
102              This probably occurred because the queues_max limit was  encoun‐
103              tered; see mq_overview(7).
104

CONFORMING TO

106       POSIX.1-2001.
107

BUGS

109       In kernels before 2.6.14, the process umask was not applied to the per‐
110       missions specified in mode.
111

SEE ALSO

113       mq_close(3), mq_getattr(3),  mq_notify(3),  mq_receive(3),  mq_send(3),
114       mq_unlink(3), mq_overview(7)
115

COLOPHON

117       This  page  is  part of release 3.53 of the Linux man-pages project.  A
118       description of the project, and information about reporting  bugs,  can
119       be found at http://www.kernel.org/doc/man-pages/.
120
121
122
123Linux                             2009-02-20                        MQ_OPEN(3)
Impressum