[英]How to spawn process on linux by using new process group id in BASH
Can anyone please advise, how to spawn a new process on linux by using new process group id in BASH unix shell? 任何人都可以建议,如何在BASH unix shell中使用新进程组ID在linux上生成一个新进程? Thank you so much! 非常感谢!
To run a command, eg "emacs xxx.txt", in a new process group, from a command prompt ie interactively: 要在新进程组中从命令提示符运行命令,例如“emacs xxx.txt”,即以交互方式运行:
setsid emacs xxx.txt &
As described in the linked "linux command setsid", the setsid command behaviour can be surprising (and in the linux I'm using just now the manpage is not helpful at all). 如链接的“linux命令setsid”中所述,setsid命令行为可能令人惊讶(在我刚才使用的linux中,联机帮助页根本没用)。 So... 所以...
If you want to spawn a command from within a script and have the command continue after the script exits , double the setsid: 如果要从脚本中生成命令并在脚本退出后继续执行命令,请将setsid加倍:
setsid setsid emacs xxx.txt
... the rationale is: ......理由是:
when bash invokes setsid during script, setsid keeps the process group id of the bash interpreter process, and so: 当bash在脚本期间调用setsid时,setsid会保留bash解释器进程的进程组ID,因此:
setsid emacs xxx.txt setsid emacs xxx.txt
... blocks (see the linked article). ...块(参见链接文章)。 But it does set a new process group before running emacs 但它确实在运行emacs之前设置了一个新的进程组
you can background it with '&': 你可以用'&'来背景:
setsid emacs xxx.txt & setsid emacs xxx.txt&
... but that leaves a race condition where the calling script might exit before the background process gets to the point where setsid changes the process group (which might kill the sub process) ...但是这会留下一个竞争条件,其中调用脚本可能会在后台进程到达setsid更改进程组(可能会终止子进程)之前退出
ie when we double the setsid the sequence is: 即当我们将setsid加倍时,序列是:
From within a script , if you want to communicate with the command and wait for it to exit , see subprocess in the bash manpage. 在脚本中 ,如果要与命令通信并等待它退出 ,请参阅bash联机帮助页中的subprocess。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.