常见的进程查询有如下命令。
yitong04@yitong04-YangTianT4900c-00:~$ ps -ef | grep java
yitong04 4068 1 0 3月11 ? 00:04:00 java -Dloader.path=/appdata/lib/um -Djava.security.egd=file:/dev/./urandom -Djava.ext.dirs=/usr/lib/java/jdk1.8.0_172/jre/lib/ext -XX:ParallelGCThreads=2 -Xms256M -jar /appdata/packages/ms-business-um/target/ms-business-um-0.0.1-PHSP-SNAPSHOT.jar --spring.profiles.active=dev
yitong04 4222 1 1 3月11 ? 00:11:53 java -Dloader.path=/appdata/lib/wre -Djava.security.egd=file:/dev/./urandom -Djava.ext.dirs=/usr/lib/java/jdk1.8.0_172/jre/lib/ext -XX:ParallelGCThreads=2 -Xms256M -jar /appdata/packages/ms-business-wre/target/ms-business-wre-0.0.1-PHSP-SNAPSHOT.jar --spring.profiles.active=dev
yitong04@yitong04-YangTianT4900c-00:~$ pgrep -f ms-business-um
4068
- ps -ef | grep “name” | grep -v grep | awk '{print $2}'
该写法要注意避免匹配到自己
yitong04@yitong04-YangTianT4900c-00:~$ ps -ef |grep "ms-business-um"| grep -v grep|awk '{print $2}'
4068
编写停止进程的脚本
#!\bin\bash
pid=${pgrep -f ms-business-um}
echo $pid
if [ ! $pid ]; then
echo "pid null"
else
kill -9 $pid
fi
exit 0