linux - 将 shell 脚本与内核操作同步

标签 linux shell embedded busybox

为了停止我的嵌入式 Linux 系统中的事件,我有以下 shell 脚本(由 bu​​sybox 解释):

#!/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/

相关文章:

c - 当 PIC32 上使能中断时,不等于运算符不工作

c - fseek 在 Linux 中不起作用

android - 在 PXA270 设备上移植 Android 操作系统

linux - 添加 ||正则表达式到 bash `` ed perl 脚本中的一行

linux - 将我的 echo 输出重定向到一个文件

c - 在嵌入式寄存器结构中用位移位替换位域

architecture - 用于培训嵌入式开发的 x86 模拟器

c++ - 链接到我的主目录中的共享对象文件

Bash 脚本 - 在一个存档中压缩多个目录

ruby-on-rails - 混合使用 Ruby 和 bash 命令——mv 返回 "x and y are the same file"