Home / Alt manpages / ipcmk(1)

  • ipcmk(1)
  • User command
  • linux

Create and Remove System V IPC Resources with ipcmk

You will create a shared memory segment, message queue or semaphore array with ipcmk, check the result with ipcs, and remove a test resource with ipcrm. Allow about ten minutes. The examples use System V IPC and leave no test objects behind when the cleanup steps are followed.

You need a shell and the util-linux package. These commands normally run as your ordinary account. Do not start with sudo: IPC objects belong to the user that creates them, and elevated privileges can make accidental cleanup harder to reason about.

1. Check the installed command

First confirm which executable is being used and record its version. This matters because the installed binary can be newer than the local manual page. On this machine, ipcmk is util-linux 2.41.3 from a Homebrew prefix, while the installed ipcmk(1) page describes util-linux 2.39.3. The System V options used here are documented by that page.

$ command -v ipcmk
/home/linuxbrew/.linuxbrew/bin/ipcmk
$ ipcmk --version
ipcmk from util-linux 2.41.3
$ ipcmk --help

Usage:
 ipcmk [options]

Create various IPC resources.

Checkpoint: if command -v points to a different installation, repeat the version check and read the manual page belonging to that system. The binary accepts additional POSIX IPC options in this installation, but this guide stays with the System V resources and flags described in the local manual page.

2. Create a shared memory segment

Use --shmem or -M followed by a size in bytes. Binary suffixes such as K and KiB are accepted. Set mode 600 for a private test object. The manual's default is 0644, which is readable and writable by the owner and readable by the group and other users, so specify a narrower mode when testing.

$ ipcmk --shmem 4K --mode 600
Shared memory id: 229401

The numeric value at the end is the shared memory ID. It is an identifier, not a filename. Check the object without attaching to it:

$ ipcs --shmem --id 229401

Shared memory Segment shmid=229401
uid=1004    gid=1004    cuid=1004    cgid=1004
mode=0600   access_perms=0600
bytes=4096  lpid=0      cpid=783903  nattch=0

Your owner IDs, process ID and timestamps will differ. The useful checks are the resource type, bytes=4096 and mode=0600.

3. Create a message queue

Use --queue or -Q to create an empty System V message queue. It has no size argument in ipcmk; queue limits are managed by the kernel and system configuration.

$ ipcmk --queue --mode 600
Message queue id: 7
$ ipcs --queues --id 7

Message Queue msqid=7
uid=1004    gid=1004    cuid=1004    cgid=1004    mode=0600
cbytes=0    qbytes=16384 qnum=0

An empty queue is expected immediately after creation: qnum=0 and cbytes=0 show that no messages have been placed in it. Creating the queue does not send or receive any messages.

4. Create a semaphore array

Use --semaphore or -S followed by the number of elements. This creates the array, but it does not assign application-specific values or coordinate any processes.

$ ipcmk --semaphore 3 --mode 600
Semaphore id: 4
$ ipcs --semaphore --id 4

Semaphore Array semid=4
uid=1004  gid=1004  cuid=1004  cgid=1004
mode=0600, access_perms=0600
nsems = 3

New semaphore elements start at zero on the tested installation. Treat that as a result to verify, not as a substitute for setting the values required by your application.

5. Remove each test object

Creation changes kernel state. Before removing anything, check the ID and type against the output you recorded. The following commands are destructive for those exact IPC objects, although they do not delete ordinary files:

$ ipcrm --shmem 229401
$ ipcrm --queue 7
$ ipcrm --semaphore 4

Use the numeric ID from your own output, not the example IDs. If another process is using a resource, removal can disrupt it. Never remove an object merely because it appears unfamiliar in a system-wide listing; confirm its owner, creator and purpose first.

Checkpoint: verify that your IDs are gone. An empty result for each filtered query is the expected outcome:

$ ipcs --shmem --id 229401
$ ipcs --queues --id 7
$ ipcs --semaphore --id 4

If you lose an ID, list the objects with ipcs --shmem, ipcs --queues or ipcs --semaphore, then identify the object using its owner, permissions and creation details. Do not guess. If creation fails with Invalid argument, check the requested size or semaphore count; a zero semaphore count, for example, is rejected.

Done means

  • ipcmk --version identified the binary being used.
  • The resource type, ID, size or element count, and access mode were checked with ipcs.
  • Test objects were created with 600 permissions rather than relying on the documented 0644 default.
  • The numeric IDs were checked before removal, and the objects no longer appear in filtered ipcs queries.