934
Chapter 45
45.6
The
ipcs and ipcrm Commands
The ipcs and ipcrm commands are the System V IPC analogs of the ls and rm file
commands. Using ipcs, we can obtain information about IPC objects on the system.
By default, ipcs displays all objects, as in the following example:
$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x6d0731db 262147 mtk 600 8192 2
------ Semaphore Arrays --------
key semid owner perms nsems
0x6107c0b8 0 cecilia 660 6
0x6107c0b6 32769 britta 660 1
------ Message Queues --------
key msqid owner perms used-bytes messages
0x71075958 229376 cecilia 620 12 2
On Linux, ipcs(1) displays information only about IPC objects for which we have read
permission, regardless of whether we own the objects. On some UNIX implementa-
tions, ipcs shows the same behavior as on Linux. However, on other implementations,
ipcs displays all objects regardless of whether read permission is granted to the user.
By default, for each object, ipcs displays the key, the identifier, the owner, and
the permissions (expressed as an octal number), followed by information specific
to the object:
z
For shared memory, ipcs displays the size of the shared memory region, the num-
ber of processes that currently have the shared memory region attached to their
virtual address space, and status flags. The status flags indicate whether the region
has been locked into RAM to prevent swapping (Section 48.7) and whether the
region has been marked to be destroyed when all processes have detached it.
z
For semaphores, ipcs displays the size of the semaphore set.
z
For message queues, ipcs displays the total number of bytes of data and the
number of messages in the queue.
The ipcs(1) manual page documents various options for displaying other informa-
tion about IPC objects.
The ipcrm command deletes an IPC object. The general form of this command
is one of the following:
$ ipcrm -X key
$ ipcrm -x id
In the above, we either specify key as an IPC object key or id as an IPC object identifier,
and the letter x is replaced by an uppercase or lowercase q (for message queues),
s (for semaphores), or m (for shared memory). Thus, we could use the following
command to delete the semaphore set with the identifier 65538:
$ ipcrm -s 65538
Introduction to System V IPC
Chia sẻ với bạn bè của bạn: |