Re: [lazarus] avoiding multi-instance detection

2006-10-03 Thread Ales Katona
/var/run with pids is also present in FreeBSD 5.x+

But it's just a dumpspace for these things..

It still doesn't add anything useful :) I think there's some syscall to
do what ps does basicly. Might be worth looking at, that way you won't
depend on external crap.

Ales

 At least FreeBSD 4 has a pid-file in /var/run:
 
 $ ls /var/run/
 cron.pidemacs   ld.so.hints ppp sshd.pid
 dev.db  inetd.pid   log printer syslog.pid
 dhcpd   isdnd.pid   mountd.pid  run utmp
 dmesg.boot  ld-elf.so.hints moused.pid  sendmail.pid
 
 $ cat /var/run/cron.pid
 122
 
 $ ps aux|grep cron
 root 122  0,0  0,1  1056  768  ??  Ss   12:14am   0:00,00 /usr/sbin/cron
 
 Don't know about os version 5 or 6 or 7 though ...
 
 HTH,
 Marc
 
 _
  To unsubscribe: mail [EMAIL PROTECTED] with
 unsubscribe as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-10-03 Thread Alexsander Rosa

The /var/run solution is almost canonic for Linux.
But how to do this in a multi-platform way?

2006/10/3, Ales Katona [EMAIL PROTECTED]:

/var/run with pids is also present in FreeBSD 5.x+

But it's just a dumpspace for these things..

It still doesn't add anything useful :) I think there's some syscall to
do what ps does basicly. Might be worth looking at, that way you won't
depend on external crap.

Ales

 At least FreeBSD 4 has a pid-file in /var/run:

 $ ls /var/run/
 cron.pidemacs   ld.so.hints ppp sshd.pid
 dev.db  inetd.pid   log printer syslog.pid
 dhcpd   isdnd.pid   mountd.pid  run utmp
 dmesg.boot  ld-elf.so.hints moused.pid  sendmail.pid

 $ cat /var/run/cron.pid
 122

 $ ps aux|grep cron
 root 122  0,0  0,1  1056  768  ??  Ss   12:14am   0:00,00 /usr/sbin/cron

 Don't know about os version 5 or 6 or 7 though ...

 HTH,
 Marc

 _
  To unsubscribe: mail [EMAIL PROTECTED] with
 unsubscribe as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives




--
Atenciosamente,

Alexsander da Rosa

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-10-03 Thread Onjahyr
solution in Linux? how sintaxe used?

:)


Alexsander Rosa escreveu:
 The /var/run solution is almost canonic for Linux.
 But how to do this in a multi-platform way?

 2006/10/3, Ales Katona [EMAIL PROTECTED]:
 /var/run with pids is also present in FreeBSD 5.x+

 But it's just a dumpspace for these things..

 It still doesn't add anything useful :) I think there's some syscall to
 do what ps does basicly. Might be worth looking at, that way you won't
 depend on external crap.

 Ales

  At least FreeBSD 4 has a pid-file in /var/run:
 
  $ ls /var/run/
  cron.pidemacs   ld.so.hints ppp
 sshd.pid
  dev.db  inetd.pid   log printer
 syslog.pid
  dhcpd   isdnd.pid   mountd.pid  run utmp
  dmesg.boot  ld-elf.so.hints moused.pid  sendmail.pid
 
  $ cat /var/run/cron.pid
  122
 
  $ ps aux|grep cron
  root 122  0,0  0,1  1056  768  ??  Ss   12:14am   0:00,00
 /usr/sbin/cron
 
  Don't know about os version 5 or 6 or 7 though ...
 
  HTH,
  Marc
 
  _
   To unsubscribe: mail [EMAIL PROTECTED] with
  unsubscribe as the Subject
 archives at http://www.lazarus.freepascal.org/mailarchives

 _
  To unsubscribe: mail [EMAIL PROTECTED] with
 unsubscribe as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives




_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-10-02 Thread Al Boldi
Burkhard Carstens wrote:
 Am Donnerstag, 28. September 2006 22:41 schrieb John vd Waeter:
  Problem when program crashes. File is not deleted. Maybe refresh file
  every 5 minutes or so, put a timestamp in it. If timestamp older then
  5 minutes, program appearantly crashed, new instance may start.
 
  John

 Put you PID in that file. That way, another instance can read that file
 (if it exists) and check, if a process with that PID is still active.
 If not, it's a likely, that the previous instance crashed ..

 Sure, this -might- also give a false positive (prev. inst. crashed, and
 another process got the very same PID in the meantime ..), but that's
 pretty unlikely ..

That's why it's always smart to check the /proc/[pid]/cmdline too.


Thanks!

--
Al

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-10-02 Thread Burkhard Carstens
Am Montag, 2. Oktober 2006 16:13 schrieb Al Boldi:
 Burkhard Carstens wrote:
  Am Donnerstag, 28. September 2006 22:41 schrieb John vd Waeter:
   Problem when program crashes. File is not deleted. Maybe refresh
   file every 5 minutes or so, put a timestamp in it. If timestamp
   older then 5 minutes, program appearantly crashed, new instance
   may start.
  
   John
 
  Put you PID in that file. That way, another instance can read that
  file (if it exists) and check, if a process with that PID is still
  active. If not, it's a likely, that the previous instance crashed
  ..
 
  Sure, this -might- also give a false positive (prev. inst. crashed,
  and another process got the very same PID in the meantime ..), but
  that's pretty unlikely ..

 That's why it's always smart to check the /proc/[pid]/cmdline too.

.. while this still doesn't make it 100% failsafe, because the app could 
have been started using a symbolic link?
OK, putting the PID + the contents of /proc/[pid]/cmdline into the 
lockfile could make it pretty safe, I guess .. But then, /proc/[pid] is 
linux only, isn't it? (of course, not on windows, but what with BSD?)

regards,
 Burkhard


_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-10-02 Thread Ales Katona
FreeBSD might or might not have /proc mounted. Default is no however, so
you can't be sure.

However you can still save the pid # of the process in some file, then
when starting a new one, read this number, check output of ps (or use
syscalls if applicable) for given number and if pos finds the name of
your app then it's running. Otherwise start and override the file.

This way even if you crash and then another process takes your old pid
you still can see if it's your app or not.

Ales

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-10-02 Thread Marc Santhoff
Am Montag, den 02.10.2006, 17:51 +0200 schrieb Ales Katona:
 FreeBSD might or might not have /proc mounted. Default is no however, so
 you can't be sure.
 
 However you can still save the pid # of the process in some file, then
 when starting a new one, read this number, check output of ps (or use
 syscalls if applicable) for given number and if pos finds the name of
 your app then it's running. Otherwise start and override the file.
 
 This way even if you crash and then another process takes your old pid
 you still can see if it's your app or not.

At least FreeBSD 4 has a pid-file in /var/run:

$ ls /var/run/
cron.pidemacs   ld.so.hints ppp sshd.pid
dev.db  inetd.pid   log printer syslog.pid
dhcpd   isdnd.pid   mountd.pid  run utmp
dmesg.boot  ld-elf.so.hints moused.pid  sendmail.pid

$ cat /var/run/cron.pid
122

$ ps aux|grep cron
root 122  0,0  0,1  1056  768  ??  Ss   12:14am   0:00,00 /usr/sbin/cron

Don't know about os version 5 or 6 or 7 though ...

HTH,
Marc

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-29 Thread Burkhard Carstens
Am Donnerstag, 28. September 2006 22:41 schrieb John vd Waeter:
 Problem when program crashes. File is not deleted. Maybe refresh file
 every 5 minutes or so, put a timestamp in it. If timestamp older then
 5 minutes, program appearantly crashed, new instance may start.

 John

Put you PID in that file. That way, another instance can read that file 
(if it exists) and check, if a process with that PID is still active. 
If not, it's a likely, that the previous instance crashed ..

Sure, this -might- also give a false positive (prev. inst. crashed, and 
another process got the very same PID in the meantime ..), but that's 
pretty unlikely ..

regards, 
 Burkhard

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-29 Thread Alejandro Lucas Baldres
Thanks for your help!-- Lucas BaldrésUsuario linux #: 425616Maquina #: 333252


[lazarus] avoiding multi-instance detection

2006-09-28 Thread Alejandro Lucas Baldres
Hello, I'm buy a program, this no can allow more of a instance. ¿How to for no allow more of one instance?Thank you and sorry for my bad english-- Lucas BaldrésUsuario linux #: 425616
Maquina #: 333252


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread Bogusław Brandys

Alejandro Lucas Baldres wrote:
Hello, I'm buy a program, this no can allow more of a instance. ¿How to 
for no allow more of one instance?


Thank you and sorry for my bad english

--
Lucas Baldrés
Usuario linux #: 425616
Maquina #: 333252


Try to describe in simpler words :)
Which platform ? Linux,Windows,Mac ?
You buy or you made and sell ?
Program disallow more then one instance or you want it to do this ?


Regards
Boguslaw

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread Alejandro Lucas Baldres
My plataform i386 with Linux (ubuntu dapper 6.06), the future of program is free and opensource.I want the program disallow more then one instance.2006/9/28, Bogusław Brandys 
[EMAIL PROTECTED]:Alejandro Lucas Baldres wrote:
 Hello, I'm buy a program, this no can allow more of a instance. ¿How to for no allow more of one instance? Thank you and sorry for my bad english -- Lucas Baldrés Usuario linux #: 425616
 Maquina #: 333252Try to describe in simpler words :)Which platform ? Linux,Windows,Mac ?You buy or you made and sell ?Program disallow more then one instance or you want it to do this ?
RegardsBoguslaw_ To unsubscribe: mail [EMAIL PROTECTED] withunsubscribe as the Subject
 archives at http://www.lazarus.freepascal.org/mailarchives-- Lucas BaldrésUsuario linux #: 425616
Maquina #: 333252


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread Bogusław Brandys

Alejandro Lucas Baldres wrote:
My plataform i386 with Linux (ubuntu dapper 6.06), the future of program 
is free and opensource.

I want the program disallow more then one instance.


The simplest solution: let program check if /tmp/filename file exists 
and create it,then on exit delete.If file exists then instance is 
already running.

More complex would be using IPC (maybe others could describe)

Regards
Boguslaw

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread ik

Another way, that is easier to control, is to use mutexes.
Mutex is a place in memory that is locked until someone free it. So
you can check if that place (usually mapped to a name, alto I do not
remember at the moment how Linux implement it) exists, and if so, you
stop your own execution, otherwise you can continue the loading.

Ido

On 9/28/06, Bogusław Brandys [EMAIL PROTECTED] wrote:

Alejandro Lucas Baldres wrote:
 My plataform i386 with Linux (ubuntu dapper 6.06), the future of program
 is free and opensource.
 I want the program disallow more then one instance.

The simplest solution: let program check if /tmp/filename file exists
and create it,then on exit delete.If file exists then instance is
already running.
More complex would be using IPC (maybe others could describe)

Regards
Boguslaw

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives



_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread Bogusław Brandys

ik wrote:

Another way, that is easier to control, is to use mutexes.
Mutex is a place in memory that is locked until someone free it. So
you can check if that place (usually mapped to a name, alto I do not
remember at the moment how Linux implement it) exists, and if so, you
stop your own execution, otherwise you can continue the loading.

Ido


AFAIk there is no system wide mutexes in Linux, but I may be wrong.


Regards
Boguslaw

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread John vd Waeter
Problem when program crashes. File is not deleted. Maybe refresh file 
every 5 minutes or so, put a timestamp in it. If timestamp older then 5 
minutes, program appearantly crashed, new instance may start.


John


Bogusław Brandys wrote:

Alejandro Lucas Baldres wrote:

My plataform i386 with Linux (ubuntu dapper 6.06), the future of 
program is free and opensource.

I want the program disallow more then one instance.



The simplest solution: let program check if /tmp/filename file exists 
and create it,then on exit delete.If file exists then instance is 
already running.

More complex would be using IPC (maybe others could describe)

Regards
Boguslaw

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives





--
John vd Waeter
mailto:[EMAIL PROTECTED]
http://www.jvdw.nl
http://www.shotinthedark.nl

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread Graeme Geldenhuys

On 28/09/06, John vd Waeter [EMAIL PROTECTED] wrote:

Problem when program crashes. File is not deleted. Maybe refresh file
every 5 minutes or so, put a timestamp in it. If timestamp older then 5
minutes, program appearantly crashed, new instance may start.

John



Simple solution, program with Unit Tests, so you app is rock solid and
will never crash. :-)

PS:
 Anybody know if mutexes in Linux is system wide?

Regards,
 - Graeme -

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread Bogusław Brandys

Graeme Geldenhuys wrote:

On 28/09/06, John vd Waeter [EMAIL PROTECTED] wrote:

Problem when program crashes. File is not deleted. Maybe refresh file
every 5 minutes or so, put a timestamp in it. If timestamp older then 5
minutes, program appearantly crashed, new instance may start.

John



Simple solution, program with Unit Tests, so you app is rock solid and
will never crash. :-)

PS:
 Anybody know if mutexes in Linux is system wide?

Regards,
 - Graeme -


According to pthreads docs: Mutexes can be applied only to threads in a 
single process and do not work between processes as do semaphores.

Maybe semaphores are right solution ?


Regards
Boguslaw


_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread Marc Weustink
Graeme Geldenhuys wrote:
 On 28/09/06, John vd Waeter [EMAIL PROTECTED] wrote:
 Problem when program crashes. File is not deleted. Maybe refresh file
 every 5 minutes or so, put a timestamp in it. If timestamp older then 5
 minutes, program appearantly crashed, new instance may start.

 John
 
 
 Simple solution, program with Unit Tests, so you app is rock solid and
 will never crash. :-)
 
 PS:
  Anybody know if mutexes in Linux is system wide?

IIRC we tried something global. Problem was that if the program crashed
the lock wasn't released, so not other instence could start after a crash.

Marc


_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread Bogusław Brandys

Graeme Geldenhuys wrote:

On 28/09/06, John vd Waeter [EMAIL PROTECTED] wrote:

Problem when program crashes. File is not deleted. Maybe refresh file
every 5 minutes or so, put a timestamp in it. If timestamp older then 5
minutes, program appearantly crashed, new instance may start.

John



Simple solution, program with Unit Tests, so you app is rock solid and
will never crash. :-)

PS:
 Anybody know if mutexes in Linux is system wide?

Regards,
 - Graeme -



Well.The main problem with linux in this particular case is that it's 
hard to find such global resource which is:
- atomic (no other process can get it in the same time like file lock or 
system-wide mutex)

- automatically released when application exit or crash or being killed

Maybe unix sockets ?
Someone with deeper linux knowledge ?


Regards
Boguslaw

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] avoiding multi-instance detection

2006-09-28 Thread A.J. Venter

Just a simple question: would that be possible to simply query the

list of actual processes that are running? 'ps ax' for example; then
you can find your application?
Yep, you could do this with a TProcess - however, having said that - as 
I said before when this same question was discussed - the best tool for 
the job is xlsclients - which lists open WINDOWS in the current X server.
If your app is in there, you know it's already running - at least if 
it's a graphical app.


So you could tprocess around xlsclients, or better yet, somebody can 
read the xlsclients source code, and write a wrapper component mapping 
the appropriate xlib calls into lazarus once and for all :)


A.J.

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives