shell脚本获取进程pid
# shell 脚本获取进程 pid
#!/bin/bash
# 进程名
process="/sbin/init"
# 获取进程ID
PID=$(ps -ef | grep $process | grep -v grep | awk '{print $2}')
if [ -n "$PID" ]; then
echo "$process is exist"
if ps -p $PID >/dev/null; then
echo "$process is runnig"
else
echo " $ process is not running"
fi
else
echo "$process is not exist"
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
上次更新: 2022/06/17, 07:22:19