Kill all processes of a user
Terminate every process owned by a given user — useful for forced logout, cleanup, and runaway-session containment.
How to kill all processes of a user in each shell
Bashunix
sudo pkill -u aliceAdd `-9` for SIGKILL (`pkill -9 -u alice`) when SIGTERM is ignored. Preview first: `pgrep -u alice -l` lists name+PID without killing.
Zshunix
sudo pkill -u aliceFishunix
sudo pkill -u alicePowerShellwindows
Get-Process -IncludeUserName | Where-Object UserName -eq 'DOMAIN\alice' | Stop-Process -Force`-IncludeUserName` REQUIRES ADMIN — without elevation it returns blank UserName and the filter silently passes nothing (no-op). For local-only accounts use `"$env:COMPUTERNAME\alice"`.
cmd.exewindows
taskkill /F /FI "USERNAME eq alice"Case-insensitive `/FI` filter. `/F` forces (Windows has no soft-signal equivalent). Preview with `tasklist /FI "USERNAME eq alice"`.
Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.
Gotchas & notes
- `pkill -u USER` is present on Linux + BSD/macOS (procps-ng on Linux, BSD procctl on macOS — same flag surface). `killall -u alice` on Linux (util-linux variant) does the same — but BEWARE: BSD `killall` historically kills by NAME ONLY and ignores `-u` (it predates the GNU semantics). Two completely different binaries share the name. Check with `man killall` first; `killall --version` only exists on Linux. Don't copy-paste cross-platform without re-reading the man page.
- pwsh edge: `Get-Process -IncludeUserName` shells out to a privileged API (`OpenProcessToken`) — non-admin sessions get `UserName` = `$null` on every process, so `Where-Object UserName -eq 'alice'` matches nothing. SILENT failure mode. Verify elevation first: `(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)`. There is no `Stop-Process -User` parameter — the Where/Stop two-step is the only path.
- cmd `taskkill /FI "USERNAME eq alice"` does NOT kill services running as alice (services live in a different session and require `sc.exe stop` or `Stop-Service`). It also misses elevated processes if the cmd window isn't elevated. For full-coverage logout-and-cleanup on Windows, prefer `logoff` (terminates the user's entire session, including services) or `query user` + `logoff <sessionID>`.
- SAFETY: `pkill -u $USER` (your CURRENT user) WILL kill your interactive shell mid-command — you may not see the second half of a piped script execute. If you're cleaning up your OWN user, run it under a different shell first (`sudo -u root bash -c "pkill -u $USER"`) or from a root TTY. On a remote server, `pkill -u alice` also drops alice's SSH session — by design but it can lock out your recovery path; keep a separate root SSH open until you confirm the desired state.
Related commands
Related tasks
- Kill a process by name— Terminate every running process whose executable matches a given name.
- Send a signal to a process— Deliver a specific Unix signal to a process — useful for graceful shutdown, config reload, and triggered behaviour.
- Find processes using the most CPU— List the top CPU-consuming processes — useful for performance triage, runaway-script detection, and capacity planning.
- Get the current username— Print the username running the current shell or script.