[svlug] Reuse of pid's.

Don Marti dmarti at zgp.org
Wed Jan 21 11:20:12 PST 2009

begin norm at dad.org quotation of Wed, Jan 21, 2009 at 10:35:02AM -0800:

> As I read the source for killall, it assumes that when a process is successfully
> killed, no other processes with the same pid will be created within the lifetime
> of that invocation of killall, which can last many seconds.

Known bug, according to the man page.

  "killall -w doesn’t detect if a process disappears
  and is replaced by  a new process with the same
  PID between scans."

> Is that assumption
> valid? Would it be safe for me to make the same assumption in my code?

Not really, since you don't know what pid the kernel
will give the next process it creates.  Realistically,
if you do make the assumption and it causes a problem,
it's going to be hard enough to duplicate that you're
unlikely to get caught, though.

If you absolutely need to be sure you're talking to
the right process, could you have it write its pid
to a file, or use a socket?  The start-stop-daemon
utility is a wrapper that will make the pidfile for
you -- then you could just "kill" based on what's in
the file.

Don Marti                                        +1 510-814-0932
http://zgp.org/~dmarti/                          +1 510-332-1587 mobile
dmarti at zgp.org
See you at OpenSource World: August 10-13, 2009 in San Francisco

More information about the svlug mailing list