【发布时间】:2020-11-06 02:03:27
【问题描述】:
我很清楚duplicate question 的存在。但该问题已被标记为已回答,我认为它根本无法回答原始问题。
即使 nohup 的父进程 (shell) 死亡,$ nohup command 也会继续执行命令。更多信息在这里:What's the difference between nohup and ampersand。
在 Win32 api 的情况下,我看到 When the system is terminating a process, it does not terminate any child processes that the process has created. Terminating a process does not generate notifications for WH_CBT hook procedures. 行。这是我要问的理想行为。这适用于 win32 powershell 自动。但是对于 linux powershell 的 Start-Job,它只是 powershell 上下文中的后台作业,因为当 powershell 被杀死时它会被杀死。
例子:
➜ ~ powershell-preview -c "Start-Job { /bin/sleep 1000 }"
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 Job1 BackgroundJob Running True localhost /bin/sleep 1000
➜ ~ ps ux | grep sleep
mvaidya 166986 0.0 0.0 9032 664 pts/11 S+ 18:59 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox sleep
【问题讨论】:
-
顺便说一句:即使在 Windows 上,运行使用
Start-Job创建的作业的子进程也会在启动 shell 退出时被终止。
标签: powershell powershell-core powershell-7.0