Scroll to navigation

MSGGET(2) Manual del Programador de Linux MSGGET(2)

NOMBRE

msgget - devuelve un identificador System V para una cola de mensajes

SINOPSIS

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
int msgget(key_t key, int msgflg);

DESCRIPCIÓN

The msgget() system call returns the System V message queue identifier associated with the value of the key argument. It may be used either to obtain the identifier of a previously created message queue (when msgflg is zero and key does not have the value IPC_PRIVATE), or to create a new set.

A new message queue is created if key has the value IPC_PRIVATE or key isn't IPC_PRIVATE, no message queue with the given key key exists, and IPC_CREAT is specified in msgflg.

If msgflg specifies both IPC_CREAT and IPC_EXCL and a message queue already exists for key, then msgget() fails with errno set to EEXIST. (This is analogous to the effect of the combination O_CREAT | O_EXCL for open(2).)

Upon creation, the least significant bits of the argument msgflg define the permissions of the message queue. These permission bits have the same format and semantics as the permissions specified for the mode argument of open(2). (The execute permissions are not used.)

Si se crea una nueva cola de mensajes, la llamada al sistema inicializa la estructura de datos del sistema (consulte msgctl(2)) para la cola msqid_ds como se muestra:

  • msg_perm.cuid y msg_perm.uid son fijados al identificador del usuario efectivo del proceso invocador.
  • msg_perm.cgid y msg_perm.gid son fijados al identificador de grupo efectivo del proveso invocador.
  • Los 9 bits menos importantes de msg_perm.mode son fijados a los 9 bits menos significativos de msgflg.
  • msg_qnum, msg_lspid, msg_lrpid, msg_stime y msg_rtime son puestos a 0.
  • msg_ctime contendrá la hora actual.
  • msg_qbytes será igual al límite impuesto por el sistema MSGMNB.

Si la cola de mensajes ya existe, se verifican los permisos, y ser realiza una comprobación a fin de verificar si está marcada para su destrucción.

VALOR DEVUELTO

Si ha funcionado correctamente, devuelve el idenficador para la cola de mensajes (un entero no negativo), en otro caso -1 con errno indicando el error.

ERRORES

En caso de error, errno tendrá uno de los siguientes valores:

A message queue exists for key, but the calling process does not have permission to access the queue, and does not have the CAP_IPC_OWNER capability in the user namespace that governs its IPC namespace.
IPC_CREAT and IPC_EXCL were specified in msgflg, but a message queue already exists for key.
No message queue exists for key and msgflg did not specify IPC_CREAT.
Una cola de mensajes ha de ser creada pero el sistema no contiene suficiente memoria para la nueva estructura de datos.
Una cola de mensajes ha de ser creada pero el límite del sistema para el máximo número de colas de mensajes (MSGMNI) será superado.

CONFORME A

POSIX.1-2001, POSIX.1-2008, SVr4.

NOTAS

The inclusion of <sys/types.h> and <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.

IPC_PRIVATE isn't a flag field but a key_t type. If this special value is used for key, the system call ignores everything but the least significant 9 bits of msgflg and creates a new message queue (on success).

Lo siguiente es una limitación en los recursos del sistema que afecta a la llamada msgget():

System-wide limit on the number of message queues. Before Linux 3.19, the default value for this limit was calculated using a formula based on available system memory. Since Linux 3.19, the default value is 32,000. On Linux, this limit can be read and modified via /proc/sys/kernel/msgmni.

Notas de Linux

Hasta la versión 2.3.20 Linux devolvía EIDRM cuando se llamaba a msgget() con una cola de mensajes planificada para ser borrada.

ERRORES

La elección del nombre IPC_PRIVATE puede que fuera desafortunada, IPC_NEW mostraría más claramente su función.

VÉASE TAMBIÉN

msgctl(2), msgrcv(2), msgsnd(2), ftok(3), capabilities(7), mq_overview(7), sysvipc(7)

COLOFÓN

Esta página es parte de la versión 5.10 del proyecto Linux man-pages. Puede encontrar una descripción del proyecto, información sobre cómo informar errores y la última versión de esta página en https://www.kernel.org/doc/man-pages/.

TRADUCCIÓN

La traducción al español de esta página del manual fue creada por Juan Piernas <piernas@ditec.um.es> y Marcos Fouces <marcos@debian.org>

Esta traducción es documentación libre; lea la GNU General Public License Version 3 o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD.

Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a debian-l10n-spanish@lists.debian.org.

2 Agosto 2019 Linux