错误:在bash中找不到ps命令

时间:2013-10-25 17:00:02

标签: bash shell

我在执行这个打印'hello'的bash脚本时遇到错误,直到后台进程继续执行。

ps command not found 

我之前已经做了几次,但不确定为什么我这次会收到错误。

./a.sh &
while ps -p $! > /dev/null; do
       echo hello
done

2 个答案:

答案 0 :(得分:1)

这并不能解决您明显的PATH问题,但除了重复调用ps之外,还有一种更简单的方法可以解决问题。

# Start your script in the background, remembering its process ID
./a.sh & A_PID=$!

# Start another background job that echos hello (once per second, to
# avoid a flood of hellos). Remember its process ID as well
( while : ; do echo hello; sleep 1 done ) & LOOP_PID=$!

# Now wait for a.sh to finish...
wait $A_PID

# ... and kill the hello job
kill $LOOP_PID

答案 1 :(得分:0)

调试此问题我建议以下

 nohup ./a.sh &
 p1=$!

 while ps -p $p1 
 do
    echo hello
    sleep 1
 done