taskkill: Terminate Processes in CI Cleanup
taskkill terminates a process by image name (/IM) or PID (/PID); CI uses it to clean up servers and stuck tools, with /F to force and /T to take down the child tree.
A test that starts a server must stop it, even on failure. taskkill is the Windows way to guarantee no orphaned process holds a port or file lock into the next run.
What it does
taskkill sends a stop request to one or more processes selected by /IM (image/exe name) or /PID. /F forces termination instead of a graceful close, and /T also kills the process's child tree. Filters with /FI narrow by window title, status, or memory.
Common usage
:: kill all node.exe, forcefully, including children
taskkill /IM node.exe /F /T
:: kill one process by PID
taskkill /PID 12345 /F
:: PowerShell equivalent
Stop-Process -Name node -Force -ErrorAction SilentlyContinueOptions
| Flag | What it does |
|---|---|
| /IM <name> | Match by image name, e.g. node.exe (supports *) |
| /PID <id> | Match a specific process id |
| /F | Force termination |
| /T | Also terminate child processes |
| /FI <filter> | Filter, e.g. "STATUS eq NOT RESPONDING" |
In CI
In cleanup steps that should not fail the job, ignore taskkill's exit when the process is already gone (the PowerShell Stop-Process ... -ErrorAction SilentlyContinue form, or taskkill ... 2>nul || ver >nul). Use /T so a wrapper process does not leave orphaned children holding ports.
Common errors in CI
"ERROR: The process \"node.exe\" not found." means it already exited; in cleanup this is fine, so suppress the non-zero exit. "ERROR: The process with PID ... could not be terminated. Reason: Access is denied." means the process runs as another user or needs elevation; run the step elevated or add /F. "ERROR: Invalid argument/option" usually means /IM was given a PID or vice versa.