Bug 25484 - Non-service Apache cannot be stopped in WinXP
Summary: Non-service Apache cannot be stopped in WinXP
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mpm_winnt (show other bugs)
Version: 2.2.21
Hardware: PC All
: P3 normal with 9 votes (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
: 36556 (view as bug list)
Depends on:
Reported: 2003-12-12 16:53 UTC by Hiran Chaudhuri
Modified: 2012-01-20 08:33 UTC (History)
6 users (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Hiran Chaudhuri 2003-12-12 16:53:32 UTC
Apache, once started from command line (apache.exe) cannot be stopped via 
command line (apache.exe -k stop).
This seems to be connected with bug 14555, but also appears in the most recent 
version (2.0.48) under Windows XP.

We need this feature to embed Apache into some other software, which cannot use 
apache as a service.
Comment 1 Hiran Chaudhuri 2003-12-30 09:25:15 UTC
Applied same priority and severity as bug 14555.
Comment 2 Hiran Chaudhuri 2004-01-07 09:14:29 UTC
Talking to JanC revealed this bug is not connected with the Win9x bug.
In Win9x, the "apache -k stop" process hangs completely, while on Win XP
it says "There is no apache service running" and terminates.

JanC suspects from the error message the code only looks for running 
services, which is certainly not what the docs describe.

Killing Apache using it's PID does not work around this problem, as Apache 
starts child processes, which are not affected if the main process is killed.
Comment 3 eddie 2005-06-02 16:54:01 UTC
The -k is only for controlling the apache service ( the code says it is only 
for dealing with the SCM - i.e. services) and the docs:


show that -k is used when running apache as a service.

If you still need to shutdown the process *i know the bug is quite old ;)* you 
could search through all processes, find each apache process and search the 
parent pids until you get to the top parent then close that first then each of 
the children (for a hint on getting parent pids look at 
http://www.codeproject.com/threads/ParentPID.asp )
Comment 4 Paul Querna 2005-06-03 01:44:34 UTC
Looks like -k was bring used in the wrong way.
Comment 5 Hiran Chaudhuri 2005-06-06 15:30:18 UTC
So there is no other way to shut down an apache process not running as a service?
We cannot just kill all the httpd processes found since there may be several
servers running on the same machine. Finding out which process tree to kill is
what works marvelous on unix machines - thought that Windows might behave
similar, especially since it was the case with Apache httpd 1.x.

Currently our workaround is really to kill the process by pid. There is no
process hierarchy as by httpd.conf we tell apache not to spawn child processes,
so killing the one parent is sufficient. To find the correct PID we keep the
handle to the process which is returned by the system call to spawn the apache
Comment 6 Mike Burr 2006-09-22 13:21:46 UTC
I'm a bit confused.  The referenced docs at:


show the "-k install", "-k uninstall" and "-k start" start options only in the
"Running Apache as a Service" section, but list "-k shutdown/stop" and "-k
restart" under BOTH "Running Apache as a Service" AND "Running Apache as a
Console Application".  This would seem to imply that I SHOULD be able to use "-k
shutdown" on an Apache running in a console (as I could in 1.3).
Comment 7 William A. Rowe Jr. 2006-12-25 22:00:37 UTC
*** Bug 36556 has been marked as a duplicate of this bug. ***
Comment 8 William A. Rowe Jr. 2007-12-21 20:14:34 UTC
apache -k stop does not support shutting down a console, and the console
mode really isn't designed for such things.  httpd is a daemon (a service,
in windows parlance) so there isn't a large amount of attention paid to it.

Sending a control C event to the console will terminate apache.  If you were
running five of them, how do you suppose -k stop would know which to shut down?

In any case, I agree it's a documentation bug that should be resolved by removing
the -k stop from featured "Running Apache as a Console Application" options.
Comment 9 Mike Burr 2007-12-22 19:05:21 UTC
We had a deadline that passed long ago & ended up working around this by writing
a trivial .exe that accepts -f and -k command line options (that have the same
meaning as the corresponding apache command line options), finds the PidFile
line in the apache config file, reads the pid file, then calls SetEvent() on the
event indicated by the pid and the -k parameter.  It's been awhile, but IIRC the
majority of this logic was copied from the code that made this work in 1.3.  I
looked at reincorporating this function into the 2.x base, but schedules were
tight & it was quicker to write a standalone .exe.

As I said, we worked around this problem long ago so I don't really have a
strong interest in how this bug is addressed.  If there is any interest in our
little hack, the company I work for contributes pretty regularly to the Apache
web server & I can't imagine they would mind making the source for our simple
.exe available if I asked.

(In reply to comment #8)

> Sending a control C event to the console will terminate apache.  If you were
> running five of them, how do you suppose -k stop would know which to shut down?

By consulting the -f parameter (see description above).
Comment 10 William A. Rowe Jr. 2007-12-30 21:30:06 UTC

I concur it's worth fixing; solving it in the MPM isn't really that hard
(using the pidfile as on unix).  I'll leave this assigned for consideration
and for want of a patch (that I don't have cycles to write, right now).
Comment 11 William A. Rowe Jr. 2007-12-30 22:12:18 UTC
Correct priority in relation to supported uses of httpd/win32.
Comment 12 nobswolf 2012-01-20 08:31:12 UTC
still valid

tested on:

Windows 7 Ultimate 64 Bit 
Apache 2.2.21

not conform with released documentation: