Running processes as background jobs
On a linux terminal you can simply run a process in the foreground like it normally does. But if you close your terminal session the process will stop running. If you run a large database import you don’t want to wait for it to finish, so you want to run it in the background.
To do this you can simply put a ‘&‘ behind the command you want to execute, for example:
mysql -u root -p < import.sql &
But it’s also possible to put a process to the background when it’s already running. You can do this with the keyboard shortcut ctrl + z. Then you ‘stop’ the process. You should see a message like this:
[1]+ Stopped mysql
Now you can choose two things, one is to run it in the foreground, the other is to run it in the background.
Just type bg <enter> and the process will continue running in the background. With fg <enter> it will run in the foreground.
You can see what processes are running in the back- or foreground with the command jobs.
Screen is also a handy utility to put processes to the background. You can connect later to see it’s output, the job keeps running when you are logged out, etc.