Suggest a StoryDo you have a news tip? We would like to hear from you.

[How To]: Retrieve Jobs from the background to the foreground in Terminal

Spread the love

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, especially if you are using terminal “tty” with a 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 the terminal are using Ctrl-C or using the kill command with PID “process id”, both of them complete kill the application and it’s no 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 processes it moves to the background and shows you 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.

jobs -l

Retrieve a job to the foreground using fg command

fg "JobID"

Replace the “JobID” with the Job ID. For example, I want to retrieve “top” system monitor I will use this command.

fg 2

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 processes in the background. Also, if am switching between only to the application I prefer to use the fg command with “+/-“. Check the table down below.

%Number Refers to a job by the job number.
%String Refers to a job whose name begins with the specified string.
%?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.

Spread the love

Leave a Reply