Linux 如何列出正在运行的屏幕会话?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/537942/
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 list running screen sessions?
提问by Wookai
I have a bunch of servers, on which I run experiments using screen
. The procedure is the following :
我有一堆服务器,我在这些服务器上使用screen
. 程序如下:
ssh
to server XXX- launch
screen
- start experiments in a few tabs
- detach
screen
- disconnect from the server
ssh
到服务器XXX- 发射
screen
- 在几个选项卡中开始实验
- 分离
screen
- 与服务器断开连接
While the experiments are running, I can easily find on which servers they are by ssh
ing to all servers and listing my running processes (using top
or ps
).
当实验运行时,我可以通过ssh
ing 到所有服务器并列出我正在运行的进程(使用top
或ps
)轻松找到它们在哪些服务器上。
However, once the experiments are finished, how could I find on which servers I have a screen session opened (so that I can have a look at the output, relaunch them, etc.) ?
但是,一旦实验完成,我如何才能找到在哪些服务器上打开了屏幕会话(以便我可以查看输出、重新启动它们等)?
PS: my experiments do print their output to files, too... but this is not the point of my question.
PS:我的实验也将它们的输出打印到文件中……但这不是我的问题的重点。
采纳答案by joshperry
To list all of the screen sessions for a user, run the following command as that user:
要列出用户的所有屏幕会话,请以该用户身份运行以下命令:
screen -ls
To see all screen sessions on a specific machine you can do:
要查看特定机器上的所有屏幕会话,您可以执行以下操作:
ls -laR /var/run/screen/
I get this on my machine:
我在我的机器上得到这个:
gentle ~ # ls -laR /var/run/screen/
/var/run/screen/:
total 1
drwxrwxr-x 4 root utmp 96 Mar 1 2005 .
drwxr-xr-x 10 root root 840 Feb 1 03:10 ..
drwx------ 2 josh users 88 Jan 13 11:33 S-josh
drwx------ 2 root root 48 Feb 11 10:50 S-root
/var/run/screen/S-josh:
total 0
drwx------ 2 josh users 88 Jan 13 11:33 .
drwxrwxr-x 4 root utmp 96 Mar 1 2005 ..
prwx------ 1 josh users 0 Feb 11 10:41 12931.pts-0.gentle
/var/run/screen/S-root:
total 0
drwx------ 2 root root 48 Feb 11 10:50 .
drwxrwxr-x 4 root utmp 96 Mar 1 2005 ..
This is a rather brilliantly Unixy use of Unix Sockets wrapped in filesystem permissions to handle security, state, and streams.
这是一个相当出色的 Unixy 使用 Unix 套接字包裹在文件系统权限中来处理安全性、状态和流。
回答by skinp
I'm not really sure of your question, but if all you really want is list currently opened screen session, try:
我不太确定你的问题,但如果你真正想要的是列出当前打开的屏幕会话,请尝试:
screen -ls
回答by JosefAssad
So you're using screen to keep the experiments running in the background, or what? If so, why not just start it in the background?
所以你使用 screen 来保持实验在后台运行,或者什么?如果是这样,为什么不直接在后台启动它?
./experiment &
And if you're asking how to get notification the job i done, how about stringing the experiment together with a mail command?
如果您要问如何获得我完成的工作的通知,如何将实验与邮件命令串在一起?
./experiment && echo "the deed is done" | mail youruser@yourlocalworkstation -s "job on server $HOSTNAME is done"
回答by samurai
Multiple folks have already pointed that
已经有很多人指出
$ screen -ls
would list the screen sessions.
将列出屏幕会话。
Here is another trick that may be useful to you.
这是另一个可能对您有用的技巧。
If you add the following command as a last line in your .bashrcfile on server xxx, then it will automatically reconnect to your screen session on login.
如果您 在服务器 xxx 上的.bashrc文件中添加以下命令作为最后一行,那么它将在登录时自动重新连接到您的屏幕会话。
screen -d -r
Hope you find it useful.
希望你觉得它有用。
回答by o0'.
While joshperry's answer is correct, I find very annoying that it does not tell you the screen name (the one you set with -t option), that is actually what you use to identify a session. (not his fault, of course, that's a screen's flaw)
虽然 joshperry 的回答是正确的,但我发现它没有告诉您屏幕名称(您使用 -t 选项设置的名称)非常烦人,这实际上是您用来识别会话的名称。(当然不是他的错,那是屏幕的缺陷)
That's why I instead use a script such as this: ps auxw|grep -i screen|grep -v grep
这就是为什么我改为使用这样的脚本: ps auxw|grep -i screen|grep -v grep
回答by ObiWahn
In most cases a screen -RRx $username/
will suffice :)
在大多数情况下,一个screen -RRx $username/
就足够了:)
If you still want to list all screens then put the following script in your path and call it screen or whatever you like:
如果您仍想列出所有屏幕,请将以下脚本放在您的路径中,并将其命名为 screen 或任何您喜欢的名称:
#!/bin/bash
if [[ "" != "-ls-all" ]]; then
exec /usr/bin/screen "$@"
else
shopt -s nullglob
screens=(/var/run/screen/S-*/*)
if (( ${#screens[@]} == 0 )); then
echo "no screen session found in /var/run/screen"
else
echo "${screens[@]#*S-}"
fi
fi
It will behave exactly like screen except for showing all screen sessions, when giving the option -ls-all as first parameter.
当将选项 -ls-all 作为第一个参数时,它的行为与 screen 完全一样,除了显示所有屏幕会话。
回答by Ankit jain
For windows system
Open putty
then login in server
If you want to see screen in Console then you have to write command
如果你想在控制台中看到屏幕,那么你必须写命令
Screen -ls
if you have to access the screen then you have to use below command
如果您必须访问屏幕,则必须使用以下命令
screen -x screen id
Write PWD
in command line to check at which folder you are currently
PWD
在命令行中写入以检查您当前所在的文件夹
回答by theworlddecoded
ps x | grep SCREEN
ps x | 屏幕显示
to see what is that screen running in case you used the command
如果您使用该命令,请查看正在运行的屏幕是什么
screen -A -m -d php make_something.php
screen -A -m -d php make_something.php