账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    OpenWrt(嵌入式Linux系统)创建一个shell自启动脚本,运行 ser2net 模块,导致的重复启动5次的问题
    18
    0
    版本:Linux version 3.18.29 OpenWrt/Linaro GCC 4.8-2014.04 unknown问题:自启动服务文件启动后,会自启动5次 ser2net 服务。shell代码:#!/bin/shprocess_pid=`ps -w | grep -w "ser2net" | grep -v grep| awk '{print $1}'`id=${#process_pid} if [ $id -gt 4 ]then /etc/init.d/ser2netservice stop &ser2net &echo "yes"elseecho "Start"ser2net &fi具体实操测试流程:root@Hiwooya:~# /etc/init.d/ser2netservice startroot@Hiwooya:~# ps -w|grep ser2net 1819 root 856 S ser2net 1828 root 852 S ser2net 1830 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1819 root 856 S ser2net 1828 root 852 S ser2net 1832 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1819 root 856 S ser2net 1828 root 852 S ser2net 1834 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1819 root 856 S ser2net 1828 root 852 S ser2net 1843 root 852 S ser2net 1845 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1819 root 856 S ser2net 1828 root 852 S ser2net 1843 root 852 S ser2net 1854 root 852 S ser2net 1856 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1819 root 856 S ser2net 1828 root 852 S ser2net 1843 root 852 S ser2net 1854 root 852 S ser2net 1865 root 852 S ser2net 1867 root 1484 S grep ser2netroot@Hiwooya:~# /etc/init.d/ser2netservice stopKilling the process_pid [ 1819 ]killed pid 1819 successKilling the process_pid [ 1828 ]killed pid 1828 successKilling the process_pid [ 1843 ]killed pid 1843 successKilling the process_pid [ 1854 ]killed pid 1854 successKilling the process_pid [ 1865 ]killed pid 1865 successKilling the process_pid [ 1876 ]killed pid 1876 success我这里使用 ser2net 模块(ser2net这里是有环境变量的)直接运行,它就不会自己启动5次,看来不是 ser2net 模块问题,这里就有些不懂是哪里出问题了,看来 Linux 这条路还是有很长的路要走,在这里想求教下,具体是 Linux 内部的机制问题,还是其他的问题。root@Hiwooya:~# ser2netroot@Hiwooya:~# ps -w|grep ser2net 1890 root 856 S ser2net 1892 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1890 root 856 S ser2net 1894 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1890 root 856 S ser2net 1896 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1890 root 856 S ser2net 1898 root 1484 S grep ser2netroot@Hiwooya:~# /usr/sbin/ser2netroot@Hiwooya:~# ps -w|grep ser2net 1890 root 856 S ser2net 1901 root 852 S /usr/sbin/ser2net 1903 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1890 root 856 S ser2net 1901 root 852 S /usr/sbin/ser2net 1905 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1890 root 856 S ser2net 1901 root 852 S /usr/sbin/ser2net 1907 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1890 root 856 S ser2net 1901 root 852 S /usr/sbin/ser2net 1909 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1890 root 856 S ser2net 1901 root 852 S /usr/sbin/ser2net 1911 root 1484 S grep ser2netroot@Hiwooya:~#此外,这里有点奇特的地方,应该在于如果我直接在终端运行我的shell代码,就不会出现这样的问题 —— 骚操作。如下所示:root@Hiwooya:~#root@Hiwooya:~# process_pid=`ps -w | grep -w "ser2net" | grep -v grep| awk '{print $1}'`root@Hiwooya:~# id=${#process_pid}root@Hiwooya:~# if [ $id -gt 4]> then> /etc/init.d/ser2netservice stop &> ser2net &> echo "yes"> else> echo "Start"> ser2net &> fiash: missing ]Startroot@Hiwooya:~# ps -w|grep ser2net 1971 root 856 S ser2net 1973 root 1484 S grep ser2net[1]+ Done ser2netroot@Hiwooya:~# ps -w|grep ser2net 1971 root 856 S ser2net 1975 root 1484 S grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1971 root 856 S ser2net 1977 root 1480 R grep ser2netroot@Hiwooya:~# ps -w|grep ser2net 1971 root 856 S ser2net 1979 root 1484 S grep ser2netroot@Hiwooya:~#虽然,我已经找到替代 ser2net 模块自启动服务的方法了,但仍旧希望可以解开这个困惑,所以,这里就看大佬会不会被我的问题炸出来,看我运气了,当然最好是我能在自己平时学习时,自己解开困惑,那就更好了。 END
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版

    回答动态

    师傅被妖怪抓走了:发布了悬赏问题火爆全网的“元宇宙”到底是什么?预计能赚取 1积分收益
    酒后略带风情:发布了悬赏问题Android内存中Graphics与Code占用过高预计能赚取 10积分收益
    扛起拖把扫天下:发布了悬赏问题typescript如何导出接口配置?求解,谢谢!预计能赚取 10积分收益
    发布了悬赏问题Vue 如何改变返回页面的路径?如让B页面只能返回到A页面.预计能赚取 11积分收益
    发布了悬赏问题vue H5移动端;底部bottom固定定位,安卓弹起键盘导致页面变形如何解决?预计能赚取 10积分收益
    发布了悬赏问题请问为什么tomcat8.5 GET请求中文正常,POST请求还需要设置UTF-8.预计能赚取 10积分收益
    发布了悬赏问题vue2.5+ts创建以及引入jq的方法预计能赚取 11积分收益
    情场浪女:发布了悬赏问题import ggplot时报错module 'pandas' has no attribute 'tslib'预计能赚取 10积分收益
    见心书画许老师18753375161:发布了悬赏问题echarts3 legend禁止点击事件,允许悬浮事件预计能赚取 11积分收益
    aa_92cb0bd09f:发布了悬赏问题codewar上的一个问题预计能赚取 11积分收益