[
162
]
Managing jobs
Up until now, everything we have been doing on the shell has been right in front of
us, from execution to completion. We've installed applications, run programs, and
walked through various commands. Each time, we've had control of our shell taken
from us, and we've only been able to start a new task when the previous one had
finished. For example, if we were to install the
vim-nox
package with the
apt install
command, we would watch helplessly while
apt
takes care of fetching the package
and installing it for us. While this is going on, our cursor goes away and our shell
completes the task for us without allowing us to queue up another command. We
can always open a new shell to the server and multi-task by having two windows
open at once, each doing different tasks. But that's likely not going to be the most
efficient method of multitasking when working with the command line.
Instead, we can actually background a process without waiting for it to complete
while working on something else. Then, we can bring that process back to the front
to return to working on it or to check whether or not it finished successfully. Think
of this as a similar concept to a windowing desktop environment, or user interfaces
on the Windows or macOS operating systems. We can work on an application,
minimize it to get it out of the way, and then maximize it to continue working with
it. Essentially, that's the same concept of backgrounding a process in a Linux shell. If
you were curious how I had a Vim process running in the background earlier while
discussing prioritizing processes, what I did was send it to the background.
So how exactly do you background and foreground a process? This concept can be
somewhat difficult to explain. In my opinion, the easiest way to learn a new concept
is to try it out, and the easiest example I can think of is by (yet again) using a text
editor. I promise that this time, using a text editor as an example won't be lame.
In fact, this example is extremely useful and may just become a part of your daily
workflow. To do this exercise, you can use any command-line text editor you prefer,
such as Vim or Nano. On Ubuntu Server,
nano
is usually installed by default, so
you already have it if you want to go with that. If you prefer to use Vim, feel free to
install the
vim-nox
package if you haven't already installed it:
sudo apt install vim-nox
You can actually install
vim
rather than
vim-nox
, but I always
default to
vim-nox
since it features built-in support for scripting
languages.
Chapter 7
Do'stlaringiz bilan baham: |