China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-30 08:35
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » How to tell whether a process is running? View 1,031 Replies 7
Original Poster Posted 2006-04-16 20:10 ·  中国 湖北 武汉 电信
新手上路
Credits 10
Posts 3
Joined 2006-04-16 19:58
20-year member
UID 53940
Status Offline
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?
Floor 2 Posted 2006-04-17 00:54 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
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).
Floor 3 Posted 2006-04-17 01:23 ·  加拿大 Bell
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Method 2 can probably be simplified a bit more:

tasklist | find "cmd.exe" && taskkill /im cmd.exe
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 4 Posted 2006-04-17 01:39 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
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 ]
Floor 5 Posted 2006-04-17 01:50 ·  加拿大 Bell
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
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.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 6 Posted 2006-04-18 01:18 ·  中国 湖北 武汉 电信
新手上路
Credits 10
Posts 3
Joined 2006-04-16 19:58
20-year member
UID 53940
Status Offline
Thanks to the two experts above for the answers.
It works under XP.

But what about under Win 2000?
taskkill doesn't work.
Floor 7 Posted 2006-04-20 23:56 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Originally posted by qy33 at 2006-4-18 01:18:
But what about under Win 2000?
taskkill doesn't work.

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.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 8 Posted 2006-05-01 17:05 ·  中国 湖北 武汉 电信
新手上路
Credits 10
Posts 3
Joined 2006-04-16 19:58
20-year member
UID 53940
Status Offline
Then how do you check what the process PID is?
Forum Jump: