Many new sysadmins find it very difficult to accomplish multiple tasks once a process takes longer. This often happens on servers where multiple applications are deployed.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux System processes and queries.
In this context, we shall look into how to send processes to the background in Linux to free our terminal to get back control of our system.
The reason for this is to set the terminal free for the next command. Also whenever anything happens, most of the time either using a desktop or a server instance, we have access to a terminal only. At that time, a user doesn’t want it to be occupied by one job. Thanks to Linux, we can free the terminal from sending a job to the background and keep running new commands to get back to our system.
Running a process in Linux system
Running a process is as simple as running any other piece of software on Linux. We are going to run a trimage package for our illustration here. To run a trimage package, simply execute the following command:
$ trimage
You will see that the trimage package is running without any issues but the terminal is now stuck.
Sending a trimage to the background is as simple as hitting Ctrl + Z and it will stop the trimage job for the time being.
This happens when you run the command below and hit enter:
$ bg
The bg Command will send the trimage process to the background. Trimage will keep running as usual whereas the terminal will be free to perform the next command.
If the package has a GUI, you can choose to close it from there, but if the package doesn't have any GUI you can simply use
$ fg
This command will push the process to the foreground.
Now close the process as always we do use Ctrl + C and you'll return to a normal terminal.
This article covers the best method to send processes to the background in your Linux system. This is helpful, if you have started a command on terminal and that command is taking to much time. Now you want to move that in background, so that you can continue with other tasks.
To list all jobs running in background use jobs command. It will show all running commands with their job id:
$ jobs
How to Place a Running Foreground Process into the Background in Linux ?
A foreground process is the a process. In order to place a foreground process into the background, we must first put the process to sleep, and then place it in the background.
Execute the command to run your process.
Press CTRL+Z to put the process into sleep.
Run the bg command to wake the process and run it in the background.