LinuxCommandLibrary

ipcmk

Create System V inter-process communication (IPC) resources

TLDR

Create a shared memory segment

$ ipcmk [[-M|--shmem]] [segment_size_in_bytes]
copy

Create a semaphore
$ ipcmk [[-S|--semaphore]] [element_size]
copy

Create a message queue
$ ipcmk [[-Q|--queue]]
copy

Create a shared memory segment with specific permissions (default is 0644)
$ ipcmk [[-M|--shmem]] [segment_size_in_bytes] [octal_permissions]
copy

SYNOPSIS

ipcmk [-M shmkey | -Q msgkey | -S semkey] [-o optkey] [-p size] [-s nsems]

PARAMETERS

-M shmkey
    Create shared memory segment with key shmkey (decimal/octal/hex).

-Q msgkey
    Create message queue with key msgkey (decimal/octal/hex).

-S semkey
    Create semaphore set with key semkey (decimal/octal/hex).

-o optkey
    Override/return existing key optkey if present (decimal/octal/hex).

-p size
    Set size in bytes for shm/msg (required); ignored for sem.

-s nsems
    Set number of semaphores for sem set (default: 1).

DESCRIPTION

ipcmk is a Linux utility for creating System V IPC identifiers used in inter-process communication. It allocates message queues, semaphore sets, or shared memory segments with a user-specified key, bypassing the need for custom C programs calling msgget(2), semget(2), or shmget(2).

System V IPC relies on numeric keys or IPC_PRIVATE for anonymous objects. ipcmk enables shell-based setup of persistent, named IPC resources, ideal for multi-process environments like scripts or daemons sharing data. Created objects default to permissions rw-rw-rw- (0666 octal), owned by the invoking user/group.

Usage requires exactly one type flag: -M for shared memory (shmkey), -Q for message queues (msgkey), or -S for semaphores (semkey). Pair with -p to set shm/msg size in bytes or -s for semaphore count (default 1 if omitted for sem). The -o flag overrides existing keys. Keys parse as decimal, octal (leading 0), or hex (leading 0x/0X).

On success, it outputs the numeric IPC id to stdout for use with ipcs(1). Errors (e.g., invalid size, key collision without -o) yield exit code 1 and stderr messages. Limits follow kernel settings (ipcs -l).

This tool simplifies IPC management in non-programming contexts, though modern alternatives like mmap(2) or posix_ipc exist.

CAVEATS

Exactly one of -M, -Q, -S required; -p mandatory for shm/msg or fails with EINVAL. Default perms 0666; kernel limits apply. Key 0 creates but may conflict.

EXIT STATUS

0 on success; 1 on error with stderr message.

OUTPUT

Prints created IPC id (e.g., 42) to stdout on success.

HISTORY

Written by Alexey Gladkov; added to util-linux 2.26 (March 2014) for shell IPC creation.

SEE ALSO

ipcs(1), ipcrm(1), msgget(2), semget(2), shmget(2)

Copied to clipboard