我使用的主板没有ps
安装完整的命令。我需要的是ps -p
等效的(设置$?
是否找到特定 PID 的东西)。
有没有办法用另一个命令(如 top)来完成此任务?
## wannabe_watchdog.sh
MY_EXE="$1"
_pid=-1
while test 1 -eq 1
do
## this ps -p isn't available on the busybox
ps -p ${_pid}
if test $? -eq 0
then
echo "executing"
sleep 10
else
echo "not executing"
./${MY_EXE} &
sleep 1
agent_pid=$(cat /var/run/my_pidfile.pid)
echo "waiting for ${_pid}"
#wait function sometimes isn't blocking (and I never figured out exactly when)
wait ${_pid}
echo "${_pid} is dead - restarting"
fi
done