Switching between applications running in the background in your current tty is no longer a problem with this tutorial. Here’s a quick tutorial for how to retrieve jobs to the foreground of your current environment.
I guess many of you guys prefer to use the terminal emulator over the graphical user interface for doing several things, specially if you are using terminal “tty” with single window and there’s no way to open multiple terminal tabs in some of “tty” consoles.
Closing an application and Moving an application to the background
Commonly used methods to close an application in terminal are using Ctrl-C or using the kill command with PID “process id”, both of them complete kill the application and it’s not longer available in the background. But, what if you want to use that application later or want to keep it in the background of the shell and retrieve it later to the foreground, we use Ctrl-Z which moves the applications to the background and I will show you down below how to retrieve the application and easily switch between them.
So, here in my shell I have five application running for tutorial purposes, “MOC” audio player, “top” system monitor, “nano” text editor running twice for different text files, and “VIM” text editor as well.
All of these applications have been moved to the background using Ctrl-Z. When you click Ctrl-Z to any of these process it moves to the background and show you the the JobID “number” of this process you have moved which you will need later to retrieve that job.
Show all Jobs in the Background
So, after you have moved all applications to the background, you will probably need to know the JobID for these process in the background. Simply run this command to show all jobs and with its JobID.
Retrieve a job to the foreground using fg command
Replace the “JobID” with the the JobID. For example I want to retrieve “top” system monitor I will use this command.
Also, there are several methods to retrieve jobs from the background to the foreground using fg command. However, I prefer to use the fg command with the JobID option in case I am running several process in the background. Also, if am switching between only to application I prefer to use the fg command with “+/-”. Check the table down below.
||Refers to a job by the job number.
||Refers to a job whose name begins with the specified string.
||Refers to a job whose name contains the specified string.
|%+ OR %%
||Refers to the current job.
||Refers to the previous job.
fg command IBM.