Skip to content
shellmap

stop-servicePowerShell's stop-service cmdlet — like systemctl stop across all 5 shells

Equivalents in every shell

Bashunix
sudo systemctl stop nginx

systemd: `systemctl stop <name>` sends `SIGTERM`, waits for `TimeoutStopSec` (default 90s), then `SIGKILL`. `systemctl kill <name>` skips the wait. SysV-init: `sudo service nginx stop`. Both block until the service exits — for fire-and-forget use `--no-block`. Returns 0 on success even if the service was already stopped.

Zshunix
sudo launchctl bootout system/com.example.svc

macOS launchd: modern API is `launchctl bootout <domain>/<service>` (10.10+); legacy `launchctl unload <plist>` still works. `launchctl stop <label>` halts the service WITHOUT unloading it (will restart on RunAtLoad / KeepAlive). On macOS 13+, prefer `launchctl bootout gui/$(id -u)/com.example.svc` for user agents.

Fishunix
sudo systemctl stop nginx

Same external commands. Fish has no native service primitives.

PowerShellwindows
Stop-Service -Name w3svc

PowerShell-native cmdlet. Sends a `STOP` control signal via the SCM (Service Control Manager). Use `-Force` to stop a service that has DEPENDENT services (without `-Force`, the cmdlet errors out with the dependent list). `-PassThru` returns the resulting `[ServiceController]`. Requires elevation.

cmd.exewindows
sc stop w3svc

Built-in `sc stop <name>` sends a STOP control. `net stop <name>` is the older interface — prompts for confirmation if the service has dependents (and lists them). Both require elevation. `taskkill /f /im <process>.exe` kills the underlying process directly but bypasses SCM bookkeeping (status will show `STOP_PENDING` until SCM notices).

Worked examples

Stop a single service

Bash
sudo systemctl stop nginx
Zsh
sudo launchctl bootout system/org.nginx.nginx
PowerShell
Stop-Service -Name w3svc
cmd.exe
sc stop w3svc

Force-stop a service that has dependents

Bash
sudo systemctl kill nginx
PowerShell
Stop-Service -Name MSSQLSERVER -Force
cmd.exe
net stop MSSQLSERVER /y

Stop multiple matching services in one call

Bash
sudo systemctl stop "*.timer"
PowerShell
Get-Service -Name "Win*" | Where-Object Status -eq Running | Stop-Service

Gotchas

  • `Stop-Service` (and `sc stop`) returns SUCCESS when the SCM accepts the STOP request, NOT when the service has actually exited. The `Stop-Service` cmdlet then BLOCKS up to 30 seconds waiting for `STOPPED` status before returning; use `-NoWait` to fire-and-forget, or `(Get-Service w3svc).WaitForStatus('Stopped', '00:01:00')` for a longer custom wait.
  • `Stop-Service -Force` ONLY overrides the dependent-services check; it does NOT force a kill of an unresponsive service. If a service hangs in STOP_PENDING, the only escape is `taskkill /f /pid <pid>` (find the PID with `Get-CimInstance Win32_Service -Filter "Name='svc'" | Select-Object ProcessId`).
  • systemd `systemctl stop` honours the unit's `TimeoutStopSec` and ExecStop scripts. A misbehaving service can ignore SIGTERM up to that timeout — increase visibility with `journalctl -u nginx -f` while stopping. To globally bypass timeouts on emergency shutdown, `systemctl --signal=SIGKILL kill nginx`.
  • macOS `launchctl stop` and `launchctl bootout` are SUBTLY DIFFERENT: `stop` halts the running instance but the LaunchAgent stays loaded — KeepAlive=true will restart it immediately. `bootout` unloads the agent definition entirely. Confusing the two is the biggest single launchd gotcha. For "really off, stay off until reboot" use `bootout`.
  • cmd `net stop` is interactive — it PROMPTS for "do you also want to stop dependent services?" and the prompt blocks scripts. Use `net stop <name> /y` (auto-yes), `sc stop <name>` (no prompt, but does not stop dependents — they fail-fast), or `Stop-Service -Force` (PS, recursively stops dependents in correct order).

WSL & PowerShell Core notes

pwsh`Stop-Service` exists on Linux/macOS pwsh as a Windows-only no-op (returns "service not found" because there are no Win32 services). The cross-platform pattern is platform branching: `if ($IsWindows) { Stop-Service nginx } elseif ($IsLinux) { sudo systemctl stop nginx } elseif ($IsMacOS) { sudo launchctl bootout system/org.nginx.nginx }`.
WSLFrom Windows pwsh, `wsl sudo systemctl stop nginx` stops a service inside the WSL distro (requires `systemd=true` in `/etc/wsl.conf` and WSL 0.67.6+). From WSL bash, `pwsh.exe -c 'Stop-Service nginx'` stops a Windows-host service — but requires running the WSL terminal "as Administrator" because Windows service control needs an elevated token even via interop.

Common tasks using stop-service

Related commands