Am Mittwoch, 14. Juni 2006 22:04 schrieb A.J. Venter:
> 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

Off course, you are right! Just grabbed this out of the fog far back in 
my memory ..

> 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.

Also rigth. As /var/run/ seems only writable by root ..
One could create that file in /tmp and make it even writable for group/
others.

Hmm, a safe but heavy way would be to grep through all thos /proc/{0-9}/
cmdline files .. ;-)

Burkhard


> > 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

Reply via email to