You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Thomas Steinbach <st...@gmx-topmail.de> on 2009/01/14 19:58:07 UTC

Apache Shutdown - Win32

Hello,

I have a small win32 program which starts
and stops apache (win) as a program (not service)
in a hidden console.

---snip---
/* global vars */
STARTUPINFO g_sia;
PROCESS_INFORMATION g_pia;
[...]
void StartApache()
{
g_sia.dwFlags = STARTF_USESHOWWINDOW;
g_sia.wShowWindow = SW_HIDE;

CreateProcess(NULL, "apache.exe...", NULL, NULL, FALSE,
CREATE_NEW_PROCESS_GROUP, NULL, NULL, &g_sia, &g_pia);
}
---snap---
using "CREATE_NEW_PROCESS_GROUP" described at:
http://msdn.microsoft.com/en-us/library/ms684863(VS.85).aspx


At the end I would like to shutdown apache in an "usual"
way and sending an CTRL+C to the console. Using
GenerateConsoleCtrlEvent(). See:
http://msdn.microsoft.com/en-us/library/ms683155(VS.85).aspx

btw: actually I terminate apache, using
CreateToolhelp32Snapshot() and iterate all child processes
and using TerminateProcess().

but I would prefer to generate an CTRL+C Signal

---snip---
void StopApache()
{
GenerateConsoleCtrlEvent(CTRL_C_EVENT, g_pia.dwProcessId);
}
---snap---

but got an Error #6 = "The handle is invalid" with GetLastError()
and nothing happens and apache is still runing.

Why? And how can I shutdown apache in this way
using the signal Ctrl+C Signal in Windows? The pid is a
global var and contains the pid of the parent process.
Should be valid - shouldn't it?

Thomas


Re: Apache Shutdown - Win32

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Thomas Steinbach wrote:
> Hello,
> 
> I have a small win32 program which starts
> and stops apache (win) as a program (not service)
> in a hidden console.

Well, httpd should work fine, but...

> void StartApache()
> {
> g_sia.dwFlags = STARTF_USESHOWWINDOW;
> g_sia.wShowWindow = SW_HIDE;

... does not generate a console window.  You have a new process
group and no cmd.exe process leader.  Try invoking with cmd.exe /c ...
and be certain you have STARTF_USESTDHANDLES as all good console
programs initially require some stdin/out/err, even if they are
pointing to an open NULL device handle.

Bill