VGA GPU passthrough qemu虚拟桌面pci穿透--Shell脚本检测与关机
转载注明:http://www.52php.cn/article/p-kotihzna-bpz.html 思路就是写一个循环检测的shell脚本,那么就直接代码了 #!/bin/bash
#调用qemu进程脚本,启动虚拟机,当前目录下,也可以家绝对路径
./qemu.sh
#打印出当前的qemu进程:grep qemu-system-x86_64查询该进程,grep -v "grep" 去掉grep进程
QemuThread=`ps -ef | grep qemu-system-x86_64 | grep -v "grep"`
echo $QemuThread
#查qemu-system-x86_64进程个数:wc -l 返回行数
count=`ps -ef | grep qemu-system-x86_64 | grep -v "grep" | wc -l`
echo $count
sec=2 #2秒检测一次
#开始一个循环,以判断进程是否关闭
for((var=0;var<1000;))
do
#每次都检测是否进程退出
count=`ps -ef | grep qemu-system-x86_64 | grep -v "grep" | wc -l`
if [ $count -gt 0 ]; then
#若进程还未关闭,则脚本sleep 2秒
echo sleep $sec second the $var time,the QEMU thread is still alive
sleep $sec
else
#若进程已经关闭,则跳出循环
echo "break 退出循环"
break
fi
done
#if [ $count -eq 0 ]; then
# echo "nohup startMethodServer.sh &"
# nohup startMethodServer.sh &
#else
# echo "It's better to check the thread!!!"
#fi
#调用关机脚本
#nohup startMethodServer.sh &
shutdown -h now
#ls
#reboot
真正在写脚本的时候可以把那些打印信息全部去掉 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |