如何从Linux中的另一个终端访问一个终端上运行的进程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8147403/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 21:42:52  来源:igfitidea点击:

How to get access of process running on one terminal from other terminal in Linux?

linuxprocessterminal

提问by Praveen

I want to know the procedure so that i can access or get control from terminal over the process running on some other terminal in Linux .

我想知道该过程,以便我可以通过终端访问或控制 Linux 中其他终端上运行的进程。

  • Both terminals belong to same system .
  • 两个终端属于同一个系统。

回答by John Riselvato

Are we talking SSH? If soo...

我们在谈论 SSH 吗?如果是...

  • SSHinto the host that has the process running:

    ssh user@host

    Then to viewprocesses running on the host type:

    ps aux | less

  • 通过 SSH 连接到运行该进程的主机:

    SSH 用户@主机

    然后查看在主机类型上运行的进程:

    ps辅助| 较少的

Gain Control? Not exactly sure what that means but ill list some simple commands.

获得控制权?不完全确定这意味着什么,但我会列出一些简单的命令。

  • View processes by "userName"

    ps -u userName

  • Look up Process

    pgrep firefox

  • Kill a process

    example:

    pidof firefox

    output: (your number will be different.)

    2786

    Now the kill:

    kill 2786

  • 按“用户名”查看进程

    ps -u 用户名

  • 查找过程

    火狐浏览器

  • 杀死一个进程

    例子:

    pidof 火狐

    输出:(你的号码会有所不同。)

    2786

    现在杀戮:

    杀死 2786

Advanced

先进的

  • shows running processes as a tree.

    pstree

  • Might be interested in looking into atop

    atop

  • 将正在运行的进程显示为树。

    pstree

  • 可能有兴趣研究顶部

    在顶上

回答by abhi_ksd

Use the screenutility to start any process from terminal, so that you can access the same process from any other terminal either locally or remotely. For instance:

使用screen实用程序从终端启动任何进程,以便您可以从本地或远程的任何其他终端访问相同的进程。例如:

From first terminal

从第一个终端

  1. Start a screen using screen -dR testand hit Enter, you will get shell within in screen.
  2. Run you program here
  1. 使用screen -dR test并点击启动屏幕Enter,您将在屏幕中获得 shell。
  2. 在这里运行你的程序

From second terminal

从第二个终端

  1. Get in to existing screen using screen -x test
  1. 使用进入现有屏幕 screen -x test

Now you should be able to see process running on first terminal, and will have the full control over that process.

现在您应该能够看到在第一个终端上运行的进程,并且可以完全控制该进程。

You can investigate more on screen utility… its a very useful tool for any system administrator.

您可以在屏幕实用程序上进行更多调查……对于任何系统管理员来说,它都是一个非常有用的工具。

Hope the above tip will help you.

希望以上提示能帮到你。

回答by onionjake

Pehaps you want something like reptyr? (https://github.com/nelhage/reptyr)

也许你想要这样的东西reptyr?( https://github.com/nelhage/reptyr)

You simply type reptyr PIDto 'gain control' of another process (like vim or whatnot).

您只需键入reptyr PID即可“控制”另一个进程(例如 vim 或诸如此类)。

Edit:

编辑:

This questionhas more information on using screen or tools like reptyr.

这个问题有更多关于使用屏幕或像 reptyr 这样的工具的信息。

回答by Phreakmtl

I know this is an old thread. But in the event you want à duplicate of à linux tty you can use conspy http://linux.die.net/man/1/conspyIt is small ans easy to compile if its not already on your distribution

我知道这是一个旧线程。但是,如果您想要 à linux tty 的副本,您可以使用 conspy http://linux.die.net/man/1/conspy如果您的发行版中还没有它,那么它很容易编译