HB Computer Security | Aide Memoire
  • Introduction
  • Core Technical Skills
    • Core Skills
      • Linux
        • Getting to Know Linux
          • Using the Shell
            • Shells, Terminals, and Virtual Consoles
            • Choose your Shell
            • Shell Commands
              • Non-PATH Commands
              • Command History
                • Command Line Editing
                  • Keystrokes for Navigating Command Lines
                  • Keystrokes for Editing Command Lines
                  • Keystrokes for Cutting and Pasting Text from within Command Lines
                • Command Line Recall
                  • Keystrokes for Command Line Recall
              • Connecting and Expanding Commands
                • Piping Between Commands
                • Sequential Commands
                • Expanding Commands
            • Shell Variables
              • Common Shell Variables
            • Aliases
            • Create your Own Shell Environment
              • Modification Ideas
          • Navigating the Linux File System (LFS)
            • Filesystem Commands
            • Listing Files and Directories
            • File Permissions and Ownership
              • Modifying Permissions with chmod
              • Modifying Default Permissions with umask
              • Change File Ownership with chown
            • Copying, Moving, and Removing Files
            • Finding Files
              • locate
              • find
              • grep
            • Downloading Files
              • axel
              • wget
              • curl
                • User-Agent: Googlebot
          • Working with Text Files
            • Using vim and vi to Edit Text Files
              • Starting with vi
              • Adding Text
              • Moving Around in the Text
            • Text Manipulation
        • System Administration
          • Installing Linux
            • Installing from Live Media
            • Installing in the Enterprise
            • Partitioning Hard Disks
              • Tips for Creating Partitions
          • Account Administration
            • The root Account
              • Becoming root with su
              • sudo
                • The /etc/sudoers File
                • Granting sudo privileges
                  • visudo Guidance
                • Useful sudo Hints
            • Other Administrative Accounts
            • Standard User Accounts
              • Risks of userdel: Orphaned Files
          • Graphical Remote Administration
            • Cockpit
              • Installation Guide
            • Remote Desktop Protocol with xrdp
              • Installation and Configuration
            • Remote Desktop with vnc
              • Installation and Configuration
              • Running VNC as a System Service
          • Managing Running Processes
            • Listing Processes
              • ps
              • top
              • htop
            • Backgrounding and Foregrounding
              • Starting a Background Process
              • Using Foreground and Background Commands
            • Killing and Recining Processes
              • kill and killall
          • Managing Software
            • Managing Software from the Desktop
            • Going Beyond the Limitations of Software Center
              • Debian Packages
                • Advanced Package Tool (apt)
                • Repositories
                • dpkg
        • Shell Scripting
          • Variables
            • Command Substitution
            • Arguments
          • Reading User Input
          • if, else, and elif
          • BOOLEAN Logic
          • Loops
            • for Loops
            • while Loops
          • Functions
          • Local Vs Global Variables
          • Summary
        • Securing Linux
      • Windows
        • Security Hardening
Powered by GitBook
On this page
  • Using kill to Signal Process by PID
  • Using killall to Signal a Process by Name

Was this helpful?

  1. Core Technical Skills
  2. Core Skills
  3. Linux
  4. System Administration
  5. Managing Running Processes
  6. Killing and Recining Processes

kill and killall

Although usually used for ending a running process, the kill and killall commands can actually be used to send any valid signal to a running process.

Signals are represented by both numbers and names. Signals that you might send most commonly from a command include SIGKILL (9), SIGTERM (15), and SIGHUP (1). The default signal is SIGTERM, which tries to terminate a process cleanly. Different processes respond to different signals. However, processes cannot block SIGKILL and SIGSTOP signals.

The following table shows the signals available in Linux:

Signal

Number

SIGHUP

1

SIGINT

2

SIGQUIT

3

SIGABRT

6

SIGKILL

9

SIGTERM

15

SIGCONT

18, 19, 25

SIGSTOP

17, 19, 23

Using kill to Signal Process by PID

Let's consider an example. Let's say you have run the top command, and you notice that the bigcommand process is consuming most of your processing power:

TOP OUTPUT EXAMPLE
PID   USER  PR NI VIRT RES  SHR S %CPU %MEM TIME+    COMMAND
10432 chris 20 0  471m 121m 18m S 99.9 3.2  77:01.76 bigcommand

So, we can see that the bigcommand process is consuming 99.9 percent of the CPU. You decide that you want to kill it so that other processes have a shot at the CPU. Here are some examples of the kill command that you can use, leveraging the process ID:

#Default sending of SIGTERM
kill 10432

#Manually selecting SIGTERM - achieves the same outcome as a default kill
kill -15 10432

#Manually selecting SIGKILL by name, not number
kill -SIGTERM 10432

On occasion, a SIGTERM doesn’t kill a process, so you may need a SIGKILL to kill it. Instead of SIGKILL, you can use –9 to get the same result

Another useful signal is SIGHUP. If, for example, something on your GNOME desktop, you could send the gnome-shell a SIGHUP signal to reread its configuration files and restart the desktop. If the process ID for gnome-shell were 1833, here are two ways you could send it a SIGHUP signal:

#Sending SIGHUP from numberic value
kill -1 1833

#Sending SIGHUP by shortened name
killall -HUP gnome-shell

Using killall to Signal a Process by Name

With the killall command, you can signal processes by name instead of by process ID. The advantage is that you don’t have to look up the process ID of the process that you want to kill. The potential downside is that you can kill more processes than you mean to if you are not careful. For example, typing killall bash may kill a bunch of shells that you don’t mean to kill.

Like the kill command, killall uses SIGTERM (15) if you don’t explicitly enter a signal number. Also as with kill, you can send any signal you like to the process you name with killall. For example, if you see a process called testme running on your system and you want to kill it, you can simply enter the following:

killall -9 testme

Whilst there is a natural danger, as outlined above, the killall command can be particularly useful if you want to kill a bunch of commands of the same name

PreviousKilling and Recining ProcessesNextManaging Software

Last updated 3 years ago

Was this helpful?