935
45.7
Obtaining a List of All IPC Objects
Linux provides two nonstandard methods of obtaining a list of all IPC objects on
the system:
z
files within the
/proc/sysvipc
directory that list all IPC objects; and
z
the use of Linux-specific ctl calls.
We describe the files in
/proc/sysvipc
directory here, and defer discussion of the ctl
calls until Section 46.6, where we provide an example program that lists all
System V message queues on the system.
Some other UNIX implementations have their own nonstandard methods of
obtaining a list of all IPC identifiers; for example, Solaris provides the msgids(),
semids(), and shmids() system calls for this purpose.
Three read-only files in the
/proc/sysvipc
directory provide the same information as
can be obtained via ipcs:
z
/proc/sysvipc/msg
lists all messages queues and their attributes.
z
/proc/sysvipc/sem
lists all semaphore sets and their attributes.
z
/proc/sysvipc/shm
lists all shared memory segments and their attributes.
Unlike the ipcs command, these files always show all objects of the corresponding
type, regardless of whether read permission is available on the objects.
An example of the contents of
/proc/sysvipc/sem
is the following (with some
white space removed to fit this example on the page):
$ cat /proc/sysvipc/sem
key semid perms nsems uid gid cuid cgid otime ctime
0 16646144 600 4 1000 100 1000 100 0 1010166460
The three
/proc/sysvipc
files provide a (nonportable) method for programs and
scripts to walk through a list of all of the existing IPC objects of a given type.
The best that we can achieve by way of a portable approach to obtaining a list
of all IPC objects of a given type is to parse the output of ipcs(1).
Chia sẻ với bạn bè của bạn: |