How to terminate a process and its parent from command prompt
I have a process that is launched from command prompt - file.bat, although its parent cmd.exe needs to be terminated as well. The only problem is there are other instances of cmd.exe is there any way of terminating the process file.bat - without deleting o开发者_StackOverflowther instances of cmd.exe
(I can't simply terminate the cmd.exe process, as I dont know the PID in this case)
You could try parsing the output of the PsList utility from Sysinternals.
You can get it from: http://technet.microsoft.com -> search for "sysinternals"
When you run "PsList -t" you'll see a list of processes, with children indented from the left margin. Here's a snippet:
The first numeric column is the PID. You didn't mention what kind of language you're writing your script in, but it shouldn't be too hard to iterate over the lines, and use a stack-like structure to store the current descent-path. When you reach the PID of the desired process, you'll be able to examine the stack to get the parent info.
精彩评论