SHELL下获得指定进程的进程号,并截取为整数

有时候查看进程,需要根据进程名得到进程号。

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+++

猜你喜欢

转载自blog.csdn.net/quantum7/article/details/82984388
今日推荐