2

I was researching about linux shared memory and stumbled upon this ipcs command.

From the man page:

ipcs - provide information on ipc facilities

ipc is not explained in the man page but it most likely stands for inter-process communication. That also makes sense from the context of the information it lists: shared memory segments, message queues and semaphore arrays.

I was wondering, since everything in linux/unix is a "file", or at least a file-like object, where are the "files" from the elements listed in ipcs?

Why are named pipes created by mkfifo not listed in ipcs? As far as I understand fifos are queues. How are the named pipes created by mkfifo different from the message queues created by ipcmk?

1
  • Some that "files" are in shared memory, not in real filesystem.
    – Eddy_Em
    Apr 22, 2013 at 10:40

2 Answers 2

5

There are several questions here :

  • Where are the files from the elements listed in ipcs ?

It depends. Queues are visible in a virtual file system. From mq_overview(7) :

   Mounting the message queue file system
       On  Linux,  message queues are created in a virtual file system.  (Other implementations may also provide such a feature, but
       the details are likely to differ.)  This file system can be mounted (by the superuser) using the following commands:

           # mkdir /dev/mqueue
           # mount -t mqueue none /dev/mqueue

Shared memory (shm_overview(7))

   Accessing shared memory objects via the file system
       On Linux, shared memory objects are created in a (tmpfs) virtual file system, normally mounted under /dev/shm.  Since  kernel
       2.6.19,  Linux supports the use of access control lists (ACLs) to control the permissions of objects in the virtual file sys-
       tem.

Semaphores (sem_overview(7))

   Accessing named semaphores via the file system
       On Linux, named semaphores are created in a virtual file system, normally mounted under /dev/shm,  with  names  of  the  form
       sem.somename.  (This is the reason that semaphore names are limited to NAME_MAX-4 rather than NAME_MAX characters.)

       Since  Linux  2.6.19,  ACLs can be placed on files under this directory, to control object permissions on a per-user and per-
       group basis.
  • Why are the named pipes created by mkfifo not listed in ipcs ?

I'm not sure about that so I'll only give you my opinion, and not an answer. My hypothesis is that as they are present in the actual file system, like the sockets, there are not managed the same way the kernel manages shared memory segments and message queues.

  • How are the named pipes created by mkfifo different from the message queues created by ipcmk?

The main difference between a pipe and a message queue is that a pipe is only a channel of communication between two processes. It functions at the byte level. You can read and write the way you want, and you have to design the protocol of communication. They are strict FIFOs: a byte written before another will always be read before at the other end. A message queue deals with messages, and not bytes. And usually, they are less strictly FIFO. It depends on the implementation but they can support a mechanism of priority between messages.

In a way, message queues provide more functionnalities but you could, if you want to, implement FIFOs with message queues and vice-versa.

3

ipcs lets you see interprocess communications methods termed "System V IPC". System V IPC is widely ignored at present, but in the past was distinctly disliked. Apparently in the early days, different groups would implement what they needed, and somebody needed message queues, shared memory and semaphores..

Those IPC methods were widely criticized for not being very Unixy, for not being a "file", the same thing that you question.

I don't have an explanation for why named pipes and message queues aren't integrated, but I would bet it originated the same way: one group wanted named pipes, so they just went and did them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .