简体   繁体   English

如何知道该进程是否设置为NOHUP?

[英]How to know if the process is set NOHUP?

Using jobs I know the process is running. 使用作业,我知道流程正在运行。

bash-4.2$ jobs
[1]+  Running                 test.sh &

I wanted it to be set NOHUP so that it won't be killed when I exit. 我希望将其设置为NOHUP,以使其在退出时不会被杀死。 I used 我用了

disown

and

bash-4.2$ jobs

shows nothing. 什么也没显示。 I'm not sure if the process is set NOHUP or not. 我不确定该进程是否设置为NOHUP。 I'm curious about this because after I read the manual it says 我对此感到很好奇,因为在阅读手册后会说

disown -h

should be used to set NOHUP. 应该用来设置NOHUP。

Edit 编辑

I don't think the link Find the Process run by nohup command helps. 我认为链接“ 找到由nohup运行的流程”命令没有帮助。 The question is different than that one. 问题不同于那个。

I'm gonna restate my problem. 我要重申我的问题。 I run a program without nohup, and later I wanted it to be set NOHUP so that it won't be killed when I exit the system. 我运行的程序没有nohup,后来我希望将其设置为NOHUP,这样在退出系统时不会被杀死。 So I used disown , but later I found the manual says I should have used disown -h to set NOHUP. 所以我使用了disown ,但是后来我发现手册说我应该使用disown -h来设置NOHUP。 I want to check if my process is set NOHUP or not successfully. 我想检查我的过程是否设置为NOHUP或未成功设置。 If not, what can I do to set it to be NOHUP? 如果没有,我该怎么做才能将其设置为NOHUP?

UPDATE UPDATE

I know two ways my be helpful: 我知道两种帮助方式:

1) Whenever a process is running over nohup It writes output on ~/nohup.out . 1)每当进程在nohup上运行时,它将输出写入〜/ nohup.out。 So you can check this file by running command find -cmin 2 . 因此,您可以通过运行命令find -cmin 2来检查此文件。 It shows you if nohup.out is changing each 2 seconds or not. 它显示nhup.out是否每2秒更改一次。 If it is changing you would understand that sth is running by nohup command, after that you can check it with lsof and continue your checking... 如果它正在更改,您将理解nohup命令正在运行sth,之后您可以使用lsof进行检查并继续进行检查...

2) If you logout from specific user andgo to tty then do ps aux | grep <user> 2)如果您从特定用户andgo注销到tty请执行ps aux | grep <user> ps aux | grep <user> or ps aux | grep ? ps aux | grep <user>ps aux | grep ? ps aux | grep ? then you can understand that is running with nohup command... because there is no pts then it shows you ? 那么您可以理解那是使用nohup命令运行的...因为没有pts,那么它告诉您 instead... 代替...

useful command: 有用的命令:

ps aux | grep <program> | awk -F" " '{print $7}'

Hope to be helpful 希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM