• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

pkill Command Examples in Linux

by admin

pkill command sends any specified signal, or by default the termination signal, to processes based on a matching pattern. Similar to the pgrep command, but actually sends a signal instead of printing to stdout. For example, if you start top in one terminal, and then issue pkill top in another terminal, you’ll see that top terminates. The command matched a name pattern rather than a process ID.

Syntax

The syntax of this command is:

# pkill [options] {pattern}

The kill and pkill commands send signals to processes directing them to terminate. Each signal has a number, name, and an associated event. Below are some of the most commonly used signals with their functionalities.

Number Name Description
1 SIGHUP Reload Configuration File
2 SIGINT Interrupt by keyboard (ctrl+c)
9 SIGKILL kill process
15 SIGTERM End process immediately. (Terminate a process in controlled manner so cleanup is possible)
18 SIGCONT Continue the process stopped with STOP
19 STOP Stop process
Note: However, there are processes that should not be terminated, such as the init process. Killing such processes can result in a system crash. A superuser can kill any process in the system.

pkill Command Examples

1. Kill all processes which match:

# pkill "process_name"

2. Kill all processes which match their full command instead of just the process name:

# pkill -f "command_name"

3. Force kill matching processes (can’t be blocked):

# pkill -9 "process_name"

4. Send SIGUSR1 signal to processes which match:

# pkill -USR1 "process_name"

5. Kill the main `firefox` process to close the browser:

# pkill --oldest "firefox"

6. The pkill command can be used to send a signal to processes running from a specific controlling Terminal, as shown in the following syntax:

# pkill -t [terminal_name] -U UID [command_pattern]

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to Find the Original Installation OS Version in CentOS/RHEL
  2. Understanding SELinux Policies in Linux
  3. fdisk: command not found
  4. jpegoptim for image optimization
  5. autoreconf: command not found
  6. kubectl: command not found
  7. CentOS / RHEL 7 : How to modify the kernel command line
  8. How to Trace Python Scripts using trace.py
  9. How to Change the Network Bonding Mode in CentOS/RHEL 6
  10. Configuring sudo to Enable Commands for Non-Root Users in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright