Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In shared memory system, when two processes share a shared memory segment, after one process is killed, how will the other running process be notified of the killed process by the shared memory system ?

share|improve this question
On which unix variants, and which shared memory system? – Gilles Jan 31 '12 at 23:45
There is no "built-in" asynchronous notification if that's what you're looking for. How are processes "killed?" legacy code? new code? I've always used a control struct located in shm, each and any process is responsible for updating their status with a timestamp, other processes, or a controlling "agent" monitor and respond to changes. – bsd Feb 1 '12 at 13:25

The only way you could handle this would be to have some kind of heartbeat system between the processes. For instance the first process could share its PID in shared memory.

Subsequent processes could announce themselves by sending a signal such as SIGUSR1. Then they could keep sending SIGUSR2 at intervals as a heartbeat. Two missing SIGUSR2 signals in a row would tell you that the process had died. You would need to use sigqueue(2) sigaction(2) to communicate the PID of the signal sender for this to work.

Another way is to arrange for the other sharing processes to be children of the first process to access the shared memory. Then the death of a child results in an automatic SIGCHLD to the parent. Even if you currently have the sharing processes started independently, you could change those to signal the first process that a new process wants to share memory. Then the first process could fork a new child to take over the activity of the process that wants to share memory, thus preserving the parent/child relationship.

Personally, I would first look at a more modern IPC method such as 0MQ (go here and read the guide) before I would try to implement this with UNIX kernel services. I would even give up on shared memory, and use memcache to share the data. In fact I have implemented a system with several processes using 0MQ for heartbeats and IPC and sharing memory via memcache.

share|improve this answer
Thanks so much Michael Dillon. – mav_2k Mar 1 '12 at 8:01

It isn't. Processes can attach and detach to the shared memory segment at any time and no notification is given to other attached processes ( if there even are any ).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.