New library: libpidfile.
Pawel Jakub Dawidek
pjd at FreeBSD.org
Tue Aug 23 08:08:23 GMT 2005
On Tue, Aug 23, 2005 at 12:46:52PM +0900, Hajimu UMEMOTO wrote:
+> >>>>> On Mon, 22 Aug 2005 23:30:28 +0200
+> >>>>> Pawel Jakub Dawidek <pjd at FreeBSD.org> said:
+> pjd> I'd like to commit a small library for handling "pidfiles".
+> NetBSD and OpenBSD has similar functions already in libutil. I think
+> we alone have a different API is bad idea. So, it is good to bring
+> them into FreeBSD from NetBSD or OpenBSD, IMHO.
I assume you're talking about NetBSD's pidlock(3).
This is exactly an example of a bad way of doing it, as I understand the
It doesn't use flock(2), instead, it reads PID from the file and checks
if process with this PID is alive. *SOME* process, not necessarily already
running instance of the daemon, but some process which has the same PID.
This is most important in case of pkill(1), when we don't want to kill
some random process.
This of course is also racy - daamon could be started between checking
is process is alive and renaming (lock|pid)file.
It only provides one function which writes the PID of the current process
into the file. With libpidfile(3), you can open the pidfile before
fork()ing, so daemon can report if another copy is already running before
going into the background.
In general NetBSD's pidlock(3) isn't a complete solution (there is no
function to remove just remove pidfile on exit, etc.
In OpenBSD pidfile(3) exists, but it is even worser. It doesn't even check
if daemon is already running...
It also doesn't support any pidfile name, you may specify only 'basename'
and it creates pidfile in a form "/var/run/<basename>.pid", so it won't
work if most of our daemon where you can specify alternate pidfile location.
Anyway. There is no one API they share and none of them is a sufficient
Pawel Jakub Dawidek http://www.wheel.pl
pjd at FreeBSD.org http://www.FreeBSD.org
FreeBSD committer Am I Evil? Yes, I Am!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20050823/74f1b921/attachment.bin
More information about the freebsd-arch