ps -ef
我遇到一个涉及AIX 7.1 上命令输出的不寻常问题。
shell 脚本通过解析此输出来监视进程。我注意到有两次这个列表中省略了一个进程(一个 Perl 程序)。我读到的有关该主题的所有内容都表明这是不可能的。该程序在早上 6 点通过 crontab 启动,一直运行到晚上 11 点,然后自行终止。我ps -ef
在监视器脚本省略后立即检查了输出,它显示:
user 1249864 9569338 0 06:00:00 - 0:19 /usr/bin/perl -w /path/to/omittedProgram.pl
...这意味着它与早上 6 点开始的过程相同。程序没有终止,然后重新启动。
是什么导致它从输出中被省略ps -ef
?
该程序检查 的输出ps -ef
,已成功运行了大约五年。我只注意到这个问题两次,但都是在过去两个月内出现的:
# set global variables
PROCESS_FILE=/tmp/processList.txt
TEMP_FILE=/tmp/greppedProcesses.tmp
BOX=`uname -n`
DATE=`date`
EMAIL_LIST="[email protected]"
# Get list of running processes
ps -ef > $PROCESS_FILE
checkProcess() {
PROCESS_NAME=$1
PROCESS_ABBREVIATION=$2
PROCESS_COUNT=$3
UNIQUE_PROCESS_IDENTIFIER=$4
GREPPED_LINES=$TEMP_FILE-$PROCESS_ABBREVIATION
grep $UNIQUE_PROCESS_IDENTIFIER $PROCESS_FILE | grep -v grep > $GREPPED_LINES
NUM=`cat $GREPPED_LINES | wc -l`
if [[ $NUM -ne $PROCESS_COUNT ]]
# Incorrect number of processes running!
then MESSAGE=`printf "The \"$PROCESS_NAME\" process count is %1d, but it should be $PROCESS_COUNT!!!" $NUM`
echo "Monitor - starting on $DATE\n\n$MESSAGE\n\n`cat $GREPPED_LINES`" | mail -s "Problem with $PROCESS_NAME on $BOX" $EMAIL_LIST
fi
# Delete the temp file
rm $GREPPED_LINES
}
checkProcess "Full Name of Program" "Program Abbreviation" <expected number of processes running> "Unique string to identify program in ps output"
checkProcess ... (for other processes) ...
exit 0
另外,我们安装的 AIX 没有pgrep
.