![](/img/trans.png)
[英]how do I start a command in a terminal as if I'd opened the terminal and typed the command
[英]How do I start a command from terminal so that terminal is not the parent?
让我们举一个命令“example-command”的例子。
example-command
,并执行example-command
。 example-command
也会被杀死。 example-command &
”,但行为相同。 如何执行命令以便在关闭终端时命令不会终止?
有两种方式,结果相同。
nohup
。 例如, nohup example-command
。 您可以正常背景和使用它; 退出后它会继续运行。 disown
命令。 不幸的是,据我所知, disown
是特定于bash的; 如果你使用另一个shell,比如tcsh
,你可能会被限制在上面的nohup
表单中。 请先搜索类似的问题。
除了上面列出的方法,您还可以:
setsid command_name
例如:
setsid xclock
谢谢
在Zsh(不是bash)中你可以:
example-command &; disown {pid}
要不就
example-command &; disown
您还可以考虑使用screen命令。
nohup example-command
您还可以使用'at'或'batch'命令并为其指定当前时间。
disown是一个bash内置。 您可以为您的命令创建包装shellcript,例如
#!/bin/bash
$1 &
P=`which $1`
disown `pidof ${P}`
不是最强大的脚本(无论如何),但可能有助于你前进。 例如:
$./launch_script.sh myProgram
如果您正在编辑它,也可以在程序源中执行此操作。
执行命令example-command
按:Control-Z
运行:bg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.