Reputation: 12857
I'm trying to use a shell script to start a command. I don't care if/when/how/why it finishes. I want the process to start and run, but I want to be able to get back to my shell immediately...
Upvotes: 134
Views: 142878
Reputation: 211
screen -m -d $command$
starts the command in a detached session. You can use screen -r
to attach to the started session. It is a wonderful tool, extremely useful also for remote sessions. Read more at man screen
.
Upvotes: 8
Reputation: 28209
Everyone just forgot disown
. So here is a summary:
&
puts the job in the background.
disown
removes the process from the shell's job control, but it still leaves it connected to the terminal.
SIGHUP
(If the shell receives a SIGHUP
, it also sends a SIGHUP
to the process, which normally causes the process to terminate).nohup
disconnects the process from the terminal, redirects its output to nohup.out
and shields it from SIGHUP
.
SIGHUP
.&
(as a background job).Upvotes: 100
Reputation: 57284
nohup cmd
doesn't hangup when you close the terminal. output by default goes to nohup.out
You can combine this with backgrounding,
nohup cmd &
and get rid of the output,
nohup cmd > /dev/null 2>&1 &
you can also disown
a command. type cmd
, Ctrl-Z
, bg
, disown
Upvotes: 58
Reputation: 16226
Alternatively, after you got the program running, you can hit Ctrl-Z which stops your program and then type
bg
which puts your last stopped program in the background. (Useful if your started something without '&' and still want it in the backgroung without restarting it)
Upvotes: 29
Reputation: 224884
You can just run the script in the background:
$ myscript &
Note that this is different from putting the &
inside your script, which probably won't do what you want.
Upvotes: 146