A process alone can do a certain things, but not everything. It will be a very useful and good resource utilization if two or more processes can communicate with each other in the form of sharing results, sending or receiving messages, and so on. In a Linux or Unix-based operating system, two or more processes can communicate with each other using IPC.
IPC is the technique by which processes communicate with each other and are managed by kernel.
IPC is possible to do by any of the following ways:
While discussing named pipes in Chapter 6, Working with Files, we learned how processes can communicate using named pipes.
The ipcs
command provides information about IPC facilities for which a calling process has the read access. It can provide information on three resources: shared memory, message queue, and semaphore.
The syntax of using ipcs
is as follows:
ipcs option
Where options are as follows:
Option |
Description |
---|---|
|
Displays information for all resources—shared memory, message queue, and semaphore |
|
Displays information about active message queues |
|
Displays information about active shared memory segments |
|
Displays information about active semaphore sets |
|
Shows the detailed information for an ID. Use it with the |
|
Shows resource limits |
|
Shows PIDs of the resource creator and last operator |
|
Prints sizes in bytes |
|
Print sizes in a human-readable format |
We can use the ipcs
command without an option or with –a
:
$ ipcs
OR
$ ipcs -a
To see only the shared memory segment, we can use ipcs
with the –m
option:
$ ipcs -m --human
Here, the --human
option made a size column in a more readable format by providing the size in KB and MB instead of giving it in bytes.
To find out detailed information about a resource ID, use ipcs
with the -i
option followed by the resource ID:
$ ipcs -m -i 393217
We can know the PID of the processes that have recently accessed a specific IPC resource using the -p
option:
$ ipcs -m -p
Here, the cpid
column shows pid
of the processes that created the shared memory resource, and lpid
refers to the PID of the processes that last accessed the shared memory resource.
13.59.75.169