我可以禁止/屏蔽已经启动的程序吗?

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

有没有办法“追溯” nohup一个过程,还是我需要离开我的电脑在线整夜? 如果无法将screen到/ nohup我已经开始了,那为什么? 与父母/子女行为如何相互作用? (我不会接受一个“不”的答案,至less不能解决“为什么”的问题 – 对不起)

如果你使用Bash,你可以运行disown -h job

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

如果没有选项,每个jobspec将从活动作业表中删除。 如果给出了-h选项,那么作业不会从表中删除,而是被标记为使得如果shell收到SIGHUP,SIGHUP不会发送到作业。 如果jobspec不存在,也不提供-a-r选项,则使用当前作业。 如果没有jobspec提供, -a选项意味着删除或标记所有作业; 没有jobspec参数的-r选项将操作限制为正在运行的作业。

使用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:将正在运行的进程附加到新的terminal
  • reptyr:更改进程的控制terminal

为了从一个tty窃取一个进程到你当前的tty,你可能想尝试一下这个破解:

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

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

当一个进程启动时,STDIN,STDOUT和STDERR被连接到某个东西 。 一般来说,一旦命令启动,你就不能改变它。 在你描述的情况下,这可能是与ssh会话相关的tty。 nohup几乎没有…

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

也就是说,将STDIN设置为/ dev / null,将STDOUT设置为文件,将STDERR设置为STDOUT。 屏幕做了更复杂的事情,包括设置指向自己的ttys。

我不知道有什么办法来追溯nohup或筛选正在运行的进程。 如果你cd到/ proc / $ pid / fd看看有什么0,1和2指向。

你可能会有一些不愉快的地方,但是如果这个过程试图用STDIN,STDOUT或者STDERR来做任何事,

Cryopid是一个来自grab.c作者的进一步发展,它把一个进程冻结成一个文件,然后运行(屏幕内)来恢复进程。

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

然而,你有没有尝试disown认识(一个bash内build)

 ~ $ 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. 

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

我最近看到一个链接到neercs ,这是一个使用libcaca,一个彩色ascii艺术库build立的屏幕式的工具。 除了其他function之外,它还拥有抓取现有stream程的能力,并将其重新保存在您的neerc(屏幕)会话中。

我还没有使用它,所以我不能评论它是否有效。

我可能在想这个,所以随时纠正我(我已经了解到关于disown!)…不会一个CTRL-Z和“BG”的工作,至less让进程在后台运行? 还是在运行时仍然希望看到STDOUT的关键问题?

如果你能忍受不能与进程交互,而且你不反对加载随机内核模块,那么你可能会比看Snoop更糟糕。 另外,还有一些其他项目。 这里是一个呼叫禁令,它主要可以做你想做的事情。

我想使用nohup (或类似的)来启动links命令行浏览器,并从ASP.NET网站下载文件后附加到它,复杂的身份validation过程和许多隐藏的视图状态,使它很难使用curl / wget的工作。

我终于结束了使用tmux解决了这个工作很棒:

  1. 运行tmux
  2. 运行你的应用程序(在我的情况下links ),并保持运行
  3. closuresSSH会话,应用程序将继续运行
  4. 稍后使用SSH连接到同一台计算机,然后运行tmux attach将应用程序返回到屏幕

是否担心会议超时? 在这种情况下,你可以按Ctrl-z和bg这个过程,然后把一些东西保持活动状态,如“ping -t localhost”或“top”。

如果是你想注销,那么恐怕我不能添加到其他评论。