今天我发现了一个奇怪的行为,我希望我可以得到一些方向.
至少有一个进程已在后台运行,我中断(Ctrl+ Z)前台进程,然后将其放在后台bg.
zsh:$ some-long-running-command
^Z
zsh: suspended some-long-running-command
$ bg
[2] - continued some-long-running-command
$ jobs
[1] + running other-command-previously-run
[2] - running some-long-running-command
$
Run Code Online (Sandbox Code Playgroud)
bash:$ other-command-previously-run &
[1] 12345
$ some-long-running-command
^Z
[2]+ Stopped some-long-running-command
$ bg
[2]+ some-long-running-command &
$ jobs
[1]- Running other-command-previously-run &
[2]+ Running some-long-running-command &
$
Run Code Online (Sandbox Code Playgroud)
那么为什么bash将进程保留在后台bg作为"当前"进程(用"+"表示,如果fg运行则将恢复),同时zsh将"其他"进程设置为当前进程?我找不到任何文件表明行为会有所不同......有趣的是,如果你做了几个fg+ ^Z+ bgin zsh,那么"当前"进程选择将"翻转".
有没有人见过这个?
bash我可以在和中重现这种行为zsh。
我的 TL;DR 答案:您看到的行为bash已记录在案。你看到的行为zsh不是(我发现的),而且我有一个理论,这可能是错误的。
重击:
\nBash手册第 7 节“作业控制基础知识”描述了内置函数的行为bg:
\n\n符号 \xe2\x80\x98%%\xe2\x80\x99 和 \xe2\x80\x98%+\xe2\x80\x99 指的是 shell 的当前作业概念,即最后一个停止的作业当它在前台或在后台启动时。
\n
因此,从 的角度来看bash,当前作业是在前台停止或在后台启动的最后一个作业。这解释了问题中注意到的行为:
\n\n那么为什么 bash 将进程放置在后台,而 bg 作为“当前”进程
\n
ZSH:\n我无法解释这一点zsh。该man zshmisc页面下的部分JOBS解释了和中zsh的含义:+-jobs
\n\n%% 当前工作。
\n
\n%+ 相当于 \xe2\x80\x98%%\xe2\x80\x99。
\n%- 以前的工作。
然而,它并没有bg解释和对将过程降级为fg或的影响。^Zpreviouscurrent
我的理论(我还没有通过纠缠中的好人来验证irc.freenode.net#zsh)是zsh使用“当前进程堆栈”;bg将current进程推到队列末尾。当使用三个进程时可以看出这一点:
\nsimont@charmander ~/repositories/SOTesting/bg\n $ one.sh& [1:52:41]\n[1] 98369\n\nsimont@charmander ~/repositories/SOTesting/bg\n $ two.sh& [1:52:49]\n[2] 99293\n\nsimont@charmander ~/repositories/SOTesting/bg\n $ three.sh [1:52:51]\n^Z\n[3] + 973 suspended three.sh\n\nsimont@charmander ~/repositories/SOTesting/bg\n $ jobs [1:52:55]\n[1] running one.sh\n[2] - running two.sh\n[3] + suspended three.sh\n\nsimont@charmander ~/repositories/SOTesting/bg\n $ bg [1:52:57]\n[3] - 973 continued three.sh\n\nsimont@charmander ~/repositories/SOTesting/bg\n $ jobs [1:52:59]\n[1] running one.sh\n[2] + running two.sh\n[3] - running three.sh\nRun Code Online (Sandbox Code Playgroud)\n正如我们在这里看到的,one和two被推到理论堆栈上。three,最后执行的(?)是,由输出中的current process表示。\n挂起后,它仍然是当前进程,但在 后,它被推送到进程中,并且作为“堆栈”中的“顶部”进程成为新进程。+jobsthreebgprevioustwocurrent
然而,这只是推测;就像我说的,我还没有得到这方面的书面证据,而且说实话,这些man zsh*页面有点复杂;我可能错过了什么。
| 归档时间: |
|
| 查看次数: |
1913 次 |
| 最近记录: |