#
# 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.