我有一个 init 脚本/etc/init.d/myservice
用于初始化这样的服务:
...
start() {
...
daemon /usr/sbin/myservice
...
}
stop() {
...
pgrep myservice
pidof myservice
ps -ef | grep myservice
...
}
Run Code Online (Sandbox Code Playgroud)
当我尝试停止服务时,这是输出:
10000 10001
10000
root 10000 1 0 09:52 ? 00:00:02 /usr/sbin/myservice
root 9791 9788 0 10:06 pts/1 00:00:00 /bin/sh /sbin/service myservice stop
root 10001 9791 1 10:06 pts/1 00:00:00 /bin/sh /etc/init.d/myservice stop
root 9805 9796 0 10:06 pts/1 00:00:00 grep myservice
Run Code Online (Sandbox Code Playgroud)
这是预期的吗?为什么pidof
只返回我想要停止的服务的正确 PID 并pgrep
返回服务 PID 和 init 脚本的 …