Here is the video version, if you prefer it:
There exist two kinds of processes. Ones that execute in the background and ones that execute in the foreground. (Ward, 2014)
Background processes are useful for situations where the program is going to be running for a long time or you want to be able to use your Terminal while the program is running. We have run all of our commands so far in the foreground – meaning we didn’t get back our Terminal until the command stopped executing. All of the commands we have used so far have relatively short running time so there was no need for running them in the background.
To give you an example of a program I could run in the background, let’s look at Mendeley (a program I use for citations). I am currently running it in the foreground and it looks like this:
mislav@mislavovo-racunalo:~/Downloads/mendeleydesktop-1.19.4-linux-x86_64/bin$ ./mendeleydesktop
See how at the end I don’t have another mislav@mislavovo-racunalo
prompt? That’s because Mendeley is running in the foreground. If I wanted to run it in the background, I would write an & at the end of the command to start Mendeley and I would get something like this:
mislav@mislavovo-racunalo:~/Downloads/mendeleydesktop-1.19.4-linux-x86_64/bin$ ./mendeleydesktop &
[1] 27961
mislav@mislavovo-racunalo:~/Downloads/mendeleydesktop-1.19.4-linux-x86_64/bin$
And I have my prompt back. Mendeley is now started in the background. The number 27961
is Mendeley’s process ID which I can use to manipulate it.
This is for you to know that you can run processes both in the background and in the foreground and to know what & is used for. Also, remember that every process has its process ID (PID), no matter if it is started in the foreground or the background.
Hope you found this useful!
References
Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 32-33
Subscribe to my newsletter to keep abreast of the interesting things I'm doing. I will send you the newsletter only when there is something interesting. This means 0% spam, 100% interesting content.