[英]How do I start a command from terminal so that terminal is not the parent?
Let's take example of a command "example-command". 让我们举一个命令“example-command”的例子。
example-command
in terminal, and example-command
executes. example-command
,并执行example-command
。 example-command
gets killed too. example-command
也会被杀死。 example-command &
", but the same behaviour. example-command &
”,但行为相同。 How do I execute a command so that when I close the terminal, the command doesn't get terminated? 如何执行命令以便在关闭终端时命令不会终止?
There are two ways, identical in result. 有两种方式,结果相同。
nohup
when you start your program. nohup
。 Eg, nohup example-command
. nohup example-command
。 You can background and work with it normally; disown
command. disown
命令。 Unfortunately, as far as I know, disown
is bash-specific; disown
是特定于bash的; if you use another shell, such tcsh
, you may be restricted to the nohup
form above. tcsh
,你可能会被限制在上面的nohup
表单中。 Please search for similar questions first. 请先搜索类似的问题。
Besides the ways listed above, you can do: 除了上面列出的方法,您还可以:
setsid command_name
For example: 例如:
setsid xclock
Thanks 谢谢
In Zsh (not bash) you can: 在Zsh(不是bash)中你可以:
example-command &; disown {pid}
or just 要不就
example-command &; disown
nohup example-command
您还可以使用'at'或'batch'命令并为其指定当前时间。
disown is a bash builtin. disown是一个bash内置。 You could create a wrapper shellscript for your command such as
您可以为您的命令创建包装shellcript,例如
#!/bin/bash
$1 &
P=`which $1`
disown `pidof ${P}`
Not the most robust script (by any means) but may help get you going. 不是最强大的脚本(无论如何),但可能有助于你前进。 For example:
例如:
$./launch_script.sh myProgram
You can also do this in the source of the program if you are editing it. 如果您正在编辑它,也可以在程序源中执行此操作。
Run: example-command 执行命令example-command
Press: Control-Z 按:Control-Z
Run: bg 运行:bg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.