killall Command in Linux



The killall command in Linux is used to send signals to all processes that match the given name. Unlike the kill command, which requires Process IDs (PIDs), killall allows users to terminate processes by specifying their names. This makes it a powerful and convenient tool, especially when dealing with multiple instances of the same process.

Table of Contents

Here is a comprehensive guide to the options available with the killall command −

Syntax of killall Command

The basic syntax for the killall command is as follows −

killall [OPTIONS] <process_name>

Here, <process_name> is the name of the process you want to target.

The killall command sends signals to all processes that match the specified name. If no signal is specified, the default SIGTERM signal is used.

killall Command Options

The killall command offers a variety of options that enhance its functionality. Some of the most commonly used options include −

Option Description
-e, --exact Require an exact match for very long names.
-I, --ignore-case Ignore case when matching process names.
-g, --process-group Kill the process group to which the process belongs.
-i, --interactive Interactively ask for confirmation before killing each process.
-l, --list List all available signals.
-q, --quiet Do not complain if no processes are killed.
-r, --regexp Interpret process name as a regular expression.
-s, --signal <SIGNAL> Send a specific signal.
-u, --user <USER> Match only processes belonging to a specified user.
-v, --verbose Report if the signal was successfully sent.
-w, --wait Wait for all killed processes to die.
-Z, --context <CONTEXT> Match only processes running in the specified security context.

Examples of killall Command in Linux

Here are some detailed examples of using the Linux killall command with various options −

  • Terminating All Instances of a Process
  • Forced Termination with SIGKILL
  • Ignoring Case When Matching Process Names
  • Targeting Process by User
  • Verbose Mode
  • Interactively Confirming Each Kill

Terminating All Instances of a Process

To terminate all instances of a specific process, you can use the killall command with the default SIGTERM signal.

sudo killall <process_name>

Suppose you have multiple instances of a process named "firefox". By running killall firefox, you send the default SIGTERM signal to all instances of "firefox", requesting them to terminate gracefully.

killall Command in Linux1

Forced Termination with SIGKILL

If processes are not responding to the SIGTERM signal, you can use the SIGKILL signal to forcefully terminate them.

sudo killall -9 <process_name>

For instance, if you have several unresponsive instances of "firefox", you can forcefully terminate them by using killall -9 firefox. The SIGKILL signal ensures immediate termination of the processes.

killall Command in Linux2

Ignoring Case When Matching Process Names

If you want to match process names without considering case, use the -I option.

sudo killall -I <process_name>

For example, to terminate processes named "Firefox", "firefox", and "FIREFOX" regardless of case, use killall -I firefox. This ensures that all variations of the process name are targeted.

killall Command in Linux3

Targeting Processes by User

The killall command can send signals to processes belonging to a specific user.

sudo killall -u <user> <process_name>

To terminate all instances of "firefox" running under the user "linux", use killall -u linux firefox. This targets processes named "firefox" that are owned by the specified user.

killall Command in Linux4

Verbose Mode

To get detailed information about the processes being terminated, use the -v option for verbose mode.

sudo killall -v <process_name>

Running killall -v firefox will terminate all instances of "firefox" and display detailed information about each terminated process. This can be useful for troubleshooting and ensuring the correct processes are being targeted.

killall Command in Linux5

Interactively Confirming Each Kill

If you want to interactively ask for confirmation before killing each process, use the -i option.

sudo killall -i <process_name>

Running killall -i firefox will prompt you to confirm the termination of each process named "firefox". This is useful when you want to ensure that you are not terminating any critical processes by mistake.

killall Command in Linux6

Conclusion

The killall command is a versatile and powerful tool for managing processes on a Linux system. By allowing users to target processes by name and providing a wide array of options, it simplifies process management, especially when dealing with multiple instances. Understanding its syntax, options, and practical applications empowers users to maintain better control over their system's processes.

Whether you need to terminate, reload, or send specific signals to processes, mastering the killall command is an essential skill. Remember to use signals judiciously and ensure that you are targeting the correct processes to avoid unintended disruptions.

Advertisements