Linux 如何获取使用 nohup 运行的程序列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16809134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get a list of programs running with nohup
提问by Nils De Winter
I am accessing a server running CentOS (linux distribution) with an SSH connection. Since I can't always stay logged in, I use "nohup [command] &" to run my programs.
我正在通过 SSH 连接访问运行 CentOS(Linux 发行版)的服务器。由于我无法始终保持登录状态,因此我使用“nohup [command] &”来运行我的程序。
I couldn't find how to get a list of all the programs I started using nohup. "jobs" only works out before I log out. After that, if I log back again, the jobs command shows me nothing, but I can see in my log files that my programs are still running.
我找不到如何获取我开始使用 nohup 的所有程序的列表。“工作”仅在我注销之前有效。之后,如果我再次登录,jobs 命令不会显示任何内容,但我可以在我的日志文件中看到我的程序仍在运行。
Is there a way to get a list of all the programs that I started using "nohup" ?
有没有办法获得我开始使用“nohup”的所有程序的列表?
采纳答案by prayagupd
When I started with $ nohup storm dev-zookeper
,
当我开始时$ nohup storm dev-zookeper
,
METHOD1 :using jobs
,
方法1:使用jobs
,
prayagupd@prayagupd:/home/vmfest# jobs -l
[1]+ 11129 Running nohup ~/bin/storm/bin/storm dev-zookeeper &
METHOD2 :using ps
command.
方法2:使用ps
命令。
$ ps xw
PID TTY STAT TIME COMMAND
1031 tty1 Ss+ 0:00 /sbin/getty -8 38400 tty1
10582 ? S 0:01 [kworker/0:0]
10826 ? Sl 0:18 java -server -Dstorm.options= -Dstorm.home=/root/bin/storm -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dsto
10853 ? Ss 0:00 sshd: vmfest [priv]
TTY column with ?
=> nohup
running programs.
带有?
=>nohup
正在运行的程序的TTY 列。
Description
描述
- TTY column = the terminal associated with the process
- STAT column = state of a process
- S = interruptible sleep (waiting for an event to complete)
- l = is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
- TTY 列 = 与进程关联的终端
- STAT 列 = 进程的状态
- S = 可中断睡眠(等待事件完成)
- l = 是多线程的(使用 CLONE_THREAD,就像 NPTL pthreads 那样)
Reference
参考
$ man ps
# then search /PROCESS STATE CODES
$ man ps
# 然后搜索 /PROCESS STATE CODES
回答by mvp
Instead of nohup
, you should use screen
. It achieves the same result - your commands are running "detached". However, you can resume screen sessions and get back into their "hidden" terminal and see recent progress inside that terminal.
相反nohup
,您应该使用screen
. 它实现了相同的结果 - 您的命令正在“分离”运行。但是,您可以恢复屏幕会话并返回到他们的“隐藏”终端并查看该终端内的最新进展。
screen
has a lot of options. Most often I use these:
screen
有很多选择。我最常使用这些:
To start first screen session or to take over of most recent detached one:
开始第一个屏幕会话或接管最近分离的会话:
screen -Rd
To detach from current session: Ctrl+ACtrl+D
从当前会话分离: Ctrl+ACtrl+D
You can also start multiple screens - read the docs.
您还可以启动多个屏幕 - 阅读文档。
回答by Old Pro
You cannot exactly get a list of commands started with nohup
but you can see them along with your other processes by using the command ps x
. Commands started with nohup
will have a question mark in the TTY column.
您无法准确获取开始的命令列表,nohup
但您可以使用命令查看它们以及其他进程ps x
。以 开头的命令nohup
将在 TTY 列中有一个问号。
回答by Victor Melnikov
If you have standart output redirect to "nohup.out" just see who use this file
如果你有标准输出重定向到“nohup.out”,看看谁使用这个文件
lsof | grep nohup.out
回答by Jcrow06
You can also just use the top command and your user ID will indicate the jobs running and the their times.
您也可以只使用 top 命令,您的用户 ID 将指示正在运行的作业及其时间。
$ top
$ top
(this will show all running jobs)
(这将显示所有正在运行的作业)
$ top -U [user ID]
$ top -U [user ID]
(This will show jobs that are specific for the user ID)
(这将显示特定于用户 ID 的作业)