pkill Command: Terminate Linux Processes

The pkill command in Linux is used to terminate processes based on their process name or other properties. Its purpose is to search for and end running processes based on process name or other matching criteria.

The syntax of the pkill command is as follows:

pkill [options] pattern

In this case, the pattern is the pattern of the process name or other attributes that need to be matched, and it can be a regular expression. Options can be used to specify the way processes are searched for and terminated.

The pkill command scans all the processes currently running on the system and matches them with the given pattern. Once a matching process is found, it immediately terminates them.

Here are some commonly used options for the pkill command:

  1. –uid: Terminate process based on user ID.
  2. -n, –newest: terminate the most recently created process.
  3. –older: terminate the earliest created process.
  4. -f, –full: Match the entire command line and not just the process name.

Here are a few examples:

# 终止名为 "firefox" 的所有进程
pkill firefox

# 终止以 "chrome" 开头的进程
pkill chrome*

# 终止由用户ID 1000 创建的所有进程
pkill -u 1000

# 终止最新创建的进程
pkill -n

# 终止最早创建的进程
pkill -o

It is important to note that the pkill command will immediately terminate matching processes, so caution should be exercised when using it to ensure important processes are not accidentally terminated.

bannerAds