facebook youtube pinterest twitter reddit whatsapp instagram

Managing Jobs In Ubuntu (Minimize Processes)

One of the most frustrating experience when working on the shell or terminal is the limited control you have when a task is undergoing processes or running, for example, if you try installing a package, say mysql-server with the apt install command, we would watch how apt does its thing without the ability to do other stuff while that process is going on.

If you are used to windows OS, it can even be more annoying as we are used to multitasking. Of course, you can open a new terminal or shell and multi-task away, but it gets crazy when you have 5 terminal opened at a time, what if we can sort of background the process, or in other words, minimize the ongoing process and continue with other stuff.

In this guide, you will learn how to minimize processes, and work on other stuff while the process is still going on, this is similar to the way you would minimize a program on Windows or macOS, let's get started...

The scenario of what we would do are:

  • Open a new file in a text editor
  • Write a dummy or random words in the opened file
  • Background the text-editor, think of minimizing Microsoft Word
  • Confirm if the process is still running (the text editor)
  • Open up Text editor 2, write random words, background it
  • Bring up the first text editor, and save the file you are editing, background it and
  • Bring back the second text editor, save the file you are editing.

Create a new file using the nano editor in your home directory, for example:

 nano ~/note-1

The ~/ would reference the user home directory, for example, if the current user home folder is James, it would create the file in /home/james/note-1

With the note-1 file opened, write any random text, I will be writing: This is my first note book

Alright, press Ctrl + Z on your keyboard to minimize the note-1 file.

You can see you were immediately taken away from the editor, and taken to the shell to do other stuff. If you've done everything right, you should see an output similar to below:

[1]+ Stopped nano ~/note-1

The [1] is the job number of our process, Stopped is its status (more on this below), and lastly, it shows you are working on a file name note-1 in the home directory.

The stopped status means the process has been temporarily put into the background and is no longer attached to the current terminal (cannot produce output and is not receiving input from the user), but it is still using the system memory.

The TLDR version is stopped means the process is running in the background.

To confirm if the process is still running, run the following command:

ps au | grep nano

The above command is basically saying, look for a process named nano if running, and pipe the output into grep, the output is as follows:

user 5594 0.0 0.2 22280 4152 pts/0 T 21:31 0:00 nano /home/user/note-1

The PID of the above nano process is 5594, this would be different from yours.

Learn More on Displaying Running Processes In Ubuntu

As the process is minimized, you can go ahead and do other stuff, let's create an additional file.

 nano ~/note-2

With the note-2 file opened, write any random text, I will be writing: This is my second note book

Background it using Ctrl + Z

At this point, we haven't saved any of the files opened, which would get lost if we log out of the system. Let's save the first file in the text-editor, bring it up using the fg command.

What?

It didn't bring up the first text editor, it instead brought up the most recent opened process (which is the opened note-2 file in the nano editor), background it and execute the jobs command, and you should see the following output:

[1]- Stopped nano ~/note-1
[2]+ Stopped nano ~/note-2

The output shows that I have two nano sessions in use, one modifying the note-1 file, and the other modifying note-2 file.

To bring up the first nano session, you simply run the fg command followed by the Job ID:

fg 1

Save the file you are editing using Ctrl + x and Y to confirm the changes.

If you re-run the jobs command you would see it only has one process left in the background, just type fg to bring it and up and save.

You can see how handy it is to background processes, you don't even have to use Ctrl + Z to background a process, you can background a process right when you execute it by entering a command with the ampersand symbol (&), for example, to open up a new a file in nano and background it immediately, use the following command:

nano ~/nano-3 &

This would open up a new file and background it immediately.

Note: Not all applications support background, in this case, you either use a multiplexer or even running a new instance of the terminal or shell.

Related Post(s)

  • Monitoring Multiple Log Files In RealTime With MultiTail (Ubuntu)

    Oh my... I really find scanning through the logs file time consuming, and painful. Luckily for me, I founded Multitail, which is an awesome, and powerful tool for not only browsing through several f

  • How To Find Files Using Locate in Ubuntu

    It's kind of frustrating when you are searching for a particular file, and you have no idea of how to find it, In this guide, I'll walk you through on two different ways you can find a file in your G

  • Managing MariaDB Databases (Ubuntu Server)

    In this guide, you'll learn how to manage MariaDB databases in your terminal, from connecting to the database server using the mariadb command, creating a database, removing (drop) database, and mana

  • Viewing Disk Usage in Ubuntu

    There are several ways to view disk usage in your Linux system, and that is what we would be going over in this guide... Out of the box, Linux provides us the df command, which is the standard Unix c

  • Understanding & Using Symbolic & Hard Links (Ubuntu)

    Have you ever wondered how you can create shortcuts that link to other files in Linux? Well, let me introduce you to symbolic and hard links. The two types of links in Linux are symbolic links and ha

  • Installing and Using dig in Ubuntu

    dig is an awesome utility for querying DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. In this guide, you'll learn how