![](/img/trans.png)
[英]How to kill python script and its children if another instance of it is already running
[英]How to kill another script in bash if it's already running
我的 Raspberry Pi 上有一个硬件按钮。 如果我按下它,脚本handle.sh
被调用,它调用另一个名为do.sh
的脚本。 如果我第二次按下按钮,我想杀死do.sh
我的愿望是切换脚本。 首先按运行do.sh
,然后按退出此脚本。
我的想法是获取do.sh
的 PID。 如果已经有一个 do.sh 的实例, do.sh
应该do.sh
handle.sh
的进程。
我的伪代码:
句柄.sh
if do.sh not running {
run do.sh
} else if do.sh is running {
kill do.sh
// do more stuff
}
do.sh
echo date
arecord -D hw:3,0 -f cd -r 44100 test.wav
像这样:
if pgrep -f do.sh &>/dev/null; then
pkill -f do.sh
// do more stuff
else
./do.sh
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.