AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 24425
Accepted
ojrac
ojrac
Asked: 2009-06-12 14:53:44 +0800 CST2009-06-12 14:53:44 +0800 CST 2009-06-12 14:53:44 +0800 CST

我可以 nohup/screen 已经启动的进程吗?

  • 772

我正在通过 SSH 对长时间运行的数据迁移脚本进行一些测试。假设我在下午 4 点左右开始运行脚本;现在,下午 6 点左右,我在诅咒自己没有做这一切screen。

有什么方法可以“追溯”nohup一个过程,还是我需要让我的电脑整夜在线?如果无法附加screen到/nohup我已经开始的进程,那为什么?与父/子进程如何交互有关?(我不会接受至少不能解决“为什么”问题的“否”答案——对不起;))

linux unix ssh gnu-screen nohup
  • 13 13 个回答
  • 96332 Views

13 个回答

  • Voted
  1. Best Answer
    gharper
    2009-06-12T15:03:32+08:002009-06-12T15:03:32+08:00

    如果您使用的是 Bash,则可以运行disown -h job

    否认

    disown [-ar] [-h] [jobspec ...]
    

    如果没有选项,每个作业规范都会从活动作业表中删除。如果-h给出该选项,则不会从表中删除作业,但会被标记,以便在 shell 接收到 SIGHUP 时不会将 SIGHUP 发送到作业。如果 jobspec 不存在,也没有提供-anor-r选项,则使用当前作业。如果未提供作业规范,则该-a 选项表示删除或标记所有作业;没有 jobspec 参数的-r选项将操作限制为正在运行的作业。

    • 219
  2. Jonathan Tran
    2011-05-23T13:27:31+08:002011-05-23T13:27:31+08:00

    使用reptyr

    从自述文件:

    reptyr - A tool for "re-ptying" programs.
    -----------------------------------------
    
    reptyr is a utility for taking an existing running program and
    attaching it to a new terminal. Started a long-running process over
    ssh, but have to leave and don't want to interrupt it? Just start a
    screen, use reptyr to grab it, and then kill the ssh session and head
    on home.
    
    USAGE
    -----
    
      reptyr PID
    
    "reptyr PID" will grab the process with id PID and attach it to your
    current terminal.
    
    After attaching, the process will take input from and write output to
    the new terminal, including ^C and ^Z. (Unfortunately, if you
    background it, you will still have to run "bg" or "fg" in the old
    terminal. This is likely impossible to fix in a reasonable way without
    patching your shell.)
    

    作者的几篇博文:

    • reptyr:将正在运行的进程附加到新终端
    • reptyr:更改进程的控制终端
    • 86
  3. Juliano
    2009-06-12T21:38:03+08:002009-06-12T21:38:03+08:00

    要将进程从一个 tty 窃取到您当前的 tty,您可能想尝试以下 hack:

    http://www.ucc.asn.au/~dagobah/things/grab.c

    它需要重新格式化才能编译到当前的 Linux/glibc 版本,但仍然可以工作。

    • 24
  4. freiheit
    2009-06-12T15:04:10+08:002009-06-12T15:04:10+08:00

    当一个进程启动时,STDIN、STDOUT 和 STDERR 连接到something。通常,一旦命令启动,您就无法更改它。在您描述的情况下,这可能是与 ssh 会话关联的 tty。nohup 几乎就是...

    command < /dev/null > nohup.out 2>&1
    

    也就是说,将 STDIN 设置为 /dev/null,将 STDOUT 设置为文件,将 STDERR 设置为 STDOUT。Screen 做了更复杂的事情,包括设置直接指向自身的 tty。

    我不知道有任何方法可以追溯 nohup 或筛选正在运行的进程。如果您 cd 到 /proc/$pid/fd 并查看 0、1 和 2 指向什么。

    你可能对 disown 有一些运气,但如果进程尝试使用 STDIN、STDOUT 或 STDERR 做任何事情,则不会。

    • 18
  5. Martin M.
    2009-06-12T15:02:34+08:002009-06-12T15:02:34+08:00

    我只能给你一个简单的“不”,没有屏幕部分的原因,我会对你自己的原因感兴趣。

    但是,您是否尝试过disown(内置 bash)

    ~ $ echo $SHELL
    /bin/bash
    ~ $ type disown
    disown is a shell builtin
    ~ $ help disown
    disown: disown [-h] [-ar] [jobspec ...]
         By default, removes each JOBSPEC argument from the table of active jobs.
        If the -h option is given, the job is not removed from the table, but is
        marked so that SIGHUP is not sent to the job if the shell receives a
        SIGHUP.  The -a option, when JOBSPEC is not supplied, means to remove all
        jobs from the job table; the -r option means to remove only running jobs.
    
    • 13
  6. TRS-80
    2009-06-15T10:26:06+08:002009-06-15T10:26:06+08:00

    Cryopid是从grab.c 的作者进一步开发的,它将一个进程冻结为一个文件,然后您运行(在屏幕内)以恢复该进程。

    • 13
  7. alanc
    2009-06-13T16:59:20+08:002009-06-13T16:59:20+08:00

    Solaris/OpenSolaris 上的 nohup 有一个 -p 标志来 nohup 正在运行的进程 - 例如,请参阅Solaris 10 nohup 手册页。

    • 10
  8. Daniel Lawson
    2009-06-15T13:03:02+08:002009-06-15T13:03:02+08:00

    我最近看到了一个指向neercs的链接,它是一个使用 libcaca(一个彩色 ascii-art 库)构建的类似屏幕的实用程序。除其他功能外,它还拥有抓取现有进程并在您的 neercs(屏幕)会话中重新父级的能力。

    但是我没有使用它,所以我无法评论它是否有效。

    • 5
  9. Chris_K
    2009-06-12T15:08:58+08:002009-06-12T15:08:58+08:00

    我可能想不到这一点,所以请随时纠正我(我已经了解了 disown!)...... ctrl-Z 和“bg”不会至少让进程在后台运行吗?还是您仍然希望在运行时看到 STDOUT 的关键问题?

    • 2
  10. David Pashley
    2009-06-12T15:35:40+08:002009-06-12T15:35:40+08:00

    如果您可以忍受无法与进程交互并且不反对加载随机内核模块,那么您可能会比查看Snoop做得更糟。或者,还有其他几个项目。这是一个调用injcode,它主要可以做你想做的事情。

    • 2

相关问题

  • 你最喜欢的 Linux 发行版是什么?[关闭]

  • 更改 PHP 的默认配置设置?

  • 保护新的 Ubuntu 服务器 [关闭]

  • (软)Ubuntu 7.10 上的 RAID 6,我应该迁移到 8.10 吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    Windows 中执行反向 DNS 查找的命令行实用程序是什么?

    • 14 个回答
  • Marko Smith

    如何检查 Windows 机器上的端口是否被阻塞?

    • 4 个回答
  • Marko Smith

    我应该打开哪个端口以允许远程桌面?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch 如何更改我的私钥密码? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve