apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Darroch <chr...@pearsoncmg.com>
Subject Re: apr_proc_trylock for linux
Date Mon, 15 May 2006 14:41:12 GMT
Hans-Peter Weidinger wrote:

> @anyone on the list:
> Does anyone know, if apr_proc_trylock a subject to be added for linux (i 
> could live with that) or is this permanent?

   The APR trunk now contains a set of trylock functions for Unixes;
by all means give them a test run.  There are five possible underlying
locking mechanisms, not all of which are available on every Unix
platform; APR configuration will choose a default one.  Some of these
mechanisms recover gracefully after a process dies while holding
a lock, and others do not.  My own tests are summarized here:


(I believe the latest Linux kernels with a bleeding-edge libc
have pthread semantics more like Solaris, BTW.)

   That all said, process mutexes may not serve your purpose ...

Danial May wrote:

> The apr proc mutex's seem to favor being inherited rather than working
> between two unrelated processes.

   Yes, and the child process should call apr_proc_mutex_child_init()
before trying to use any process mutexes.  (In practice, this is
because one of the five possible Unix locking mechanisms, flock(),
requires initialization.  So does OS/2, it seems.)

   To be platform agnostic, therefore, this call should always be made;
that in turn implies that unrelated processes can't share locks.  See
the remarks under:


> Intention: If a second instance of the process is started, the command 
> line parameter should be given to the first
> instance and then terminate immediately.

   Just as a suggestion, could you do something like what Apache httpd
does to achieve this?  The running process writes its process ID into
a file and it removes the file when it exits.  If another process is
started, it reads the pid from the file and send an appropriate signal
(based on the command line parameters) to the running process, then


GPG Key ID: 366A375B
GPG Key Fingerprint: 485E 5041 17E1 E2BB C263  E4DE C8E3 FA36 366A 375B

View raw message