How do I kill a grandchild process from shell program?

Jim Seymour nntp.ff@thentao.com
Tue Oct 24 01:16:00 GMT 2006


I've been Googling all afternoon trying to figure out whether this is a 
bug, a "feature", or a stupid user problem.  If it's the latter, I 
apologize in advance...

I'm using Cygwin v1.5.21-2 and bash v3.1.17(9) under Windows XP Pro.

I have two shell programs - one that launches the other in the 
background.  The background one runs a utility program that (under 
normal circumstances) will shut down gracefully.

However, if things don't work fine, the background process sticks around 
to plague me later.

I'd like to end my main script by killing the background process (if 
it's still around), but I'm having a helluva time figuring out HOW.

I thought I'd hit the jackpot when I learned about the %?S jobspec, but 
kill doesn't seem to respect it.  It reports "no such job" (see Note 1)

I can use "kill $!" in the main script, but that only kills the 
background bash process, leaving the utility program running.

Questions:

1) Is "kill %?name" supposed to work in this environment?
2) Is there a simple way to kill a process along with its children?

Thanks for reading this far...

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Note 1)
Here's an example "ps" output and the associated "kill" command:
$ ps
   PID  PPID  PGID  WINPID  TTY  UID    STIME COMMAND
  2196     1  2196    2196  con 11024 16:10:01 /usr/bin/bash
   724  2196   724     716  con 11024 17:00:39 /usr/bin/sh
  3340   724   724    3048  con 11024 17:00:41 /usr/local/bin/ocdremote
  3556  2196  3556    2192  con 11024 17:00:49 /usr/bin/ps

$ kill %?ocdremote
bash: kill: %?ocdremote: no such job

-- 
Jim Seymour


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list