tasklist & taskkill
Every running program is a process with a numeric PID (process ID). Task Manager shows them in a window; from the command line you list them with tasklist and stop them with taskkill. Both work in any Command Prompt, both can target remote computers, and both produce text that batch scripts can filter.
If processes, PIDs and parent/child relationships are new to you, read Processes in the OS course first.
tasklist
With no options, tasklist prints one row per process:
C:\Users\ada>tasklist
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 8 K
System 4 Services 0 5,936 K
Registry 156 Services 0 58,412 K
smss.exe 512 Services 0 1,284 K
csrss.exe 804 Services 0 6,140 K
svchost.exe 1120 Services 0 31,876 K
explorer.exe 6248 Console 1 184,220 K
chrome.exe 8812 Console 1 412,336 K
chrome.exe 9104 Console 1 96,480 K
Code.exe 10716 Console 1 238,904 K
cmd.exe 11532 Console 1 5,412 K
tasklist.exe 12008 Console 1 10,288 KSample output, shortened (a typical PC runs 200–300 processes). The columns:
| Column | Meaning |
|---|---|
| Image Name | the executable's file name. Several processes can share it (one chrome.exe per tab group) |
| PID | the unique ID of this process right now. PIDs are reused after a process exits |
| Session Name / Session# | Services (session 0) holds system processes and services; your desktop is Console, session 1 or higher. Remote Desktop users get RDP-Tcp#N |
| Mem Usage | the process's working set: physical RAM it currently uses, in KB |
Notice that tasklist.exe lists itself: it is a process too, alive just long enough to print the list.
Filtering and formats
| Option | Effect |
|---|---|
/fi "IMAGENAME eq chrome.exe" |
filter; operators eq ne gt lt ge le. Other fields: PID, STATUS (RUNNING, NOT RESPONDING), MEMUSAGE (KB), USERNAME, WINDOWTITLE, SERVICES, SESSION |
/v |
verbose: adds Status, User Name, CPU Time and Window Title |
/svc |
lists the services hosted inside each process (handy for svchost.exe) |
/m [dll] |
lists the DLLs each process has loaded, or which processes use one DLL |
/fo table|list|csv |
output format; /nh removes the header |
/s pc /u user |
ask another computer |
C:\Users\ada>tasklist /fi "imagename eq chrome.exe" /fi "memusage gt 200000"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
chrome.exe 8812 Console 1 412,336 K
C:\Users\ada>tasklist /fi "status eq not responding"
INFO: No tasks are running which match the specified criteria.
C:\Users\ada>tasklist /svc /fi "pid eq 1120"
Image Name PID Services
========================= ======== ============================================
svchost.exe 1120 BrokerInfrastructure, DcomLaunch, PlugPlay,
Power, SystemEventsBrokerSeveral /fi options are combined with AND. A filter that matches nothing prints an INFO: line, and tasklist still exits with 0, so test whether something is running by searching its output, not by errorlevel:
tasklist /fi "imagename eq notepad.exe" /nh | find /i "notepad.exe" >nul && echo Notepad is runningProcessing tasklist output in batch
For scripts, ask for CSV without a header: every value is quoted and fields are separated by commas, so nothing depends on column widths.
C:\Users\ada>tasklist /fo csv /nh /fi "imagename eq chrome.exe"
"chrome.exe","8812","Console","1","412,336 K"
"chrome.exe","9104","Console","1","96,480 K"The playground can't run tasklist, so the following examples save a captured CSV list to a file first. On your PC you would read the live output instead, with for /f ... in ('tasklist /fo csv /nh').
The memory value itself contains a comma ("412,336 K"), so splitting at commas cuts it in two: %%e gets "412 and %%f gets 336 K". The trick is tokens=1,2,5*: take image and PID, skip to the fifth piece and put everything from there into the next letter, then strip quotes, commas and K:
@echo off
setlocal enabledelayedexpansion
(
echo "explorer.exe","6248","Console","1","184,220 K"
echo "chrome.exe","8812","Console","1","412,336 K"
echo "chrome.exe","9104","Console","1","96,480 K"
echo "Code.exe","10716","Console","1","238,904 K"
echo "chrome.exe","9330","Console","1","51,204 K"
echo "cmd.exe","11532","Console","1","5,412 K"
) > procs.csv
for /f "tokens=1,2,5* delims=," %%a in (procs.csv) do (
set "mem=%%~c,%%~d"
set "mem=!mem:"=!"
set "mem=!mem:,=!"
set "mem=!mem: K=!"
echo %%~a PID %%~b !mem! KB
)explorer.exe PID 6248 184220 KB
chrome.exe PID 8812 412336 KB
chrome.exe PID 9104 96480 KB
Code.exe PID 10716 238904 KB
chrome.exe PID 9330 51204 KB
cmd.exe PID 11532 5412 KB
Values under 1,000 KB have no comma, so in a real list %%d can be empty; joining both pieces and deleting the commas handles both cases.
Now a small report: how many chrome.exe processes, how much memory together, and which processes use more than 200 MB:
@echo off
setlocal enabledelayedexpansion
(
echo "explorer.exe","6248","Console","1","184,220 K"
echo "chrome.exe","8812","Console","1","412,336 K"
echo "chrome.exe","9104","Console","1","96,480 K"
echo "Code.exe","10716","Console","1","238,904 K"
echo "chrome.exe","9330","Console","1","51,204 K"
echo "cmd.exe","11532","Console","1","5,412 K"
) > procs.csv
set /a count=0, totalKB=0
for /f "tokens=1,2,5* delims=," %%a in (procs.csv) do (
set "mem=%%~c,%%~d"
set "mem=!mem:"=!"
set "mem=!mem:,=!"
set /a kb=!mem: K=!
if /i "%%~a"=="chrome.exe" set /a count+=1, totalKB+=kb
if !kb! GTR 200000 echo big: %%~a ^(PID %%~b^) uses !kb! KB
)
set /a totalMB=totalKB/1024
echo chrome.exe: %count% processes, %totalMB% MB in totalbig: chrome.exe (PID 8812) uses 412336 KB
big: Code.exe (PID 10716) uses 238904 KB
chrome.exe: 3 processes, 546 MB in total
if /i compares case-insensitively, which matters because image names keep whatever case the file has (Code.exe).
taskkill
taskkill ends processes by name (/im) or by PID (/pid). You can repeat either option, and /im accepts * wildcards.
C:\Users\ada>taskkill /im notepad.exe
SUCCESS: Sent termination signal to the process "notepad.exe" with PID 10244.
C:\Users\ada>taskkill /pid 8812 /pid 9104 /f
SUCCESS: The process with PID 8812 has been terminated.
SUCCESS: The process with PID 9104 has been terminated.
C:\Users\ada>taskkill /im chrome.exe /t /f
SUCCESS: The process with PID 9330 (child process of PID 8812) has been terminated.
SUCCESS: The process with PID 8812 (child process of PID 6248) has been terminated.
C:\Users\ada>taskkill /im nosuch.exe
ERROR: The process "nosuch.exe" not found.
C:\Users\ada>taskkill /im MsMpEng.exe /f
ERROR: The process "MsMpEng.exe" with PID 4012 could not be terminated.
Reason: Access is denied.Sample output. What the options mean:
| Option | Effect |
|---|---|
(no /f) |
polite: asks the program to close, like clicking ✕. It can show "Save changes?" or refuse. Console programs and services usually need /f |
/f |
force: the process is terminated immediately; unsaved work is lost |
/t |
tree: also ends every child process the target started |
/fi "..." |
the same filters as tasklist, e.g. /fi "status eq not responding" |
Exit codes: 0 success, 128 no matching process, 1 access denied or another failure. Processes of other users and protected system processes need an elevated prompt, and some (antivirus, csrss.exe) can't be killed at all.
Tip: kill by PID when several processes share a name and you only want one of them. Kill by name with
/twhen you want an application and all of its helpers gone.
A safe "kill if running" helper
Because taskkill complains loudly when nothing matches, scripts usually check first and hide the message. In the playground the check is done against the saved list instead of the live tasklist, and echo shows the command that would run:
@echo off
(
echo "explorer.exe","6248","Console","1","184,220 K"
echo "chrome.exe","8812","Console","1","412,336 K"
echo "Code.exe","10716","Console","1","238,904 K"
) > procs.csv
for %%p in (chrome.exe notepad.exe code.exe) do call :stop %%p
goto :eof
:stop
findstr /i /c:"\"%~1\"" procs.csv >nul
if errorlevel 1 (
echo %~1 is not running, nothing to do
) else (
echo would run: taskkill /im %~1 /t /f
)
exit /bwould run: taskkill /im chrome.exe /t /f
notepad.exe is not running, nothing to do
would run: taskkill /im code.exe /t /f
On a real machine the findstr line becomes tasklist /fo csv /nh | findstr /i /c:"\"%~1\"" >nul, and the echo would run: line becomes the real taskkill /im %~1 /t /f >nul 2>&1. Searching for the name with its quotes avoids false matches such as code.exe inside vscode.exe.
PowerShell equivalents
| CMD | PowerShell |
|---|---|
tasklist |
Get-Process |
tasklist /fi "imagename eq chrome.exe" |
Get-Process chrome |
tasklist /fi "memusage gt 200000" |
Get-Process | Where-Object WorkingSet64 -gt 200MB |
taskkill /pid 8812 /f |
Stop-Process -Id 8812 -Force |
taskkill /im notepad.exe |
Stop-Process -Name notepad |
Get-Process returns objects, so memory is already a number and no CSV parsing is needed. On Linux the same jobs are done by ps, pgrep and kill (Linux Processes).
Test yourself
What does the Mem Usage column of tasklist show?
- The process's virtual address space size in MB
- Its working set: physical memory currently used, in KB
- Its total disk usage
- The memory limit set for the process
What is the difference between taskkill /im app.exe and taskkill /im app.exe /f?
- No difference; /f only hides messages
- Without /f the program is asked to close (and may refuse or prompt); /f terminates it immediately
- /f also kills child processes
- /f kills it on every computer in the domain
Why should a script not use errorlevel after tasklist /fi "imagename eq app.exe" to see if app.exe runs?
- tasklist exits with 0 even when no process matches; it only prints an INFO line
- tasklist never sets errorlevel to anything but 9009
- Filters only work with /v
- errorlevel can't be read after tasklist