Thursday, July 23, 2015

lsipc new command to list IPC facilities

Although it seems that System V IPC is obsolete thing, it's still used by many (enterprise) tools like databases, application servers etc.

The classic tool ipcs(1) provides basic overview, unfortunately the output is very fixed and it's impossible to mix the output columns (for example --pid and --creator cannot be used together etc.). It's also very difficult to extend the current implementation without break backward compatibility.

The solution is a new libsmartcols based tool: lsipc(1). It's like many another util-linux ls-like tools, columns are maintains independently, it's easy to extend, user has absolute control on the output and it provides more output formats (including JSON).

The important and unique is the default (--global) output:
# lsipc
RESOURCE DESCRIPTION                            LIMIT   USED  USE%
MSGMNI   Number of message queues               32000      0 0.00%
MSGMAX   Max size of message (bytes)             8192      0 0.00%
MSGMNB   Default max size of queue (bytes)      16384      0 0.00%
SHMMNI   Shared memory segments                  4096     21 0.51%
SHMALL   Shared memory pages                268435456 294049 0.11%
SEMMNS   Total number of semaphores        1024000000      0 0.00%
SEMMNI   Number of Semaphore IDs                32000      0 0.00%
the information about shared memory is provided with COMMAND column, that makes things more human friendly:
# lsipc --shmem
KEY        ID           PERMS OWNER SIZE NATTCH STATUS CTIME  CPID LPID COMMAND
0x6c6c6536 0        rw-------  root   4K      0        Jul16   288  288
0x00000000 327681   rw-------  kzak   4M      2 dest   Jul16  1487  992 gjs /home/kzak/.local/share/gnome-shell/extensions/
0x00000000 393219   rw-------  kzak 512K      2 dest   Jul16  1141 2853 /usr/bin/gnome-shell
0x00000000 2064389  rw-------  kzak 384K      2 dest   Jul17  9443  992 xchat
0x00000000 47611910 rw-------  kzak   8M      2 dest   10:07  2853  804 /usr/lib64/firefox/firefox
0x00000000 2228231  rw-------  kzak 384K      2 dest   Jul17  9443  992 xchat
0x00000000 2195464  rw-------  kzak   2M      2 dest   Jul17  9443  992 xchat
0x00000000 42303503 rw-------  kzak   8M      2 dest   Jul22  1340  992 /usr/bin/gnome-software --gapplication-service
0x00000000 42270736 rw-------  kzak   4M      2 dest   Jul22  1340  992 /usr/bin/gnome-software --gapplication-service
0x00000000 43188243 rw-------  kzak   4M      2 dest   Jul22  8873 1845 /usr/libexec/gnome-terminal-server
0x00000000 33882133 rw-------  kzak 384K      2 dest   Jul20 26049  992 /usr/bin/python3 /usr/bin/hp-systray --force-startup
and you can define your own output:
# lsipc --shmem -o KEY,SIZE,PERMS
KEY        SIZE     PERMS
0x6c6c6536   4K rw-------
0x00000000   4M rw-------
0x00000000 512K rw-------
0x00000000 384K rw-------
0x00000000   8M rw-------
0x00000000 384K rw-------
0x00000000   2M rw-------
0x00000000   8M rw-------
0x00000000   4M rw-------
0x00000000   4M rw-------
0x00000000 384K rw-------
or ask for specific segment:
# lsipc --shmem --id 47611910
Key:                                0x00000000
ID:                                 47611910
Owner:                              kzak
Permissions:                        rw-------
Creator UID:                        1000
Creator user:                       kzak
Creator GID:                        1000
Creator group:                      kzak
UID:                                1000
User name:                          kzak
GID:                                1000
Group name:                         kzak
Last change:                        Thu Jul 23 10:07:46 2015
Segment size:                       8M
Attached processes:                 2
Status:                             dest
Attach time:                        Thu Jul 23 10:07:46 2015
Creator command:                    /usr/lib64/firefox/firefox
Creator PID:                        2853
Last user PID:                      804
and it should be easy to export complex info about IPC to the monitoring tool:
# lsipc --json -o resource,limit,used
{
   "ipclimits": [
      {"resource": "MSGMNI", "limit": "32000", "used": "0"},
      {"resource": "MSGMAX", "limit": "8192", "used": "0"},
      {"resource": "MSGMNB", "limit": "16384", "used": "0"},
      {"resource": "SHMMNI", "limit": "4096", "used": "11"},
      {"resource": "SHMALL", "limit": "268435456", "used": "8097"},
      {"resource": "SEMMNS", "limit": "1024000000", "used": "0"},
      {"resource": "SEMMNI", "limit": "32000", "used": "0"}
   ]
}
lsipc(1) will be available in util-linux v2.27 (probaly August 2015).