Updated: 22 October 2026 · Applies to: procps-ng 4.0.4 and psmisc on Ubuntu 26.04, systemd 257 on AlmaLinux 10.2, tested; the same commands work on Ubuntu 24.04, Debian 13 and Rocky Linux

Find the process ID (PID) with pgrep, then stop it with kill, or do both in one step with pkill. A program that runs as a service (nginx, Apache, MySQL, PHP-FPM) should not be killed at all: restart it with systemctl restart instead. The examples below use a program called myapp; replace it with your own process name.

pgrep -a myapp

Output (PID and full command):

72 /bin/bash /usr/local/bin/myapp
73 /bin/bash /usr/local/bin/myapp
kill 72

Find the process

  • pgrep NAME prints only the PIDs. Add -a to see the full command line, -u USER to limit it to one user, and -x to match the name exactly.
  • pgrep -f matches against the whole command line, so you can pick one of several copies of the same program by its arguments.
  • pidof NAME works for normal programs, but it skips scripts: for a shell or Python script use pidof -x.
  • ps shows more detail, such as the user and how long the process has run.

Find the PIDs of a script by name:

pidof -x myapp

Output:

73 72

Pick the copy started with --port 8082:

pgrep -af 'myapp --port 8082'

Show user, running time and command for every myapp process:

ps -C myapp -o pid,user,etime,args

Output:

    PID USER         ELAPSED COMMAND
     72 root           00:00 /bin/bash /usr/local/bin/myapp
     73 root           00:00 /bin/bash /usr/local/bin/myapp

If you only know the port a program listens on, see How to Find Which Process Is Using a Port in Linux (ss, lsof, fuser). For a live view sorted by CPU or memory, see How to List and Find Running Processes in Linux (ps, top).

Kill a process by PID

  1. Find the PID with pgrep -a as shown above.
  2. Ask the process to stop. Plain kill sends SIGTERM (signal 15), which lets the program close files and clean up:
    kill 72
  3. Check that it is gone. No output from pgrep (exit status 1) means no process matched:
    pgrep -a myapp
  4. Only if it is still there after a few seconds, force it with SIGKILL (signal 9). The process cannot catch or ignore this signal, so it gets no chance to save anything:
    kill -9 72

In our test, a script that traps SIGTERM printed "ignoring TERM" and kept running after kill; kill -9 ended it at once. Several PIDs can go on one line:

kill 72 73

Kill processes by name

pkill takes the same matching options as pgrep and signals every match. Check the list with pgrep -a first, because a short name can match more than you expect (in a test, pkill sleep also stopped an unrelated sleep that kept a container alive).

pkill myapp

Only the copy started with --port 8082:

pkill -f 'myapp --port 8082'

Only processes of the user alice:

pkill -u alice myapp

Add -e to print what was killed, or -9 to send SIGKILL. killall also works by exact name and reports each process with -v:

killall -v myapp

Output:

Killed myapp(135) with signal 15
Killed myapp(136) with signal 15

If you see killall: command not found (as in a minimal Ubuntu 26.04 image), install the psmisc package, which also provides pstree and fuser:

sudo apt install psmisc

Common signals

  • 15, TERM: the default; asks the program to exit cleanly.
  • 9, KILL: ends the process at once; use it last.
  • 1, HUP: many daemons reload their settings on it. According to nginx, its master process re-reads the configuration on HUP, while a program without a handler simply exits.
  • 2, INT: the same as pressing Ctrl+C.

You can give a signal by number or by name. These three commands do the same:

kill -15 72
kill -TERM 72
kill -s TERM 72

To list every signal:

kill -l

Restart a process

For anything managed by systemd, restart it through systemd. It stops the old process and starts a new one with a new PID:

sudo systemctl restart nginx

Check that it came back:

systemctl status nginx --no-pager

To reload the settings when the service supports it, and restart it otherwise:

sudo systemctl reload-or-restart nginx

Plain reload on a service without reload support fails with "Job type reload is not applicable". To restart a service only if it is already running:

sudo systemctl try-restart nginx

Do not kill a service's process by hand to restart it. In our test on AlmaLinux 10, a service with Restart=on-failure came back after kill -9, but stayed stopped after a plain kill, because SIGTERM counts as a clean exit.

If a restart fails with "Start request repeated too quickly", read the service log to find the cause:

journalctl -u nginx --no-pager -n 50

Then clear the failure counter and try again:

sudo systemctl reset-failed nginx
sudo systemctl restart nginx

A program you started yourself, outside systemd, has no restart command: stop it and start it again the same way you started it. For a program started in the background with nohup:

pkill -x myapp
nohup myapp >/tmp/myapp.log 2>&1 &

Then confirm the new PID:

pgrep -a myapp

If such a program has to stay up, turn it into a systemd service so it restarts on failure and after a reboot.

Errors you may see

  • kill: (72) - No such process: the process already ended, or the PID is wrong.
  • kill: (127) - Operation not permitted: the process belongs to another user. Run the command with sudo.
  • myapp: no process found from killall, or exit status 1 from pkill: nothing matched the name.
  • A process in state Z (zombie) in ps is already dead and is waiting for its parent to collect it. Killing it does nothing; restarting or stopping the parent clears it.

Related guides: Get a Process Name From a PID in Linux, or a PID From a Name, Find the Process Using a Port in Linux and Stop It (lsof, ss) and How to Restart the SSH Service (sshd) on Linux: Ubuntu, Debian, AlmaLinux and Rocky Linux.

Official documentation: pgrep and pkill, signal(7) and systemctl.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket