Many times you would want process to keep running in background forever be it running a service or executing binary. If not started in background process will get killed as your console session end.
We will be sharing few tricks as how you can achieve this in Linux
1) Using Screen Command
To start process in background with screen use these steps
Screen command in Linux allow you to use multiple shell sessions which are forked from single shell session, this allow launching process from screen command and detaching them as separate shell session.
Install screen using this command depending upon linux distribution you are using
apt-get install screen
or
yum install screen
To Execute a Command in Background use this screen command
screen -dm <your command>
This will detach session immediately
To Start process in background with session name use this command
screen -S <session-name> -dm <your command>
Use ctrl + a + d to detach from the screen and keep the process running in background.
you can check running screen session executing your process in background using command
screen -ls
2) Using bg Command to send already running commands to background
Once you start the command in shell you can easily use bg command to send it to background
Simply interrupt the command with CTRL + Z and then execute bg to send last running process to background