apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel May" <dan...@spryware.com>
Subject RE: apr_proc_trylock for linux
Date Mon, 15 May 2006 21:21:31 GMT
We specifically use it for demon like processes under Windows and Linux
where we need to limit a single instance to run.  Let's say for instance
you have a demon that is the sole creator of a shared memory segment, or
any other resource that you want to create once and share among other
processes.

In the Windows world, the common practice is:


//this code is from Microsoft KB Q243953 
main()
{
   char *strMutexName = "AUniqueNameForThisApp"; // should use a GUID
here 
   HANDLE hMutex = CreateMutex(NULL, FALSE, strMutexName); 
   DWORD  dwLastError = GetLastError(); 

   if(ERROR_ALREADY_EXISTS == dwLastError)
	return 1;

   ...

   if(hMutex)
	CloseHandle(hMutex); //do as late as possible
   return 0;
}



/Daniel

-----Original Message-----
From: William A. Rowe, Jr. [mailto:wrowe@rowe-clan.net] 
Sent: Monday, May 15, 2006 2:08 PM
To: Hans-Peter Weidinger
Cc: Chris Darroch; dev@apr.apache.org
Subject: Re: apr_proc_trylock for linux

Hans-Peter Weidinger wrote:
> Hi Chris,
> 
> thanks for the info. I feared that the trylock will not be available 
> for unixes (especially linux) permanently.

There's alot of work to do on the lock portability for APR 2.0, and
several changes that can be applied even before APR 2 is released.  (We
don't change our ABI within the version, e.g. existing APR-0 and APR-1
functions are set in stone.)

In any case, I read the first post in this thread and thought OMG - if
this even is supposed to work, it's certainly not a portable test for
multiple instances of the same program running.

So what I'm hearing is a cry for some apr_app_proc_instance() function
of some sort, which would minimally report that another process of the
same application is already running, and preferably provide some
apr_proc_t to reflect what the original process was.

Since most unix boxes and applications are very happy to have multiple
instances of the same application in use at the same time, can you help
clarify what this sort of API accomplishes or is used for?

Bill


Mime
View raw message