XSI IPC (System V IPC)
XSI IPC, commonly known as System V IPC, is a collection of inter-process communication mechanisms introduced in UNIX System V. Unlike pipes and FIFOs, System V IPC provides persistent kernel-managed IPC objects that enable complex communication and synchronization between unrelated processes.
Learning Objectives
- Understand System V IPC.
- Learn the history of XSI IPC.
- Study IPC keys and identifiers.
- Understand
ftok(). - Learn kernel IPC objects.
- Prepare for Message Queues, Semaphores and Shared Memory.
1. What is XSI IPC?
XSI IPC (X/Open System Interfaces IPC), commonly referred to as System V IPC, is a set of operating system facilities that allow processes to communicate and synchronize through kernel-managed objects. The three IPC mechanisms are:
- Message Queues
- Semaphores
- Shared Memory
Each mechanism is independent and serves different communication requirements.
2. History of System V IPC
System V IPC first appeared in AT&T UNIX System V and was later adopted into the X/Open standards and POSIX XSI option. Modern UNIX and Linux systems continue to support System V IPC for backward compatibility and enterprise applications.
| Technology | Purpose |
|---|---|
| Message Queues | Message passing |
| Semaphores | Synchronization |
| Shared Memory | High-speed data sharing |
3. Components
Each IPC mechanism maintains its own kernel objects and system calls.
4. IPC Keys (key_t)
System V IPC objects are identified using a key of type
key_t.
The key allows unrelated processes to locate the same IPC object.
5. Why IPC Keys are Needed
| Requirement | Reason |
|---|---|
| Object Discovery | Locate an existing IPC object. |
| Object Creation | Create a new IPC object. |
| Sharing | Allow multiple processes to reference the same object. |
| Persistence | Objects remain until explicitly removed. |
6. ftok()
The ftok() function generates a System V IPC key
from a pathname and a project identifier.
| Parameter | Description |
|---|---|
| pathname | Existing file used as input. |
| proj_id | Project identifier. |
7. IPC Identifier (ID)
Once a kernel IPC object is created, the kernel assigns an IPC identifier (ID). Applications use this identifier in subsequent system calls rather than the original key.
8. Kernel IPC Objects
The kernel stores System V IPC objects in dedicated internal tables. Each object contains:
- IPC Identifier
- Owner Information
- Permissions
- Status Information
- Resource Data
9. Advantages of XSI IPC
- Supports unrelated processes.
- Persistent kernel objects.
- Efficient synchronization.
- High-performance shared memory.
- Widely supported across UNIX systems.
10. Interview Questions
- What is XSI IPC?
- What are the three System V IPC mechanisms?
- Why are IPC keys required?
- What is
key_t? - What is the purpose of
ftok()? - What does the kernel return after creating an IPC object?
- Can unrelated processes use System V IPC?
- What information is stored in an IPC object?
- Why is System V IPC still widely used?
- What is the difference between an IPC key and an IPC identifier?
11. Creating System V IPC Objects
Each System V IPC mechanism provides a dedicated system call for creating or locating an existing IPC object.
| IPC Mechanism | System Call |
|---|---|
| Message Queue | msgget() |
| Semaphore Set | semget() |
| Shared Memory | shmget() |
12. msgget()
The msgget() system call creates a new message queue or
obtains the identifier of an existing one.
On success, the kernel returns a message queue identifier.
13. semget()
The semget() system call creates a semaphore set or
returns the identifier of an existing semaphore set.
14. shmget()
The shmget() system call creates a shared memory segment
or returns the identifier of an existing one.
15. IPC Creation Flags
| Flag | Purpose |
|---|---|
IPC_CREAT |
Create the object if it does not already exist. |
IPC_EXCL |
Used with IPC_CREAT to ensure exclusive creation. |
IPC_PRIVATE |
Create a new private IPC object. |
16. IPC_CREAT
When IPC_CREAT is specified, the kernel creates the IPC
object if no object currently exists for the supplied key.
If an object with the same key already exists, its identifier is
returned instead.
17. IPC_EXCL
The IPC_EXCL flag is meaningful only when combined with
IPC_CREAT.
If an IPC object already exists for the specified key, the system call
fails instead of returning the existing identifier.
18. IPC_PRIVATE
IPC_PRIVATE is a special key value that always requests
creation of a new IPC object.
The kernel ignores pathname-based key generation for this request.
19. ipc_perm Structure
Every System V IPC object contains an
ipc_perm structure that stores ownership and access
control information.
| Field | Purpose |
|---|---|
| Owner UID | Object owner. |
| Owner GID | Owner group. |
| Mode | Permission bits. |
| Key | Associated IPC key. |
20. IPC Object Creation Workflow
21. Linux IPC Commands
| Command | Description |
|---|---|
ipcs |
Display System V IPC objects. |
ipcs -q |
Show message queues. |
ipcs -m |
Show shared memory segments. |
ipcs -s |
Show semaphore sets. |
lsipc |
Display detailed IPC information. |
ipcrm |
Remove IPC objects. |
22. Interview Questions
- Which three system calls create System V IPC objects?
- What is the purpose of
IPC_CREAT? - Why is
IPC_EXCLused withIPC_CREAT? - What is the meaning of
IPC_PRIVATE? - What information is stored in
ipc_perm? - What happens if an IPC object already exists and only
IPC_CREATis specified? - Which command lists all IPC objects?
- Which command removes a message queue?
- How does the kernel assign IPC identifiers?
- Why are IPC permissions important?
23. IPC Permission Bits
System V IPC objects use UNIX-style permission bits to control access. Permissions determine whether a process may read from, write to, or modify an IPC object.
| Permission | Description |
|---|---|
| 0400 | Owner Read |
| 0200 | Owner Write |
| 0040 | Group Read |
| 0020 | Group Write |
| 0004 | Others Read |
| 0002 | Others Write |
24. Ownership and Access Control
Every IPC object records ownership information inside its
ipc_perm structure.
The kernel checks these permissions whenever a process attempts to
access an IPC object.
25. msgctl()
The msgctl() system call performs control operations on a
message queue.
| Common Command | Description |
|---|---|
IPC_STAT |
Retrieve queue information. |
IPC_SET |
Modify permissions or ownership. |
IPC_RMID |
Remove the message queue. |
26. semctl()
The semctl() system call controls semaphore sets.
It can retrieve status, modify permissions, initialize semaphore values, and remove semaphore sets.
27. shmctl()
The shmctl() system call performs control operations on a
shared memory segment.
28. Removing IPC Objects
System V IPC objects remain in the kernel until explicitly removed.
The control system calls support the
IPC_RMID command for object removal.
29. IPC Status Information
Applications can retrieve information about IPC objects using the
IPC_STAT command.
Typical information includes:
- Owner UID and GID
- Permission bits
- Creation time
- Last access time
- Object size or usage statistics
30. Example: Creating a Message Queue
31. Linux Administration Commands
| Command | Description |
|---|---|
ipcs -a |
Display every IPC object. |
ipcrm -q <id> |
Remove a message queue. |
ipcrm -m <id> |
Remove shared memory. |
ipcrm -s <id> |
Remove semaphore set. |
lsipc -J |
Display IPC information in JSON format (Linux). |
32. Advanced Interview Questions
- Which structure stores System V IPC permissions?
- What is the purpose of
IPC_STAT? - How are IPC objects removed?
- Which APIs belong to the control family?
- What information can be retrieved using
IPC_STAT? - Can IPC permissions be modified after object creation?
- Why do IPC objects remain after processes terminate?
- Which Linux command lists all active IPC objects?
- How do you delete a shared memory segment?
- Why should applications remove unused IPC objects?
33. System V IPC Architecture
System V IPC objects reside inside the kernel. Processes reference these objects using kernel-assigned IPC identifiers after locating them through a common key.
34. System V IPC Lifecycle
Unlike pipes and FIFOs, System V IPC objects continue to exist after the creating process exits until they are explicitly removed.
35. System V IPC vs POSIX IPC
| Feature | System V IPC | POSIX IPC |
|---|---|---|
| Identification | key_t + IPC ID | Pathname-like Name |
| Object Creation | msgget(), semget(), shmget() | mq_open(), sem_open(), shm_open() |
| Persistence | Until IPC_RMID | Until unlink operation |
| Permission Model | ipc_perm | UNIX File Permissions |
| Standard | XSI (System V) | POSIX.1 |
| Typical Usage | Legacy Enterprise Applications | Modern UNIX/Linux Applications |
36. Common Programming Mistakes
- Forgetting to remove IPC objects.
- Ignoring return values from IPC system calls.
- Using incorrect permission bits.
- Using different keys in cooperating processes.
- Assuming IPC objects disappear when a process exits.
- Failing to initialize IPC resources before use.
- Not handling permission errors.
37. Debugging Tips
| Problem | Possible Cause |
|---|---|
| Object already exists | IPC object not removed previously. |
| Permission denied | Incorrect ipc_perm permissions. |
| Cannot locate object | Different key generated by ftok(). |
| Kernel resource leak | Missing IPC_RMID operation. |
| Unexpected IPC ID | Existing object reused by kernel. |
38. Best Practices
- Generate consistent IPC keys.
- Check every IPC system call for errors.
- Use
IPC_EXCLwhen exclusive creation is required. - Assign appropriate permissions during object creation.
- Remove unused IPC objects using
IPC_RMID. - Document key-generation strategy for cooperating applications.
- Monitor IPC resources using Linux administration tools.
39. Advanced Interview Questions
- Explain the complete lifecycle of a System V IPC object.
- Why are IPC keys different from IPC identifiers?
- What is the purpose of
ftok()? - How does
IPC_EXCLprevent duplicate object creation? - Why do System V IPC objects survive process termination?
- When should
IPC_PRIVATEbe used? - What are the advantages of kernel-managed IPC objects?
- How can orphaned IPC objects be detected?
- How do System V IPC permissions differ from POSIX IPC?
- When would you choose System V IPC over POSIX IPC?
40. Module Summary
This module introduced the System V (XSI) IPC framework used by UNIX
systems. We studied IPC keys, the ftok() function,
kernel-managed IPC identifiers, creation APIs
(msgget(), semget(),
shmget()), control APIs
(msgctl(), semctl(),
shmctl()), permission management, lifecycle,
administration commands, debugging techniques, and best practices.
The following modules examine each IPC mechanism in greater detail,
followed by the POSIX IPC interfaces that provide standardized
alternatives.
Concept Mastery Assessment — Module 42
Verify your conceptual understanding with 12 targeted technical assessment questions. Instant feedback and explanations are provided for every choice.