如果进程死掉了,有人能告诉我如何重新自动运行它吗?下面是我的代码,我已经累了,但它给了我一个错误:
编辑代码:

commandpid=`$busyboxValue pidof command`
echo ${commandpid} > /sdcard/CommandProcess.txt
if [ $commandpid -gt 0 ]
then
    echo -16 > /proc/$commandpid/oom_adj
    echo -1000 > /proc/$commandpid/oom_score_adj
fi

while [ true ]
do
    echo "PID $commandpid"
    if [ ps -p $commandpid > /dev/null ]
    then
        echo "[$(date)] :Process is already running with PID $commandpid"
    else
        echo "[$(date)] :Process is not running"
        /data/local/command 1200 &
        commandpid=`$busyboxValue pidof command`
        echo ${commandpid} > /sdcard/CommandProcess.txt
    fi
    sleep 10
done

我已经更新了代码,但仍然使用上面的代码多进程id。这是否意味着我的其他部分代码仍在执行?如果是,我需要做什么改变来阻止它?
有人能帮我吗?

最佳答案

重复运行命令,不管退出状态如何:

while :; do command; done

重复运行命令直到成功退出:
until command; do :; done

关于linux - 如果进程终止,如何重新运行-Linux,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26796427/

10-15 00:11