ojr*_*rac 272 linux unix ssh nohup gnu-screen
我正在通过 SSH 对长时间运行的数据迁移脚本进行一些测试。假设我在下午 4 点左右开始运行脚本;现在,下午 6 点左右,我诅咒自己没有全力以赴screen。
有什么办法可以“追溯”nohup一个进程,还是我需要整晚让我的电脑在线?如果无法附加screen到/nohup我已经开始的进程,那为什么?与父/子进程的交互方式有关吗?(我不会接受至少没有解决“为什么”问题的“否”答案——抱歉;))
gha*_*per 215
如果您使用的是 Bash,则可以运行 disown -h job
Run Code Online (Sandbox Code Playgroud)disown [-ar] [-h] [jobspec ...]如果没有选项,每个作业规范都会从活动作业表中删除。如果
-h给出该选项,则作业不会从表中删除,但会被标记,以便在 shell 收到 SIGHUP 时不会将 SIGHUP 发送到作业。如果 jobspec 不存在,并且没有提供-anor-r选项,则使用当前作业。如果没有提供jobspec,则该-a选项表示删除或标记所有作业;-r没有 jobspec 参数的选项将操作限制为正在运行的作业。
小智 85
使用爬虫
从自述文件:
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.)
Run Code Online (Sandbox Code Playgroud)
其作者的一些博客文章:
Jul*_*ano 22
要将进程从一个 tty 窃取到您当前的 tty,您可能想尝试以下 hack:
http://www.ucc.asn.au/~dagobah/things/grab.c
它需要一些重新格式化才能编译到当前的 Linux/glibc 版本,但仍然有效。
fre*_*eit 18
当一个进程启动时,STDIN、STDOUT 和 STDERR 连接到某些东西。通常,一旦命令启动,您就无法更改它。在您描述的情况下,这可能是与 ssh 会话相关的 tty。nohup 几乎只是...
command < /dev/null > nohup.out 2>&1
Run Code Online (Sandbox Code Playgroud)
也就是说,将 STDIN 设置为 /dev/null,将 STDOUT 设置为文件,将 STDERR 设置为 STDOUT。Screen 做更复杂的事情,包括设置指向自身的 tty。
我不知道有什么方法可以追溯 nohup 或筛选正在运行的进程。如果您 cd 到 /proc/$pid/fd 并查看 0、1 和 2 指向什么。
您可能对 disown 有一些运气,但如果进程尝试使用 STDIN、STDOUT 或 STDERR 执行任何操作,则不会。
Mar*_* M. 13
我只能给你一个简单的“不”,没有屏幕部分的原因,我会对你自己的原因感兴趣。
但是你有没有试过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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
92322 次 |
| 最近记录: |