当前位置:   article > 正文

设置python程序自启动shell脚本_python 启动run.sh

python 启动run.sh

最近在rk3399pro开发板上编写python程序(opencv获取rtsp流–vpu硬件解码—多进程读取/处理),但是由于远程网络摄像头rtsp流会发生丢包、网络卡顿的现象,导致程序意外退出,现通过设置shell脚本自动启动意外中断的程序。
1、编写/运行shell脚本

vim run.sh  #建一个run.sh脚本,写入下面内容
"""
#!/bin/bash
while [ 1 ];do
    python test.py
done
"""
chmod +x ./run.sh  #设置权限
./run.sh    #运行脚本
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2、shell脚本退出

#查看进程号(run.sh为shell脚本名)
root@root:~# ps -ef | grep run.sh   
root      5783  1397  0 11:04 pts/0    00:00:00 /bin/bash ./run.sh
root      5966  5953  0 11:08 pts/2    00:00:00 grep run.sh
#终止进程
root@root:~# kill -9 5783
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

一般的shell脚本到这一步就可以退出了,但由于我是多进程,所以还需要把进程再kill一遍。

root@root:~# top #查看进程号
PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                    
5797 root      20   0  789124  73788  44760 S  35.1   1.9   2:58.34 python                     
5798 root      20   0  909916  67728  42960 R  25.6   1.7   2:05.47 python 
root@root:~# kill -9 5797 5798  #批量kill 进程
  • 1
  • 2
  • 3
  • 4
  • 5

这样退出shell脚本了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/article/detail/51333
推荐阅读
相关标签
  

闽ICP备14008679号