Copied to clipboard

pkill

The pkill command is used to terminate processes based on process name or other attributes.

The pkill and kill commands are both tools used to terminate processes, but they differ in the following ways:

  • The kill command requires you to manually specify the PID of the process to be terminated, while the pkill command can terminate a process based on its name or other attributes.
  • The kill command can only terminate a process, while the pkill command can also display process information and list process IDs.

Therefore, if you know the PID of the process, you can use the kill command to terminate it. If you only know the name or other attributes of the process, then using the pkill command may be more convenient.

Examples

  • Kill a process based on its name:

    pkill nginx
    
  • Kill a process based on its name for a specific user:

    pkill -u user nginx
    
  • Kill a process based on its name for a specific process group ID:

    pkill -g 123 nginx
    
  • Kill a process based on its name for a specific session ID:

    pkill -s 1234 nginx
    
  • Kill a process based on its name for a specific terminal:

    pkill -t pts/0 nginx
    
  • Kill a process based on its name for a specific process ID:

    pkill -P 12345 nginx
    
  • Kill all processes:

    pkill -9 -e -f .