Comment 7 for bug 1327946

Revision history for this message
Davanum Srinivas (DIMS) (dims-v) wrote :

k. based on a tip in [1]. It looks like we can set the value of the semaphore to the pid() and retrieve it when needed to check if the other process is still active. Here's a code snippet

vagrant@bosh-lite:/tmp$ python
Python 2.7.3 (default, Feb 27 2014, 19:58:35)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import posix_ipc
>>> import os
>>> a = posix_ipc.Semaphore("xyz002",flags=posix_ipc.O_CREAT,initial_value=os.getpid())
>>> print a.value
1233
>>> a.acquire
<built-in method acquire of posix_ipc.Semaphore object at 0x14206e8>
>>>
vagrant@bosh-lite:/tmp$ python
Python 2.7.3 (default, Feb 27 2014, 19:58:35)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import posix_ipc
>>> import os
>>> a = posix_ipc.Semaphore("xyz002",flags=posix_ipc.O_CREAT,initial_value=os.getpid())
>>> print os.getpid()
25901
>>> print a.value
1233
>>>

[1] http://osdir.com/ml/darwin-kernel/2009-03/msg00029.html