Linux Shell check process PID

Source: Internet
Author: User

#
# Check the PID of such program
#
Checkpid (){
If [-z "'ps X | grep $1 | grep-V grep | grep-V $0 | awk '{print $1}'' "]; then
Echo "the $1 program cant run well ."
Fi
}

 

 

 

Simple Description:

PS reportProgramStatus.

Ps x shows all programs, not distinguished by terminals.

$1 is the first parameter of the function, for example, checkpid test. $1 = test, $0 = checkpid test.

Grep searches for matching strings in the file.

Ps x | grep $1 shows the program status that contains the keyword '$1.

Ps x | grep $1 | grep-V grep | grep-V $0 remove the influence of its own command

Awk '{print $1}' extracts and format data packets from the display of Command Execution

For example:

Ps x | grep test | grep-V grep | grep-V "checkpid test"

After execution, it is displayed:

12040 pts/1 ss Test

So,

Ps x | grep test | grep-V grep | grep-V "checkpid test" | awk '{print $1 }'

Shown:

12040

That is, the PID of the process.

Related Article

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.