-1
我在執行此打印'hello'的bash腳本時出錯,直到後臺進程繼續執行。錯誤:在命令中找不到ps命令
ps command not found
我已經做了幾次之前,但不知道爲什麼我這次得到錯誤。
./a.sh &
while ps -p $! > /dev/null; do
echo hello
done
我在執行此打印'hello'的bash腳本時出錯,直到後臺進程繼續執行。錯誤:在命令中找不到ps命令
ps command not found
我已經做了幾次之前,但不知道爲什麼我這次得到錯誤。
./a.sh &
while ps -p $! > /dev/null; do
echo hello
done
調試這個問題,我建議如下
nohup ./a.sh &
p1=$!
while ps -p $p1
do
echo hello
sleep 1
done
這並不解決您的明顯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
您是否惹了PATH?你還有/ bin/ps嗎? – geoffspear
我已經驗證了這一點,PATH有這個位置ps – marc
什麼是完整的輸出,它運行一次,然後停止?或者它立即拋出命令未找到錯誤? – Farlan