Pkill and Pgrep commands in Linux

Source: Internet
Author: User
Tags session id pkill

Pkill and Pgrep commands in Linux

Name

Pgrep, pkill– find or signal to process through name and other attributes.

Grammar

pgrep [-FLVX] [-n |-O] [-D delim] [-P ppidlist] [-G pgrplist] [-S sidlist] [-u euidlist] [-u uidlist] [-G gidlist] [-j PR Ojidlist] [-t termlist] [-t taskidlist] [-C ctidlist] [-Z zoneidlist] [pattern]

Pkill [-signal] [-FVX] [-n |-o] [-P ppidlist] [-G pgrplist] [-S sidlist] [-u euidlist] [-u uidlist] [-G gidlist] [-j proj Idlist] [-t termlist] [-t taskidlist] [-C ctidlist] [-Z zoneidlist] [pattern]

Description

The PGREP program checks the active process in the system, reporting the process properties that match the ID of the process that specified the condition on the command line. Each process ID is represented by a decimal number, separated by a split string and the next ID, and the default split string is a new line. For each property option, a user can specify a collection of possible values separated by commas on the command line. For example

Pgrep-g Other,daemon

Matching the real group ID is the process of other or daemon. If more than one condition is assigned, these match conditions are calculated as logical and "and" rules. For example

Pgrep-g other,daemon-u Root,daemon

The properties of the matching process are:

(The real group ID is other or daemon) with (the real user ID is root or daemon)

The Pkill function is the same as pgrep, except that the matching process is signaled as if it were replaced with the output of the PGREP process ID with Kill (1). A signal name or number can be used as the first command-line option for Pkill.

Options

The following options are supported: The following options are supported:

-C Ctidlist only the processes that match the IDs listed in the list.

-D delim Specifies a split string between each matching process ID. If no-d option is specified, the default is the new line character. The-d option is only valid in the Pgrep command.

The-f Regular expression pattern matches the full process parameter string (obtained from the Pr_psargs field of the/proc/nnnnn/psinfo file). Without the-f option, the expression matches only the execution file name (obtained from the/proc/nnnnn/psinfo file Pr_fname field).

-G pgrplist only matches process group ID in the given list of processes. If group 0 is included in the list, this is interpreted as the group ID of the pgrep or pkill process.

-G gidlist only matches the real group ID in the given list of processes. Each group ID can be specified using a group name or a group ID of a number.

-j Projidlist matches the project ID in the given list of processes. Each project ID can be specified using the project's name or a numeric item ID.

-l long format output. Outputs the name of each matching process along with the process ID. The process name is obtained from the Pr_psargs or Pr_fname field, depending on whether the-F option is specified. The-l option is only valid in the Pgrep command.

-N matches the latest (recently generated) process that meets all other matching criteria. cannot be used with the-o option.

-O matches the oldest (first generated) process that meets all other matching criteria. cannot be used with the-n option.

-P ppidlist Only the process that matches the ID of the parent process in the given list.

-S sidlist only the process that matches the process session ID in the given list. If ID 0 is in the list, this is interpreted as the session ID of the PGREP or Pikill process.

-T termlist only matches the process associated with the terminal in the given list. Each terminal is specified as the suffix of the terminal device path name in/dev. such as term/a or pts/0.

-T Taskidlist matches only the process of the task ID in the given list. If ID 0 is included in the list, this is interpreted as the session ID of the PGREP or Pikill process.

-U euidlist only matches the process of a valid user ID in the given list. Each user ID can be specified by a login name or a user ID of a number.

-U uidlist only matches the real user ID of the process in the given list. Each user ID can be specified by a login name or a user ID of a number.

-V Reverse match. Matches all processes except those that match the matching criteria.

-X only considers that the process whose argument string or execution file name correctly matches the specified pattern is a matching process. The pattern is considered accurate when all characters in the process parameter string or executable file name match the pattern.

-Z zoneidlist matches only the process of the zone ID in the given list. Each zone ID can be specified with a range name or a number's area ID. This option is only valid in the global zone. If the Pkill program signals the process to and from other regions, the city must declare the {Priv_proc_zone} privilege.

The-signal specifies the signal destined for each matching process. If not specified, SIGTERM is the default signal. -signal is only valid as the first option in the Pkill command. The signal can be a symbolic name defined in signal.h without the sig prefix, but also a corresponding signal value.

Operation

The following actions are supported:

Pattern

Specify an extended regular expression (Extended Regular expression (ERE)) pattern to match the executable file name or the full process parameter string. The full description of the ERE syntax is referred to as Regex (5).

Example

Example 1 get a process ID

Get the process ID for SendMail:

Example% pgrep-x-U root sendmail

283

Example 2 terminating a process

To terminate the most recently generated xterm:

Example% Pkill-n xterm

Exit Status

The following exit values are returned:

01 or more processes are matched.

1 no processes are matched.

2 An invalid command-line argument was specified.

3 A fatal error has occurred.

    • This article is from: Linux Learning Tutorial Network

Pkill and Pgrep commands in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.