Dash Wiki
Posts (Latest 10 updated) :
Read all
Contents:
  1. [English] Debian Almquist Shell (dash) pkill Usage: Terminate processes by name
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
    5. Tips

[English] Debian Almquist Shell (dash) pkill Usage: Terminate processes by name

Overview

The pkill command in the Debian Almquist Shell (dash) is used to terminate processes based on their names or other attributes. It allows users to kill processes without needing to look up their process IDs (PIDs), making it a convenient tool for managing running applications.

Usage

The basic syntax of the pkill command is as follows:

pkill [options] [arguments]

Common Options

  • -f: Match against the full command line instead of just the process name.
  • -n: Kill the newest process matching the criteria.
  • -o: Kill the oldest process matching the criteria.
  • -signal: Specify a signal to send to the process (e.g., -9 for SIGKILL).
  • -u: Specify the user whose processes to kill.

Common Examples

Here are several practical examples of using pkill:

  1. Terminate a process by name:
    pkill firefox
    

    This command will terminate all instances of the Firefox browser.

  2. Kill processes matching a pattern:
    pkill -f "python script.py"
    

    This command will kill all processes that have “python script.py” in their command line.

  3. Send a specific signal to a process:
    pkill -9 apache2
    

    This command forcefully kills all instances of the Apache web server by sending the SIGKILL signal.

  4. Kill the newest instance of a process:
    pkill -n ssh
    

    This command will terminate the most recently started SSH session.

  5. Kill processes by user:
    pkill -u username
    

    This command will terminate all processes owned by the specified user.

Tips

  • Always be cautious when using pkill, as it can terminate multiple processes at once.
  • Use the -n or -o options if you only want to kill the most recent or oldest instance of a process.
  • Consider using pgrep first to preview which processes will be affected before executing pkill.