Killing the command shell will not kill its child process ?

F

for.fun

Hi everybody,


I have the following problem :

Consider the following "test.cmd" command script :

test.cmd:

REM ----------------------

MyChildProcess.exe

REM ----------------------


(where "MyChildProcess.exe" is just a never-ending application suitable
for my test)


When I kill the "test.cmd" (using the Windows task manager or any
Windows kill tool), my "test.cmd" process is correctly killed but
"MyChildProcess.exe" stays alive (and I suppose it becomes a system's
child because its parent died)

What I would like to do is : killing the "test.cmd" (cmd.exe) also kill
"MyChildProcess.exe"

(I am running "MyChildProcess.exe" as a service using "SrvAny.exe" and
the "NET STOP" command only send a stop signal to the "test.cmd" shell
script and leave the "MyChildProcess.exe" running)

Under Unix, this behavior is achevied with the "exec" command => the
child process becomes a part of the parent process so both of them die
when one of them receive a kill signal.


=> Does anybody know is the same feature as "exec" exist under Windows
?

=> If no, is there a way to modify the "test.cmd" shell script so both
parent and child can be killed on the same time ?


Thanks in advance for your help.
 
R

RDSchaefer

Ok, a few questions:
Why are you using a cmd file to start it?

Why are you killing the cmd file (or cmd.exe) instead of
"MyChildProcess.exe"?

If you are using "SrvAny.exe" to run it as a service, why are you
using a cmd file?

What, exactly, is the NET STOP command you are using?

Ralph
 
F

for.fun

Why are you using a cmd file to start it?

In facts, the program I want to run is a Java class started by
"java.exe" ("MyChildProcess.exe" was just a simple example)
The process must be started at boot time (no user logged on the PC) so
I installed it as a service with "SrvAny".
Moreover, the "java.exe" process need some environment variables to be
set : the only way to achieve this is writing a CMD script which set
the environment and then start "java.exe".
In order to start the script as a service, I installed "SrvAny.exe"
(Windows 2003 Resource Kit) and set it to start the CMD script.

Why are you killing the cmd file (or cmd.exe) instead of "MyChildProcess.exe"?

Let's say "java.exe" instead of "MyChildProcess.exe".
I am not killing "java.exe" myself, "NET STOP MyJavaService" do it.
When I call "NET STOP MyJavaService", the Windows service manager call
"TerminateProcess()" on the process ID started by "SrvAny.exe"
The started process is "CMD.EXE" and not "java.exe" which is a child of
"CMD.EXE".
Consequently, only the "CMD.EXE" is stopped and "java.exe" stays alive.

If you are using "SrvAny.exe" to run it as a service, why are you using a cmd file?

Look my first reply.

What, exactly, is the NET STOP command you are using?

I call :

C:/> NET STOP MyJavaService

.... in order to stop the service.


I hope you have all the information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top