码迷,mamicode.com
首页 > 系统相关 > 详细

linux nohup

时间:2016-07-07 22:42:04      阅读:369      评论:0      收藏:0      [点我收藏+]

标签:linux nohup

If standard output is a terminal, append output to ‘nohup.out‘

If standard error is a terminal, redirect it to standard output.  To save output to FILE, use ‘nohup COMMAND > FILE‘.


nohup: ignoring input and appending output to `nohup.out‘




nohup sh test.sh &


会将脚本中的输出(标准输出和错误输出)都append到本路径下的nohup.out文件中


如果使用nohup命令提交作业,那么在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中,除非另外指定了输出文件:


nohup command > myout.file 2>&1 &


应用: 

1 我不需要将脚本中的错误输出写到nohup文件中

nohup sh test.sh 2>/dev/null &


2 我需要将脚本中的输出输出到一个文件中而不是nohup.out中




疑问如果我退出了终端,我在ps -ef |grep "test.sh"的时候,并不会显示是重定向到哪个文件,这个时候如何找出呢?


方法

第一步:

ps -ef |grep "test.sh"   找出这个进程的pid


[root@master scripts]# ps -ef |grep "test.sh"

root      2700     1  0 20:38 ?        00:00:00 sh test.sh


第二步: 利用lsof列出这个进程所占用的文件

lsof -p 2700




注意: nohup python test.py & 可能tail -f nohup.out 得到的结果不是你想要得,这个就要理解python中的(print 函数 sys.stdout.write() sys.stdout.flush()) 得深入理解一下了。有个缓冲的概念。



本文出自 “崔德华运维打工从业路” 博客,请务必保留此出处http://cuidehua.blog.51cto.com/5449828/1812430

linux nohup

标签:linux nohup

原文地址:http://cuidehua.blog.51cto.com/5449828/1812430

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!