RE: [fpc-pascal] single application instance

2005-10-05 Thread Jose Pascual
any example of implementation for semaphore in linux which I can use to
know if there is
some instance of my program already running?

 -Mensaje original-
 De: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] En nombre de 
 Matt Emson
 Enviado el: viernes, 23 de septiembre de 2005 18:53
 Para: FPC-Pascal users discussions
 Asunto: Re: [fpc-pascal] single application instance
 
 
  Semaphores  Mutexes. Semaphores do not always have names 
 and are not 
  system-wide.
 
 In my experience, its the other way round. Semaphores are 
 system wide/cross process. Admittedly, they are not always 
 named though.
 
 ___
 fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
 http://lists.freepascal.org/mailman/listinfo/fp c-pascal
 
 
 __ Información de NOD32, revisión 1.1230 
 (20050922) __
 
 Este mensaje ha sido analizado con  NOD32 antivirus system 
http://www.nod32.com


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] single application instance

2005-09-23 Thread Alexey Pavluchenko
Hello Jose,

Thursday, September 22, 2005, 1:20:48 PM, you wrote:

JP How can avoid to run my program more than once?

I suppose you wanted to ask how can I allow only one instance of my
program running under Win32. Correct me if I'm wrong. If I'm right,
then you may do it like this: check for named mutex with the name
unique to your program, if it does not exist then create it, if it
does then terminate the program. The following code is from APPINIT
unit written by Marc Batchelor:

=== cut ===
procedure InitInstance;
begin
  { Check to see if the mutex is already there }
  InstanceMutexHandle := OpenMutex(MUTEX_ALL_ACCESS, false,
@UniqueApplicationString[1]);
  if InstanceMutexHandle = 0 then
  begin
{ This is the first instance }
InstanceMutexHandle := CreateMutex(nil, false,
  @UniqueApplicationString[1]);
{ Error checking to see if anyone beat us... }
if InstanceMutexHandle = 0 then
  IsFirstInstance := false
else
  IsFirstInstance := true;
  end
  else
IsFirstInstance := false;
end;
=== cut ===

UniqueApplicationString in the above example is a shortstring, if you
use ansistring then you don't need '@' operator and '[1]' index, just
typecast it to pchar. The string should be unique system-wide so it is
probably best to generate it based on some pseudo-random numbers.

-- 
Best regards,
 Alexey


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


RE: [fpc-pascal] single application instance

2005-09-23 Thread Jose Pascual
Hi Alexey,

thank you for your answer, I'm thinking about some portable solution for
win32 and linux?
How can I also do it in linux?

tia!
best regards


 -Mensaje original-
 De: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] En nombre de 
 Alexey Pavluchenko
 Enviado el: viernes, 23 de septiembre de 2005 10:35
 Para: FPC-Pascal users discussions
 Asunto: Re: [fpc-pascal] single application instance
 
 
 Hello Jose,
 
 Thursday, September 22, 2005, 1:20:48 PM, you wrote:
 
 JP How can avoid to run my program more than once?
 
 I suppose you wanted to ask how can I allow only one 
 instance of my program running under Win32. Correct me if 
 I'm wrong. If I'm right, then you may do it like this: check 
 for named mutex with the name unique to your program, if it 
 does not exist then create it, if it does then terminate the 
 program. The following code is from APPINIT unit written by 
 Marc Batchelor:
 
 === cut ===
 procedure InitInstance;
 begin
   { Check to see if the mutex is already there }
   InstanceMutexHandle := OpenMutex(MUTEX_ALL_ACCESS, false,
 @UniqueApplicationString[1]);
   if InstanceMutexHandle = 0 then
   begin
 { This is the first instance }
 InstanceMutexHandle := CreateMutex(nil, false,
   @UniqueApplicationString[1]);
 { Error checking to see if anyone beat us... }
 if InstanceMutexHandle = 0 then
   IsFirstInstance := false
 else
   IsFirstInstance := true;
   end
   else
 IsFirstInstance := false;
 end;
 === cut ===
 
 UniqueApplicationString in the above example is a 
 shortstring, if you use ansistring then you don't need '@' 
 operator and '[1]' index, just typecast it to pchar. The 
 string should be unique system-wide so it is probably best to 
 generate it based on some pseudo-random numbers.
 
 -- 
 Best regards,
  Alexey
 
 
 ___
 fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
 http://lists.freepascal.org/mailman/listinfo/fp c-pascal
 
 
 __ Información de NOD32, revisión 1.1230 
 (20050922) __
 
 Este mensaje ha sido analizado con  NOD32 antivirus system 
http://www.nod32.com


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] single application instance

2005-09-23 Thread Matt Emson
 How can I also do it in linux?

Use semaphores. There is a semaphore implementation for LINUX, Windows, BeOS
and probably most other Unices. Certainly, any platform that conforms to
POSIX and/or PThreads will have a semaphore implementation.

The mechanics will be different - the idea will be universal.

M

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] single application instance

2005-09-23 Thread Micha Nelissen
On Fri, 23 Sep 2005 17:16:36 +0100
Matt Emson [EMAIL PROTECTED] wrote:

  How can I also do it in linux?
 
 Use semaphores. There is a semaphore implementation for LINUX, Windows, BeOS

Semaphores  Mutexes. Semaphores do not always have names and are not
system-wide.

Micha
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] single application instance

2005-09-23 Thread Marco van de Voort
  How can I also do it in linux?
 
 Use semaphores. There is a semaphore implementation for LINUX, Windows, BeOS
 and probably most other Unices. Certainly, any platform that conforms to
 POSIX and/or PThreads will have a semaphore implementation.
 
 The mechanics will be different - the idea will be universal.

For *nix it is in unit ipc.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] single application instance

2005-09-22 Thread Jose Pascual
Hi,

How can avoid to run my program more than once?

thank you in advanced


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal