The below is all good, except the FHS says that lock files should be save
in /var/run/$PROGRAMNAME.lock instead.
/var/lock may not exist on all distro's but /var/run will always exist and is
specifically meant for storing lock files.
In this case technically it's NOT a lockfile, it's a pid file so it OUGHT to
go in /var/run/$PROGRAMNAME.pid
The nice bit is that this could even be parsed by shell scripts (E.g.
bootscripts).
Downside is - that's global, right now you are limiting to one root owned
instance per machine !
What you probably WANT is to save it to $HOME/.programname.pid
So that the same user won't run it twice.
At least for a graphical program - the /var/run approach only really makes
sense for daemons.
Ciao
A.J.
> so in steps:
> - on program start, check if a file named "/var/lock/name-off-your-app"
> exists.
> - if not: create it and write the value IntToStr(GetProcessID) into it
> - if yes: begin
> - open that file and read the pid from there into a string
> variable (e.g. suspiciousPID)
> - read file '/proc/'+suspiciousPID+'/cmdline' and check if your
> appname is in there
> - if yes: app allready running, halt(1)
> - if not: the lock file is left from a previous, but not longer
> active session. you may replace it with a new one containing
> your current pid
>
> > Try this:
> > PID=`OS aux | grep bash | awk '{print $2} |tail -n 1`
> > Then run the same command again
>
> (try
> PID=`pidof bash | awk '{ print $1 }'`
> cat /proc/$PID/cmdline
> )
>
> _________________________________________________________________
> To unsubscribe: mail [EMAIL PROTECTED] with
> "unsubscribe" as the Subject
> archives at http://www.lazarus.freepascal.org/mailarchives
--
"there's nothing as inspirational for a hacker as a cat obscuring a bug
by sitting in front of the monitor" - Boudewijn Rempt
A.J. Venter
Chief Software Architect
OpenLab International
www.getopenlab.com
www.silentcoder.co.za
+27 82 726 5103
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives