How to stop server (hg serve) ?

Greg Ward greg-hg at gerg.ca
Mon Nov 2 08:44:28 CST 2009


On Mon, Nov 2, 2009 at 6:34 AM, Christian Ebert <blacktrash at gmx.net> wrote:
> $ sw_vers
> ProductName:    Mac OS X
> ProductVersion: 10.5.8
> BuildVersion:   9L30
> $ hg serve --pid-file test.pid &
> [1] 5417
> $ cat test.pid
> 5417
> $ kill -9 `cat test.pid`
> [1]+  Killed                  hg serve --pid-file test.pid

I'm glad the pid file works on OS X, but you really shouldn't use
"kill -9" as a first resort.  And explaining it like this will make
newbies think that "kill -9" is the right thing to do.  In general,
it's not.

Consider a server that maintains data structures on disk.  A
well-written server will intercept signals (eg. Ctrl-C or vanilla
"kill" (SIGTERM)) and shut itself down in a orderly fashion.
Transactions will be aborted or committed as appropriate, locks will
be released, etc.

However, SIGKILL (aka kill -9) cannot be intercepted by the process
being killed.  That's the whole point of it.  So if you "kill -9" a
well-behaved server, you are making it impossible for it to shutdown
cleanly (abort transactions, release locks, etc.).  That leaves a mess
for the next user of those data structures to deal with.

The usual way to shutdown a server process on Unix is to send it a
SIGTERM (kill <pid>).  If it is still running after a few seconds,
*then* you pull out the big guns and send SIGKILL (kill -9 <pid>).

Greg



More information about the Mercurial mailing list