写一个脚本,完成如下功能:
(1)显示当前系统上每一个进程及其进程号,而后提示用户输入一个进程号,如果用户输入的进程号错误,而说明其错误,并提醒用户重新输入;
(1)显示当前系统上每一个进程及其进程号,而后提示用户输入一个进程号,如果用户输入的进程号错误,而说明其错误,并提醒用户重新输入;
(2)显示用户所选进程的state, PPID和RSS及期对应的值;
#!/bin/bash
exec 2>>/dev/null
#Phase.1 show all process,and get the PID from user
ps -ef
i=0
echo please enter the PID you want to query
while [ "$i" -ne 1 ];
do
read pid
ps -ef | awk '{print $2}' | grep -w $pid >/dev/null
if [ $? -eq 0 ];then
#echo $pid
let i=$i+1
else
echo the PID you input does not exist,please input the PID again
fi
done
#echo $i
#Phase.2 ouput the PID PPID RSS of the process which the PID that user input
STAT=` ps aux |grep -w $pid | grep -v grep | awk '{print $8}'`
PPID=` ps -ef |grep -w $pid | grep -v grep | awk '{print $3}'`
RSS=` ps aux |grep -w $pid | grep -v grep | awk '{print $6}'`
echo the process ID is $pid:STAT=$STAT,PPID=$PPID,RSS=$RSS