简体   繁体   中英

Process running after TASKKILL

The problem is related to the script shown below:

@echo on
:MAIN
start "myname" cmd /c "build\jre\bin\java -jar MainThread.jar"
timeout /t 2 >null
TASKLIST /v /fi "IMAGENAME eq cmd.exe">myfile.txt
TASKKILL /f /fi "IMAGENAME eq cmd.exe" /fi "WINDOWTITLE eq myname"
TASKLIST /v /fi "IMAGENAME eq cmd.exe">myfile2.txt
:exit

When i execute tasklist for first time, myname is being listed in TASKLIST.After executing taskkill, myname process is not being shown in TASKLIST executed after TASKKILL but it is running.Although its name was not present in TASKLIST, it was executing.TASKKILL succeeded in removing its entry but didn't kill the process.How should I kill that process?

Started java process takes up parental cmd window name however no sooner than latter parental cmd process is terminated. Proof given using substitute where not having java installed (as where.exe runs for quite a while to take a screenshot or even inspect task manager).

Test script :

@echo on
:MAIN
start "myname" cmd /C where /R c:\ "whistle.*" 
@timeout /t 1 >null
TASKLIST /V /NH /fi "WINDOWTITLE eq myname" /FO "CSV"
TASKLIST /v /NH /fi "IMAGENAME eq Where.exe" /FO "CSV"
TASKKILL /f /fi "IMAGENAME eq cmd.exe" /fi "WINDOWTITLE eq myname"
TASKLIST /V /NH /fi "WINDOWTITLE eq myname" /FO "CSV"
:exit

Output :

==> D:\bat\SO\36185868.bat

==> start "myname" cmd /C where /R c:\ "whistle.*"

==> TASKLIST /V /NH /fi "WINDOWTITLE eq myname" /FO "CSV"
"cmd.exe","3340","Console","1","2 240 K","Running","pcn\usern","0:00:00","myname"

==> TASKLIST /v /NH /fi "IMAGENAME eq Where.exe" /FO "CSV"
"where.exe","5188","Console","1","3 184 K","Unknown","pcn\usern","0:00:01","N/A"

==> TASKKILL /f /fi "IMAGENAME eq cmd.exe" /fi "WINDOWTITLE eq myname"
SUCCESS: The process with PID 3340 has been terminated.

==> TASKLIST /V /NH /fi "WINDOWTITLE eq myname" /FO "CSV"
"where.exe","5188","Console","1","3 184 K","Running","pcn\usern","0:00:01","myname"

==>

Screenshot :

任务

Thank you guys for helping. I used TASKKILL /f /t /fi "IMAGENAME eq cmd.exe" /fi "WINDOWTITLE eq myname" command. /t is used to close all child processes and java.exe being 1 of its child process was closed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM