Let's take example of a command "example-command".
example-command
in terminal, and example-command
executes. example-command
gets killed too. example-command &
", but the same behaviour. 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. Eg, nohup example-command
. You can background and work with it normally; it will simply continue running after you've quit. disown
command. Unfortunately, as far as I know, disown
is bash-specific; if you use another shell, such tcsh
, you may be restricted to the nohup
form above. 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:
example-command &; disown {pid}
or just
example-command &; disown
You could also consider using the screen command.
nohup example-command
您还可以使用'at'或'batch'命令并为其指定当前时间。
disown is a bash builtin. You could create a wrapper shellscript for your command such as
#!/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
Press: Control-Z
Run: bg
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.