Killing processes in UNIX

Q. Sometime I need to stop a command or task under UNIX. I also noticed that some process will ignore my keystroke-generated signals such as CTRL + C or CTRL+D, so my question is – How do I kill process in UNIX?


A. You need to use a command called kill. The kill utility sends a signal to the processes specified by the pid operand(s). Only the super-user (root) may send signals to other users’ processes.

kill command syntax

The kill command causes the specified signal to be sent to the specified process. The kill command has the general form as follows:
kill –N PID

  • N is a signal number
  • PID is the Process Identification Number. If you do not know the PID, it can be learned through the ps command.

Understanding signal numbers

The signal number 1 is a hangup signal. I recommended using 1 signal because it should kill the process and it can save the buffer (if supported). For example if it is an editor, save the buffer. This is the default if you do not specify a signal number. Signal number 9, a kill signal, is the surest way to kill a process.

Some of the more commonly used signals:

signal #Usage
1 HUP (hang up)
2 INT (interrupt)
3 QUIT (quit)
6 ABRT (abort)
9 KILL (non-catchable, non-ignorable kill)
14 ALRM (alarm clock)
15 TERM (software termination signal)

How do I use kill command?

Terminate the processes with pids 1412 and 1157:
$ kill 1412 1157
Send the hangup signal (SIGHUP) to the process with pid 5071:
# kill -s HUP 5071
Terminate the process group with pgid 12117:
# kill -- -12117
If you do not know the PID of a process, you can learn it by issuing a process status command, ps.
# ps | more
# ps | grep file.c
# ps | grep -i httpd

To send -9 (KILL) singal to the processo with pid 1234, enter:
# kill -9 1234

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

8 comments… add one
  • Rajendra Dec 4, 2009 @ 18:44

    how to find PID?

    • anilkumar Jul 28, 2011 @ 10:29

      # ps | more
      # ps | grep file.c
      # ps | grep -i httpd

  • hereis Dec 29, 2009 @ 2:08

    use the command –top-
    and if you want to kill a process
    just hit “k” and then the “pid” of
    the process and then input the signal
    that’s ok.

  • Anil Dewani May 15, 2010 @ 17:45


    you can use pidof command, example:

    # pidof openvpn

    or you can even use ps command and fetch the PID from it, example:

    # ps | grep openvpn | awk ‘{print $1}’`

  • Luciano Nov 10, 2011 @ 16:31

    @Anil Dewani

    U made my day with that hint: # ps | grep openvpn | awk ‘{print $1}’`

    I finally completed / fixed a script.

  • Goutham Jan 4, 2012 @ 5:42

    How to find the process id of a process which has already been killed in UNIX?

    • yuvaraj.m Feb 2, 2012 @ 19:04

      how do you find the process id (PID)?
      One of the most common uses is to terminate hanging daemons.
      For instance, you want to stop a daemon called LALALA. To find
      out the PID of the LALALA, you execute the “ps -ef | grep LALALA”
      command from a shell terminal. The “ps -ef | grep LALALA”
      command lists all processes running in a full listing format, which
      includes the process id. Then the command filters out the process
      name in “grep LALALA”.
      Example: ps -ef | grep LALALA
      LALALA 7209 32097 0 12:17 pts/87 00:00:00 ps -ef

    • ramkumar Jul 19, 2014 @ 6:24

      $ps ax

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.