![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-18 04:25 |
47,814 topics / 349,907 posts / today 4 new / 48,259 members |
| DOS疑难解答 & 问题讨论 (解答室) » How to tell whether a process is running? |
| Printable Version 1,086 / 7 |
| Floor1 qy33 | Posted 2006-04-16 20:10 |
| 新手上路 Posts 3 Credits 10 | |
|
As the title says, how can I tell whether a certain process has already started?
If it has started, then terminate it. How should this batch file be written? |
|
| Floor2 3742668 | Posted 2006-04-17 00:54 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
Method 1:
wmic process where name="cmd.exe" call terminate Method 2: tasklist | find "cmd.exe" && taskkill /fi "imagename eq cmd.exe" The runtime environment needs XP PRO. There are quite a lot of commands related to processes in XP. To view processes you can use tasklist and wmic process. To terminate a process you can use call terminate in wmic, or taskkill, or tskill, or NTSD's -p(PID) or -pn(name). |
|
| Floor3 Wengier | Posted 2006-04-17 01:23 |
| 系统支持 Posts 10,521 Credits 27,736 | |
|
Method 2 can probably be simplified a bit more:
tasklist | find "cmd.exe" && taskkill /im cmd.exe |
|
| Floor4 3742668 | Posted 2006-04-17 01:39 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
Oops, here comes the nitpicker.。。
True, using the /im parameter is indeed more convenient and a bit simpler. But judging from Microsoft's development trend and from the standpoint of cultivating good habits, I generally prefer using findstr instead of find, and /fi instead of /im. In Microsoft's terms, that should count as standardization, I guess. Also, /fi supports wildcards. Oops, the nitpicker is the webmaster, gotta run fast.。。 [ Last edited by 3742668 on 2006-4-17 at 01:43 ] |
|
| Floor5 Wengier | Posted 2006-04-17 01:50 |
| 系统支持 Posts 10,521 Credits 27,736 | |
|
Hehe, of course it wouldn't be "arguing for the sake of it"; the forum is meant to be a place for mutual learning, discussion, and exchange.
Things like findstr really are more formal/standardized (as mentioned above), while things like find are comparatively a simplified approach, very much in the standard DOS style. You could say each has its own characteristics, suitable for users with different habits or requirements. |
|
| Floor6 qy33 | Posted 2006-04-18 01:18 |
| 新手上路 Posts 3 Credits 10 | |
|
Thanks to the two experts above for the answers.
It works under XP. But what about under Win 2000? taskkill doesn't work. |
|
| Floor7 JonePeng | Posted 2006-04-20 23:56 |
| 金牌会员 Posts 1,883 Credits 4,562 From 广东广州 | |
Originally posted by qy33 at 2006-4-18 01:18: There is no TaskKill under Win2000, but you can use the command “ntsd -c q -p PID” instead. For example, if a certain process has PID “444”, then you can execute the command “ntsd -c q -p 444” to forcibly close that process. |
|
| Floor8 qy33 | Posted 2006-05-01 17:05 |
| 新手上路 Posts 3 Credits 10 | |
|
Then how do you check what the process PID is?
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |