V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
xionghengheng
V2EX  ›  Python

一个关于守护进程执行 linux 命令的问题

  •  
  •   xionghengheng · 2015-06-08 10:51:32 +08:00 · 3082 次点击
    这是一个创建于 3238 天前的主题,其中的信息可能已经有所发展或是发生改变。
    使用了一个linux的nohup命令(该命令可以直接模拟守护进程)
    nohup python xx.py &
    问题是在该py文件执行了以下语句:
    os.system('php mailToEveryone.php')
    print 'mail success!!!!'

    结果却并没有执行,直接把那个忽略啦。。。。什么原因
    第 1 条附言  ·  2015-06-10 11:58:19 +08:00
    补充下,是在守护进程执行os.system()直接被忽略了,先在问题解决了,文件用绝对路径就好
    11 条回复    2015-06-10 11:49:43 +08:00
    lululau
        1
    lululau  
       2015-06-08 11:10:15 +08:00
    都说是守护进程了,还期望在控制终端上观察到输出吗,先了解下 daemon 的概念

    可以看看 ./nohup.out 文件里有没有你期望的输出
    fangjinmin
        2
    fangjinmin  
       2015-06-08 11:14:52 +08:00
    不是没有执行,是你没有把日志打印出来而己。

    nohup python xx.py >nohup.log 2>&1 &
    way2exluren
        3
    way2exluren  
       2015-06-08 11:19:41 +08:00
    那句os.system里的命令用绝对路径,不要用相对路径
    iyaozhen
        4
    iyaozhen  
       2015-06-08 11:22:19 +08:00 via Android
    nohup 命令直观感受是后台运行脚本,然后输出会写到当前目录的 nohup.out 文件中。


    然而并不能守护,挂了还是挂了。
    clino
        5
    clino  
       2015-06-08 11:23:15 +08:00 via Android
    用screen更好更清楚
    xionghengheng
        6
    xionghengheng  
    OP
       2015-06-08 12:49:48 +08:00
    @lululau 不好意思 没有描述清楚,我肯定知道标准输出,标准错误已经重定向到了nohup.out,我当然也查看了该文件。。。。压根就没有任何关于该命令是否执行或者错误的输出
    xionghengheng
        7
    xionghengheng  
    OP
       2015-06-08 12:51:02 +08:00
    @iyaozhen 当然可以守护,关闭bash客户端,照样运行,脚本并没有挂掉,而是直接跳过了那条命令
    xionghengheng
        8
    xionghengheng  
    OP
       2015-06-08 12:54:10 +08:00
    @lululau Stevens的unix高级环境第九章 以及看了很多次了。。。谢谢
    xionghengheng
        9
    xionghengheng  
    OP
       2015-06-08 12:57:22 +08:00
    @way2exluren 谢谢 我尝试下
    lilydjwg
        10
    lilydjwg  
       2015-06-08 13:45:19 +08:00
    @xionghengheng 的确没有描述清楚——你是怎么判断没有执行的?没有执行的「那条命令」是哪条?
    xionghengheng
        11
    xionghengheng  
    OP
       2015-06-10 11:49:43 +08:00
    @way2exluren 确实是这样的。。。用绝对路径就好
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1298 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:42 · PVG 01:42 · LAX 10:42 · JFK 13:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.