man-pages/man2/msgget.2

236 lines
5.6 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Copyright 1993 Giorgio Ciucci <giorgio@crcc.it>
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provflags the copyright notice and this permission notice are
2004-11-03 13:51:07 +00:00
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
2004-11-03 13:51:07 +00:00
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
2004-11-03 13:51:07 +00:00
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Added correction due to Nick Duffek <nsd@bbc.com>, aeb, 960426
.\" Modified Wed Nov 6 04:00:31 1996 by Eric S. Raymond <esr@thyrsus.com>
2007-09-20 06:52:22 +00:00
.\" Modified, 8 Jan 2003, Michael Kerrisk, <mtk.manpages@gmail.com>
2004-11-03 13:51:07 +00:00
.\" Removed EIDRM from errors - that can't happen...
2007-09-20 06:52:22 +00:00
.\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
2004-11-03 13:51:07 +00:00
.\" Added notes on capability requirements
2007-09-20 06:52:22 +00:00
.\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
.\" Language and formatting clean-ups
.\" Added notes on /proc files
2004-11-03 13:51:07 +00:00
.\"
.TH MSGGET 2 2012-05-31 "Linux" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
msgget \- get a message queue identifier
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.B #include <sys/ipc.h>
.B #include <sys/msg.h>
2008-07-08 14:36:09 +00:00
2008-07-06 14:54:26 +00:00
.BI "int msgget(key_t " key ", int " msgflg );
2008-07-08 14:36:09 +00:00
.fi
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
The
.BR msgget ()
system call returns the message queue identifier associated
2004-11-03 13:51:07 +00:00
with the value of the
.I key
argument.
A new message queue is created if
.I key
has the value
.B IPC_PRIVATE
or
.I key
isn't
.BR IPC_PRIVATE ,
no message queue with the given key
2007-09-20 16:26:31 +00:00
.I key
2004-11-03 13:51:07 +00:00
exists, and
.B IPC_CREAT
is specified in
.IR msgflg .
.PP
If
2004-11-03 13:51:07 +00:00
.I msgflg
specifies both
2004-11-03 13:51:07 +00:00
.B IPC_CREAT
and
.B IPC_EXCL
and a message queue already exists for
.IR key ,
then
.BR msgget ()
fails with
.I errno
set to
.BR EEXIST .
(This is analogous to the effect of the combination
.B O_CREAT | O_EXCL
for
.BR open (2).)
2004-11-03 13:51:07 +00:00
.PP
Upon creation, the least significant bits of the argument
2004-11-03 13:51:07 +00:00
.I msgflg
define the permissions of the message queue.
2004-11-03 13:51:07 +00:00
These permission bits have the same format and semantics
as the permissions specified for the
.I mode
argument of
.BR open (2).
(The execute permissions are not used.)
2004-11-03 13:51:07 +00:00
.PP
If a new message queue is created,
then its associated data structure
2005-09-15 12:06:26 +00:00
.I msqid_ds
(see
.BR msgctl (2))
is initialized as follows:
2004-11-03 13:51:07 +00:00
.IP
.I msg_perm.cuid
2004-11-03 13:51:07 +00:00
and
.I msg_perm.uid
2005-07-18 16:13:49 +00:00
are set to the effective user ID of the calling process.
2004-11-03 13:51:07 +00:00
.IP
.I msg_perm.cgid
2004-11-03 13:51:07 +00:00
and
.I msg_perm.gid
2005-07-18 16:13:49 +00:00
are set to the effective group ID of the calling process.
2004-11-03 13:51:07 +00:00
.IP
The least significant 9 bits of
.I msg_perm.mode
are set to the least significant 9 bits of
2004-11-03 13:51:07 +00:00
.IR msgflg .
.IP
.IR msg_qnum ,
.IR msg_lspid ,
.IR msg_lrpid ,
2007-09-20 16:26:31 +00:00
.I msg_stime
2004-11-03 13:51:07 +00:00
and
.I msg_rtime
2004-11-03 13:51:07 +00:00
are set to 0.
.IP
.I msg_ctime
2004-11-03 13:51:07 +00:00
is set to the current time.
.IP
.I msg_qbytes
2004-11-03 13:51:07 +00:00
is set to the system limit
.BR MSGMNB .
.PP
If the message queue already exists the permissions are
2004-11-03 13:51:07 +00:00
verified, and a check is made to see if it is marked for
destruction.
.SH "RETURN VALUE"
If successful, the return value will be the message queue identifier (a
nonnegative integer), otherwise \-1
2004-11-03 13:51:07 +00:00
with
.I errno
2004-11-03 13:51:07 +00:00
indicating the error.
.SH ERRORS
On failure,
.I errno
2004-11-03 13:51:07 +00:00
is set to one of the following values:
2008-08-06 20:33:17 +00:00
.TP
2004-11-03 13:51:07 +00:00
.B EACCES
A message queue exists for
.IR key ,
but the calling process does not have permission to access the queue,
and does not have the
2007-09-20 16:26:31 +00:00
.B CAP_IPC_OWNER
2004-11-03 13:51:07 +00:00
capability.
.TP
.B EEXIST
A message queue exists for
2005-11-02 13:55:25 +00:00
.I key
2004-11-03 13:51:07 +00:00
and
.I msgflg
specified both
2004-11-03 13:51:07 +00:00
.B IPC_CREAT
and
.BR IPC_EXCL .
.TP
.B ENOENT
No message queue exists for
.I key
and
.I msgflg
did not specify
2004-11-03 13:51:07 +00:00
.BR IPC_CREAT .
.TP
.B ENOMEM
A message queue has to be created but the system does not have enough
memory for the new data structure.
2004-11-03 13:51:07 +00:00
.TP
.B ENOSPC
A message queue has to be created but the system limit for the maximum
number of message queues
.RB ( MSGMNI )
would be exceeded.
.SH "CONFORMING TO"
SVr4, POSIX.1-2001.
2004-11-03 13:51:07 +00:00
.SH NOTES
The inclusion of
.I <sys/types.h>
and
.I <sys/ipc.h>
isn't required on Linux or by any version of POSIX.
However,
some old implementations required the inclusion of these header files,
and the SVID also documented their inclusion.
Applications intended to be portable to such old systems may need
to include these header files.
.\" Like Linux, the FreeBSD man pages still document
.\" the inclusion of these header files.
2004-11-03 13:51:07 +00:00
.B IPC_PRIVATE
isn't a flag field but a
.I key_t
2004-11-03 13:51:07 +00:00
type.
If this special value is used for
.IR key ,
the system call ignores everything but the least significant 9 bits of
2004-11-03 13:51:07 +00:00
.I msgflg
and creates a new message queue (on success).
.PP
The following is a system limit on message queue resources affecting a
.BR msgget ()
2004-11-03 13:51:07 +00:00
call:
2008-08-06 20:33:17 +00:00
.TP
2004-11-03 13:51:07 +00:00
.B MSGMNI
System wide maximum number of message queues: policy
dependent
(on Linux, this limit can be read and modified via
.IR /proc/sys/kernel/msgmni ).
.SS "Linux Notes"
2007-06-22 17:16:20 +00:00
Until version 2.3.20 Linux would return
2007-09-20 16:26:31 +00:00
.B EIDRM
2007-06-22 17:16:20 +00:00
for a
.BR msgget ()
on a message queue scheduled for deletion.
2004-11-03 13:51:07 +00:00
.SH BUGS
2007-06-22 17:16:20 +00:00
The name choice
2007-09-20 16:26:31 +00:00
.B IPC_PRIVATE
2007-12-16 13:13:29 +00:00
was perhaps unfortunate,
.B IPC_NEW
2004-11-03 13:51:07 +00:00
would more clearly show its function.
.SH "SEE ALSO"
.BR msgctl (2),
.BR msgrcv (2),
.BR msgsnd (2),
.BR ftok (3),
.BR capabilities (7),
2006-04-21 03:53:43 +00:00
.BR mq_overview (7),
.BR svipc (7)