Reputation:
Execute the command and return immediately, not blocking until the command finishes.
Concepts: Background execution, signals, signal handlers, processes, asynchronous execution System calls: sigset()
How?
Upvotes: 0
Views: 401
Reputation: 151
You can execute a command (or shell script) as a background job by appending an ampersand to the command as shown below.
$ ./my-script.sh &
You can execute a command (or shell script) in the background using &, But the problem with this, if you logout from the session, the command will get killed. To avoid that, you should use nohup as shown below.
example
$nohup ./my-shell-script.sh &
or
$nohup ps -aux &
After you execute a command in the background using nohup, the command will get executed even after you logout. But, you cannot connect to the same session again to see exactly what is happening on the screen. To do that, you should use screen command.
Apart from this, I recommend to use tmux, you can create a session and reattach a session any time.
$tmux new -s mysessionname
More info about tmux
Upvotes: 0
Reputation: 25094
You can direct the outputs to a separate buffer, a file if you don't want to spam your current terminal.
yourapp >> ~/tempOutput.txt &
If you want output it to "nowhere" you can redirect to null
yourapp >> /dev/null &
Upvotes: 1
Reputation: 806
To run the command :
sudo nohup {your command} &
To check the running command process id using nohup
ps -ef | grep nohup
and to kill the command if needed
kill {process id}
Upvotes: 0