为了停止我的嵌入式 Linux 系统中的事件,我有以下 shell 脚本(由 busybox 解释):
#!/bin/sh
pkill usefulp_program
swapoff /home/.swapfile
umount -l /home
sleep 3 # While I can't find a way to sync, sleep
如果我取消 sleep
行,脚本会立即返回,甚至不等待 umount
(这是懒惰的,因为出于某种原因它拒绝卸载,否则).你知道我怎样才能等到三个操作都完成才能完成脚本吗?诉诸任意 sleep
看起来不是一个好的解决方案。
此外,关于为什么没有 -l
我不能 umount
的任何提示?
最佳答案
您需要等待被杀死的进程终止。根据您的评论...
wait <pid>
...行不通!所以,可以循环 ala:
while ps -p <pid> > /dev/null; do sleep 1; done
在执行 swapoff 和 umount 之前等待被杀死的进程终止。
关于linux - 将 shell 脚本与内核操作同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5574332/