multiple instance on Unix

Grant Edwards grante at
Thu Sep 30 00:43:14 CEST 2004

On 2004-09-29, Jorgen Grahn <jgrahn-nntq at> wrote:

> Unix programs normally don't attempt to "protect" themselves
> in this way.

Some do, some don't.  Many system daemons want to make sure
that only a single instance is running.  That's one of the
functions of all the *.pid files in /var/run.  It's less common
that user programs try to enforce such a restriction, but it
happens.  It's usually done by creating a lock file in the
user's home directory if it's a per-user restriction.

> I can /definitely/ see situations where two programs modifying
> the same set of files, resulting in binary garbage, but if
> these are different programs your approach doesn't work.
> Best is a design which doesn't need locking. Second best is
> locking which is tied to the resources (files) which need to
> be protected.

Agreed, but creating a lockfile to make sure only a single
instance of the program is running is the standard third

> Leaving it up to the user to be careful is another popular
> choice ;-)


Grant Edwards                   grante             Yow!  PARDON me, am I
                                  at               speaking ENGLISH?

More information about the Python-list mailing list