Linux获取进程的PID
程序员文章站
2024-01-21 21:14:16
...
常见的进程查询有如下命令。
- ps -ef | grep "name"
[email protected]:~$ 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
- pgrep -f "name"
[email protected]:~$ pgrep -f ms-business-um
4068
-
ps -ef | grep “name” | grep -v grep | awk '{print $2}'
该写法要注意避免匹配到自己
[email protected]:~$ 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
上一篇: java中的时间