有时候查看进程,需要根据进程名得到进程号。
PROCESS_NAME=gh_main
text=`ps -A | grep $PROCESS_NAME`
# 去掉开头的空格
text=`echo $text | sed -e 's/^[ \t]*//g'`
# 得到进程号之后的空格
pos=`expr index "$text" " "`
pos=`expr $pos - 1`
#截取进程号
pid=`echo $text | cut -c 1-$pos`
echo pid=---$pid+++