killall - Linux


Overview

The killall command in Linux is used to terminate running processes based on their name. Unlike kill, which requires a specific process ID, killall matches processes by name and can affect multiple processes at once. This tool is particularly useful in scripts and system administration for managing groups of processes and can be utilized effectively in environments where processes need to be frequently restarted or stopped.

Syntax

The basic syntax of the killall command is as follows:

killall [options] name...
  • name specifies the process name(s) to target. This is a required argument and can include wildcards.

Options/Flags

killall provides various options to alter its default behavior:

  • -e, --exact: Require an exact match for very long names.
  • -I, --ignore-case: Do not consider case when matching process names.
  • -g, --process-group: Kill all processes in the current process group.
  • -i, --interactive: Ask for confirmation before killing each process.
  • -l, --list: List all known signal names.
  • -q, --quiet: Do not print any error messages about processes not found.
  • -v, --verbose: Report if the signal was successfully sent.
  • -w, --wait: Wait for all killed processes to die. killall checks once per second if any of the killed processes still exist and only returns if none are left.
  • -s signal, --signal signal: Send a specific signal instead of the default SIGTERM.

Examples

  1. Terminate all instances of a process named MyApp:
    killall MyApp
    
  2. Terminate all processes ignoring case:
    killall -I myapp
    
  3. Ask for confirmation before killing each matching process:
    killall -i MyApp
    
  4. Send a SIGKILL signal instead of the default SIGTERM:
    killall -s SIGKILL MyApp
    
  5. Wait for the process to exit after sending termination signal:
    killall -w MyApp
    

Common Issues

  • Process not found: If killall does not find any running process by the given name, it reports an error. Using the -q option suppresses these messages.
  • Permission errors: Running killall against processes owned by other users including system services may require elevated privileges. Ensure you run it with sudo if necessary.

Integration

killall can be integrated with shell scripts or used in combination with other commands. For example, to restart a service process, you might use:

killall -w myservice && myservice &

This command ensures myservice is stopped before attempting to restart it.

  • kill: Send signals to processes given specific PIDs.
  • pkill: Kill processes based on a variety of attributes like name, user, and more.

For further reading or more detailed information, refer to the man pages (man killall).

These tools collectively help manage processes effectively in Unix-like systems and each offers unique features that can be better suited depending on the scenario.