Apache Control : Starting and Stopping Apache from foreign application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Hi all,
I have the following problem :-
I wrote a Apache Control Program in Visual Studio 2003, which does the following
1>. Starts Apache with CreateProcess Call. I run Apache on the command interpreter but not as a service.
2>. Redirects all standard input / output of Apache to the Apache Control Program so that the Apache cmd-line output actually appears in the log window of the control program
3>. Stops Apache
#3 has some problem.
When I try to stop Apache, I try the following
1>. Send a control-C control event to the process the CreateProcess call returns
2>. Close the input pipe which I passed on to Apache during the CreateProcess
3>. Do an TerminateProcess on the process id returned by the CreateProcess call
When I run Apache from the command line, a ctrl+c stops both the running httpd process. However programmatically #1 does not have any effect. It feels that Apache has not received the Ctrl+C I send.
#2 does not have any impact on the running Apache Process either
#3 only kills the primary httpd process running. It does not kill the second process.
Here is the code excerpt :-
///////////// STARTING APACHE //////////////////////
_tcscpy(_pszCmdLine,m_szApacheBaseDir);
_tcscat(_pszCmdLine,_T("\\bin\\httpd.exe"));
_tcscat(_pszCmdLine,_T(" -f "));
_tcscat(_pszCmdLine,m_szApacheCfgFile);
_tcscat(_pszCmdLine,_T(" -e debug"));
//.. code to create input/output/error pipes and replicate the handles in the si structure
if (!::CreateProcess(
NULL,
(LPTSTR)pszCmdLine,
NULL, NULL,
TRUE,
CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP,
NULL, NULL,
&si,
&pi))
{
int n = GetLastError();
return FALSE;
}
///////////////////// STOPPING APACHE ///////////////////////
int j = _tcslen(ctrlC);
WriteFile(m_hStdinWrite, (LPCTSTR)ctrlC,2, &dwWritten, NULL);
if ( !GenerateConsoleCtrlEvent(CTRL_C_EVENT,m_dwProcessGroupId))
j = GetLastError();
CloseHandle(m_hStdinWrite);
CloseHandle(m_hStdinRead);
if (m_dwProcessGroupId)
{
_hProcessHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,m_dwProcessGroupId);
if (_hProcessHandle)
{
GetExitCodeProcess(_hProcessHandle,&_dwExitCode);
int n = GetLastError();
TerminateProcess(_hProcessHandle,1);
}
int n = GetLastError();
}
I would like to know how to send a Ctrl+C event to apache so that I can cleanly / gracefully shutdown Apache.
Any pointers will be extremely appreciated?
Thanks in Advance,
Asif
[Index of Archives]
[Open SSH Users]
[Linux ACPI]
[Linux Kernel]
[Linux Laptop]
[Kernel Newbies]
[Security]
[Netfilter]
[Bugtraq]
[Squid]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Samba]
[Video 4 Linux]
[Device Mapper]