Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Apache: Dev

Want to kill Apache process when its parent process gets killed.

 

 

Apache dev RSS feed   Index | Next | Previous | View Threaded


Ashwani_Sharma at mindtree

Sep 10, 2007, 7:44 AM

Post #1 of 5 (573 views)
Permalink
Want to kill Apache process when its parent process gets killed.

Hi,



In my application I am spawning httpd.exe from the parent process.



My requirement is that:



1. Whenever the parent process is getting killed, it should also kill
the Apache web server and then go down.

This I am able to do successfully.



2. In the Abnormal termination of the parent process. The Apache should
keep looking for its parent process. If the parent process is not present

then the Apache web server should also kill itself.



How can I implement the 2nd point?



Please guide.







Thanks and Regards,

Ashwani Sharma

Mob: 09916454843

Off: +91-80-26265053





DISCLAIMER:
This message (including attachment if any) is confidential and may be privileged. Before opening attachments please check them for viruses and defects. MindTree Consulting Limited (MindTree) will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside. If you have received this message by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited.Please note that e-mails are susceptible to change and MindTree shall not be liable for any improper, untimely or incomplete transmission.
E-mail may contain viruses. Before opening attachments please check them for viruses and defects. While MindTree Consulting Limited (MindTree) has put in place checks to minimize the risks, MindTree will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside.


trawick at gmail

Sep 11, 2007, 3:44 AM

Post #2 of 5 (525 views)
Permalink
Re: Want to kill Apache process when its parent process gets killed. [In reply to]

On 9/10/07, Ashwani Kumar Sharma <Ashwani_Sharma [at] mindtree> wrote:

> In my application I am spawning httpd.exe from the parent process.
...
> My requirement is that:
...
> In the Abnormal termination of the parent process. The Apache should keep
> looking for its parent process. If the parent process is not present
>
> then the Apache web server should also kill itself.
> How can I implement the 2nd point?

not even a half-baked idea:

Somebody gets the monitor hook called from the Windows MPM (i.e.,
fixes Apache on Windows to call a hook that is provided on
Unix/Linux).

General idea (mpm_winnt.c)

/* Wait for shutdown or restart events or for child death */
winnt_mpm_state = AP_MPMQ_RUNNING;
do {
rv = WaitForMultipleObjects(NUM_WAIT_HANDLES, (HANDLE *)
event_handles, FALSE, something-that-means-one-second);
if (rv == WAIT_TIMEOUT) {
ap_run_monitor(pconf);
}
} while (rv == WAIT_TIMEOUT);

(remove existing check for WAIT_TIMEOUT that considers it a fatal error)

Your application starts httpd.exe with a define like

-DMOD_FOO_MONITORED_PID=13579

and a config that loads a custom plug-in module provided by you which
implements the monitor hook that checks for when that pid goes away.

???How to make the monitor hook take down httpd? apache -k stop???


Ashwani_Sharma at mindtree

Sep 11, 2007, 4:10 AM

Post #3 of 5 (524 views)
Permalink
RE: Want to kill Apache process when its parent process gets killed. [In reply to]

Hi Jeff,

Thanks for your reply.

The httpd.exe of Apache web server has two processes running in windows.
When we kill the parent httpd.exe the child httpd.exe is still running and
listening to the web request. I don't want this.

I want to modify this in such a way that if I kill the parent httpd.exe
through following code, the child process should also get killed. How is it
possible? Please guide me. It's very urgent.

hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (hProcess == NULL) return FALSE;
dwError = ERROR_SUCCESS;
if (!TerminateProcess(hProcess, (DWORD)-1))
dwError = GetLastError();


where pid is the parent process id.



Thanks and Regards,
Ashwani Sharma
Mob: 09916454843
Off: +91-80-26265053


-----Original Message-----
From: Jeff Trawick [mailto:trawick [at] gmail]
Sent: Tuesday, September 11, 2007 4:15 PM
To: dev [at] httpd
Subject: Re: Want to kill Apache process when its parent process gets killed.

On 9/10/07, Ashwani Kumar Sharma <Ashwani_Sharma [at] mindtree> wrote:

> In my application I am spawning httpd.exe from the parent process.
...
> My requirement is that:
...
> In the Abnormal termination of the parent process. The Apache should keep
> looking for its parent process. If the parent process is not present
>
> then the Apache web server should also kill itself.
> How can I implement the 2nd point?

not even a half-baked idea:

Somebody gets the monitor hook called from the Windows MPM (i.e.,
fixes Apache on Windows to call a hook that is provided on
Unix/Linux).

General idea (mpm_winnt.c)

/* Wait for shutdown or restart events or for child death */
winnt_mpm_state = AP_MPMQ_RUNNING;
do {
rv = WaitForMultipleObjects(NUM_WAIT_HANDLES, (HANDLE *)
event_handles, FALSE, something-that-means-one-second);
if (rv == WAIT_TIMEOUT) {
ap_run_monitor(pconf);
}
} while (rv == WAIT_TIMEOUT);

(remove existing check for WAIT_TIMEOUT that considers it a fatal error)

Your application starts httpd.exe with a define like

-DMOD_FOO_MONITORED_PID=13579

and a config that loads a custom plug-in module provided by you which
implements the monitor hook that checks for when that pid goes away.

???How to make the monitor hook take down httpd? apache -k stop???


DISCLAIMER:
This message (including attachment if any) is confidential and may be privileged. If you have received this message by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited.
E-mail may contain viruses. Before opening attachments please check them for viruses and defects. While MindTree Consulting Limited (MindTree) has put in place checks to minimize the risks, MindTree will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside.
Please note that e-mails are susceptible to change and MindTree shall not be liable for any improper, untimely or incomplete transmission.
MindTree reserves the right to monitor and review the content of all messages sent to or from MindTree e-mail address. Messages sent to or from this e-mail address may be stored on the MindTree e-mail system or else where.


trawick at gmail

Sep 11, 2007, 11:19 AM

Post #4 of 5 (516 views)
Permalink
Re: Want to kill Apache process when its parent process gets killed. [In reply to]

On 9/11/07, Ashwani Kumar Sharma <Ashwani_Sharma [at] mindtree> wrote:
> Hi Jeff,
>
> Thanks for your reply.
>
> The httpd.exe of Apache web server has two processes running in windows.
> When we kill the parent httpd.exe the child httpd.exe is still running and
> listening to the web request. I don't want this.

When you said

"In my application I am spawning httpd.exe from the parent process."

I assumed thereafter that "parent" refers to your own application that
starts the web server, but you have a different kind of issuefor which
I have no ideas.

Good luck...


wrowe at rowe-clan

Sep 11, 2007, 2:17 PM

Post #5 of 5 (515 views)
Permalink
Re: Want to kill Apache process when its parent process gets killed. [In reply to]

Ashwani Kumar Sharma wrote:
>
> The httpd.exe of Apache web server has two processes running in windows.
> When we kill the parent httpd.exe the child httpd.exe is still running and
> listening to the web request. I don't want this.

Since you forcibly terminate the server process(es) your instance of httpd.exe
won't be cleaned up. It's really not terribly graceful.

It's the unix equivilant of sending kill -KILL instead of kill. Ick.

I believe you can solve your entire problem by telling httpd.exe to shut down,
and avoiding the abandoned children. The API would be GenerateConsoleCtrlEvent
to force a CTRL_C_EVENT at the process

http://msdn2.microsoft.com/en-us/library/ms683155.aspx

all of which is to say you aren't using httpd.exe as a service, which is where
most of the testing and evalution effort is invested in.

Since you are replacing the parent wrapper you might consider dropping the
parent altogether (see the -X flag, I'm not sure if -DONE_PROCESS is the
same effect on win32 offhand).

Bill

Apache dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.