DEV Community

Aivars Kalvāns
Aivars Kalvāns

Posted on • Originally published at aivarsk.com on

Listing SystemV IPC queues

The correct way to list the queues on the Linux machine is by using the ipcs -q command. However, I have not seen anything in the system calls that would provide such a capability. But Today I Learned…

The ipcs utility has two ways of retrieving the list of queues. The first and main one is to read and parse /proc/sysvipc/msg. If the file is not present, it does a fallback by using a strange Linux-specific msgctl call with MSG_INFO command. Which among other things has this property:

successful IPC_INFO or MSG_INFO operation returns the index of the highest used entry in the kernel’s internal array recording information about all message queues

And then it’s just a loop from 0 to that max ID and checking all possible queue identifiers.

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay