
How Linux Processes Communicate and Coordinate Work
Linux IPC is a set of distinct ways for processes to exchange data and coordinate work. There is no universal interface worth forcing onto every problem. Use a pipe for a stream between related processes, a Unix socket for a local client-server connection, and shared memory only when you’re prepared to manage synchronization yourself. Then check the actual system calls and errors with strace and logs; a copied fix won’t tell you why the process is stuck.
Last updated: 2026-11-11
What Is IPC in Linux?
IPC means interprocess communication. It covers both moving information between processes and coordinating when those processes can act.
Processes have separate address spaces. A child created with fork() starts with a separate view of memory, so changing a variable in one process doesn’t update the other. IPC provides ways to pass data, share mapped memory, send notifications, or control access to a resource.
Those jobs are related, but they aren’t interchangeable. A semaphore can coordinate access to shared memory, but it doesn’t carry the data. A signal can tell a process to stop or reload, but it isn’t a reliable message queue. Keep data transfer, synchronization, and notification separate when choosing an interface.
The right mechanism depends on who needs to communicate, what shape the data has, and what should happen if one side exits. That’s the useful starting point for linux ipc.
Linux IPC mechanisms and methods
Pick the simplest mechanism that handles the data and failure cases you have. More machinery means more lifecycle rules to get wrong.
| Mechanism | Good fit | Main trade-off |
|---|---|---|
| Pipes | A byte stream between related processes, often after fork() | Usually one-way; open write ends can keep readers blocked |
| FIFOs | A byte stream between unrelated processes on one host | Path-based setup; opening can block until the other side opens it |
| Unix domain sockets | Local client-server communication and bidirectional data | Stream sockets need message framing |
| Network sockets | Communication across machines or network namespaces | Requires a network protocol and connection handling |
| Signals | Shutdown, reload, and lightweight notification | Standard signals don’t carry a data stream and can coalesce |
| Message queues | Buffered records with message selection or priority | Queue limits and cleanup need attention |
| Semaphores | Coordinating access to shared resources | Synchronization only; incorrect waits can block indefinitely |
| Shared memory | Large or frequent data exchange on one host | Processes must design their own synchronization and data layout |
Pipes are a good default for shell pipelines and parent-child streams. On Linux, PIPE_BUF is 4096 bytes; writes up to that size have atomicity guarantees with respect to other writers. That doesn’t make a pipe a record protocol. Readers still receive a byte stream and need to handle partial reads.
Use a FIFO when unrelated local processes need a simple stream and a filesystem path is useful. Use a Unix domain socket when you need two-way communication, client-server behavior, or file-descriptor passing. Linux Unix domain sockets support SCM_RIGHTS ancillary messages for sending open file descriptors between processes.
Network sockets are the right choice when communication must cross a host boundary. They also make sense when the same protocol may later need remote clients. Don’t choose one just because “sockets scale”; a local Unix socket is often easier to secure and debug when both processes live on the same machine.
Signals are for events, not payloads. Message queues preserve message boundaries and can select or prioritize messages. Shared memory avoids sending every byte through a message interface, but it gives you the job of coordinating readers and writers.
For readiness-driven socket handling, see Linux poll and epoll. The same rule applies there: choose an interface because its behavior fits the problem, not because a benchmark headline said it was fastest.
A Linux IPC tutorial: from creation to cleanup
Start by writing down the data path and the cleanup path. If you can’t say who creates the resource, who opens it, and who removes it, the design isn’t ready.
- Choose the data model. Use a stream for bytes, a queue for separate messages, or shared memory for a region both processes map. Add a separate synchronization mechanism when shared state needs coordinated access.
- Choose the scope. Pipes usually suit related processes. FIFOs, Unix sockets, POSIX queues, and POSIX shared memory can connect unrelated processes on one host. Network sockets cross hosts.
- Create the resource and check the result. System calls and library calls can fail because of permissions, resource limits, missing paths, or invalid arguments. Check the return value and
errnoimmediately. Don’t treat “the other process probably started” as proof that attachment worked. - Check access and isolation. Inspect the owner and mode of filesystem-based resources. Also check whether the processes share the same mount or IPC namespace. A resource can exist and still be invisible from the other process’s namespace.
- Attach both sides and handle blocking. Decide what a reader does when there is no data, what a writer does when the receiver exits, and how shutdown wakes a blocked process. A blocked call is not automatically a deadlock; trace it before changing the design.
- Clean up according to the interface. Close file descriptors when a process is done with them. Unlink named resources when their owners are finished. Remove System V objects explicitly when they should not persist.
Permissions deserve a deliberate check. A world-writable socket or shared-memory object may make a test pass while leaving an unintended access path. Set ownership and mode to match the processes that should connect, then verify those settings from both sides.
Namespaces can also explain “it exists here but not there.” Linux IPC namespaces isolate System V IPC objects and POSIX message queues. Mount namespaces can make filesystem paths, including named sockets and shared-memory mounts, differ between processes.
For process creation details, see how fork and vfork change memory sharing. For descriptor ownership and cleanup, use the Linux file descriptor model.
System V and POSIX message queues

Use a message queue when the receiver needs complete records, buffering, or message selection. Don’t pick one just because the word “queue” sounds safer than a socket. You still need to handle limits, permissions, and stale objects.
POSIX message queues use names and descriptors. Programs create or open a queue with mq_open(), send messages with mq_send(), and receive them with mq_receive(). A receiver can request a message buffer, but the queue determines which message comes first.
mq_receive() removes the oldest message with the highest priority from the queue, then places it in the provided buffer. POSIX message priorities range from 0, low priority, to sysconf(_SC_MQ_PRIO_MAX) - 1, high priority. A steady flow of high-priority messages can delay lower-priority work, so don’t use priority as decoration.
System V message queues use numeric keys and message types. A receiver can select messages by type, which can be useful when maintaining an existing application with that design. However, System V objects can outlive their creator, so a process crash may leave a queue behind.
Check active System V message queues with ipcs -q. Remove an abandoned queue only after confirming its owner and users; deleting a live queue is a fast way to turn a diagnosis into an outage. POSIX queues also have lifecycle rules: close descriptors when finished, and unlink the queue name when no process should open it again.
For new code, choose POSIX queues when their named interface and priority behavior fit the design. Keep System V queues when compatibility or an existing deployment requires them. Replacing a working interface just to make it look newer is not a reliability plan.
Semaphores for process synchronization
Semaphores coordinate access; they don’t carry application data. Use one when processes need to signal availability or protect a shared resource, and be explicit about who posts, who waits, and what happens if a process exits at the wrong time.
System V semaphores operate on sets and use semop() for operations. POSIX offers named semaphores through sem_open() and unnamed semaphores through sem_init(). Named semaphores suit unrelated processes that need a shared name. Unnamed semaphores can live in shared memory when the processes share that region.
The main failure is a wait that never completes. One process may exit without posting, the initial semaphore value may be wrong, or shutdown may leave another process blocked. Log the operation and its result. Then trace the wait instead of adding sleeps until the problem disappears.
Named POSIX semaphores need sem_close() when a process is done with its handle and sem_unlink() when the name should be removed. Unnamed semaphores need sem_destroy() after no process can use them. System V objects need explicit removal when they should not persist.
System V semaphore limits are kernel configuration details, not universal design targets. For example, a Red Hat Enterprise Linux recommendation for Oracle databases says the maximum semaphores per set should be at least 250. That guidance is specific to that environment; it is not a general Linux requirement.
Shared memory requires explicit coordination

Shared memory is useful when copying data through repeated send and receive calls costs too much. It is also where a fast design can turn into a data-corruption bug.
On Linux, POSIX shared-memory objects are normally created in a tmpfs filesystem mounted under /dev/shm. Processes open the object, size it, and map it into their address spaces. The mapping gives both processes access to the same region; it does not tell them when a write is complete or whether a reader has seen consistent data.
Define the layout before either process uses the region. Agree on field sizes, offsets, versioning, ownership, and how to represent an empty or incomplete record. Then use a semaphore, process-shared mutex, or another deliberate synchronization method. A shared pointer is usually not useful across processes because each process may map the region at a different address.
Cleanup has two parts. Close each process’s handle and unmap its region when finished; unlink the shared-memory name when new processes should no longer attach. On Linux, POSIX shared-memory objects normally appear under /dev/shm, which helps with inspection but doesn’t replace correct cleanup.
System V shared memory has different calls and lifecycle rules. Its kernel limits are configurable, so don’t copy a shmmax value from a different machine and assume it applies. Check the running system and the application’s actual request before changing kernel settings.
Linux IPC system calls, signals, and observability
The system-call boundary tells you what the process actually asked the kernel to do. A call that blocks, returns an error, or gets interrupted is more useful evidence than a vague report that “IPC stopped working.”
Common interfaces include pipe(), read(), and write() for pipes; mkfifo() for FIFOs; socket(), connect(), sendmsg(), and recvmsg() for sockets; and mmap() for mapping shared memory. POSIX queues and semaphores use their own library interfaces, which may enter the kernel through different calls.
Use strace to follow those operations. The -f flag follows child processes created through fork(), vfork(), and clone() by processes already being traced. That matters when the call that hangs happens in a child rather than the process you first attached to.
strace -f -e trace=read,write,sendmsg,recvmsg,connect,accept,mmap -p PID
Check the output for the exact call that blocks or fails. A read() waiting for input points to a different problem than connect() returning an error. For process and system-call background, see the Linux system calls tutorial.
Signals fit into IPC as notifications. Use them for events such as reload or shutdown, then send the actual data through a pipe, socket, queue, or shared region. Standard signals do not queue repeated instances while blocked: multiple deliveries of the same blocked standard signal can become one pending instance. Don’t count them as messages.
A signal handler can interrupt the process at an inconvenient point. Keep its work limited to what is safe in that context; a common pattern is to set a volatile sig_atomic_t flag and handle the event in the main loop. See the signal handling guide before putting I/O or cleanup logic in a handler.
Diagnose Linux IPC failures at the source

Trace the failing operation before changing permissions, limits, or cleanup code. First reproduce the problem, then identify which process is waiting and what call it is waiting in.
Run strace -f when child processes are involved. Check the application logs for the operation and error, and use journalctl if a systemd unit is part of the failure. For kernel messages, read dmesg; the kernel ring buffer can show resource or driver errors that an application log misses.
Check resources with the tool that matches the interface. ipcs -q reports active System V message queues. ipcs -s and ipcs -m show semaphore sets and shared-memory segments. For filesystem-based endpoints, inspect the path’s owner, mode, and namespace visibility. Also check open file descriptors: an extra pipe writer can prevent EOF, while a process that closed a socket may leave its peer waiting for a protocol-level response.
Then fix the cause. If the call blocks because a writer still holds a pipe descriptor, close that descriptor in the right process. If a queue or shared-memory object has the wrong permissions, correct its ownership and mode. If a process waits forever on a semaphore, establish which path should post it and what happens when that path exits.
Generic recipes tend to hide the failure until it returns. When the trace doesn’t explain the behavior, check the relevant kernel interface and source. Know what the operation does, what it returns, and which process owns the resource before changing system-wide settings.
FAQ
Which IPC mechanism should I learn first?
Start with pipes and Unix domain sockets. Pipes teach you stream behavior and descriptor ownership; sockets cover local client-server communication and bidirectional data. Add queues or shared memory when the problem requires their specific behavior.
Can two unrelated processes use a pipe?
An ordinary anonymous pipe is usually set up by one process and inherited by related processes. For unrelated processes, use a FIFO or a Unix domain socket, depending on whether you need a simple stream or a fuller local connection.
Why can a shared-memory program still be slow?
Sharing the bytes doesn’t remove work such as locking, cache contention, or waiting for another process. Measure the complete path. Shared memory only helps when data exchange is the actual bottleneck and coordination is designed well.
How do I tell whether an IPC object is stale?
Check which processes still use it before removing it. System V objects can be listed with ipcs; filesystem-based resources can be inspected by path and open descriptors. A resource that looks old may still belong to a live process.
