Linuxshell checks the process PID-general Linux technology-Linux programming and kernel information. The following is a detailed description. #
# 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 reports program status.
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 }'
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