killall - macOS


Overview

The killall command in macOS is used to terminate all processes that match the name specified. It sends a signal to processes with identifiers derived from their names, making it particularly useful for stopping multiple instances of the same program. This command is most effective in scenarios where you need to quickly stop all processes related to a specific application or service, especially during system troubleshooting or maintenance.

Syntax

The basic syntax of the killall command is as follows:

killall [options] program_name

Options include:

  • -s: Display the kill command that corresponds to what is being done for each process.
  • -q: Do not print error messages about processes that are not found.
  • -r: Interpret the process name as a regular expression.
  • -u USERNAME: Only match processes that the given user owns.
  • -SIGNAL: Specify the signal to send to the process, such as SIGTERM, SIGHUP, etc.

Options/Flags

  • -HUP, -1: This sends the SIGHUP signal, commonly used to cause programs to restart.
  • -INT, -2: Sends the SIGINT signal, used to interrupt programs.
  • -QUIT, -3: Sends the SIGQUIT signal, which quits the program and often creates a core dump.
  • -KILL, -9: Forcibly halts the process immediately. This signal cannot be ignored.
  • -TERM, -15: Sends the SIGTERM signal which is the default. This tells programs to terminate gracefully, allowing for cleanup operations.
  • -u: Targets only processes owned by a specific user.
  • -t TTY: Kills all processes associated with a specific terminal.

Examples

  • To terminate all instances of Google Chrome:
    killall "Google Chrome"
    
  • To stop all processes owned by user ‘john’:
    killall -u john
    
  • To send a SIGHUP signal to all Python processes:
    killall -HUP python
    
  • To use a regex pattern to kill processes:
    killall -r '^php'
    

Common Issues

  • Process Not Found: If the specified process does not exist, killall will return an error. Using the -q option allows you to suppress this error.
  • Permissions: Attempting to kill a process owned by another user or a system process without sufficient privileges results in a denial. Running killall with sudo may be necessary.
  • Incorrect Signal Spec: Providing an incorrect signal either leads to undefined behavior or no action. Ensure you’re familiar with UNIX signals when using signal options.

Integration

killall can be integrated with other shell commands for process management. For example, combining it with grep to selectively kill processes:

ps aux | grep my_process | awk '{print $2}' | xargs killall
  • kill: Terminate processes by process ID.
  • pkill: Kill processes based on a pattern.
  • top: Task manager for Unix systems, useful for monitoring processes.

For more information and options, you can access the manual page on macOS by executing man killall in the terminal. This provides an exhaustive list of flags and detailed usage scenarios.