Process Management In Linux
In this section, I go over process management in a Linux system.
Table of Contents
Managing processes and background jobs is an important skill. These skills make us more efficient to our company. We can start a process and have it run in the background while we work on something in the foreground.
We can use these techniques to schedule jobs to run at night. This allows us to get things done that might affect users in the daytime. Anything we can do to increase our productivity is a bonus and makes you look good.
Monitoring processes is an important to every administrator. When we monitor processes, we can identify problems quickly. We want to find any issues before users do. Processes have programs associated with them and it is important to catch something failing or soon afterwards.
When we actively do a task, such as typing this article out, we are working in the foreground. Another example is running utilities from the command line. As we do these tasks, we typically have to wait for them to finish before we start another. This is ok if it is something short and finishes quickly.
However, only working in the foreground limits our efficiency. One goal of administrators is to be efficient as possible. The reason is that there is often too much work to not be efficient. Any of you that work as admins or in a support role know the amount of work that accumulates. We are probably the biggest reason to-do list software is so popular. So, a marvelous feature of Linux systems is the ability to assign background jobs.
Assigning tasks in the background lets you multitask. If you have a list of forty tasks today, multitask in order to finish them all. So, you start one, then move it to the background. Then you start another. This is all done from the command line, so it is easy to do.
You can also just start a task as a background job. This is handy and eliminates a step. You do this with the & character after the task name.
This starts the command and immediately puts it in the background.
Run this command to see your task running in the background anhd its ID.
Once you have a long task running, you can move it to the background. An example of a long-running task could be a report. You do this with the Bg command. If you have multiple jobs running, then you need to supply the ID of the task name. The Jobs command will give you the ID. However, if there is only one task, you can issue the Bg command without options and it will move the current task to the background.
You can see a list of jobs with the Jobs command. It will also show you the status and ID of any jobs. So, now that you have a background job, you can see it listed with the Jobs command. Use “jobs --help simple” to see its description and arguments.
jobs --help simple
You can bring a background job back to the foreground with the Fg command. You just need to supply its ID. If there is only task, you can just use the Fg command with no options. Like before, you get the ID with the Jobs command.
Every program that is running has a process ID. We can use the PS command to see this status. PS stands for process status. We can use it with zero or more arguments. The arguments are other process IDs. The PS command is used to get running IDs. When entering an ID, we can get information about that distinct process. When using the PS command by itself, it lists processes that came from your terminal. Enter “ps --help simple” to get started with its arguments.
This command shows the amount of free and used memory in your machine. It is customizable in what it can show. The most useful arguments are probably “free -mh” and “free -gh”.
You should run this command often. It gives you important information on what is using your memory. Better yet, script this as a task and have it send you a daily report.
This command shows you how long the system has been up, the users that are logged in, and how busy the system has been. It has a couple other arguments you can use, so use “uptime —help simple” to look at those. I find the default more useful.
Monitoring Your System
The built in utility to do this is the Top command. It gets the job done and is included in most Linux systems. However, these days I would recommend the “Htop” command instead. We installed this with your package manager. On my Fedora system, it is “sudo dnf install htop”. It is a prettier utility and gives better information. There are several options at the bottom of your screen and they can change what it does and its appearance.
Very often, we want to see what processes are changing. This could be for a variety of reasons. Seeing what uses the most memory is a common reason to monitor processes. You can also check that everything is still running or not causing issues. I used to run a Wordpress server where the database process would randomly stop. This was annoying, and I had to watch this process daily for a while.
Processes can receive signals in a variety of ways. We have already talked about this a little. Dealing with foreground and background tasks is another version of this. We can use signals to stop, continue, and kill processes.
The most common task is to kill a process. Do this if it stops working correctly. Sometimes programs can just get stuck and stop responding. When this happens, you should just kill the process so you can restart it.
There are multiple ways of doing this, but I will just mention the Kill command. It is probably the easiest to remember. It also has some arguments and you can see them by using the help for it, “kill --help”.
I need to mention another way of interrupting processes. For example, when we used the Top command earlier, we needed to interrupt it in order to enter other commands. The best way to do this is by using the “control-c” combination. It is another way to signal processes.
There are other ways of sending signals in case you see them. In most cases, they are equivalent to the methods we have described here. They are both good, but they do the same things.
In this section, we have discussed the management of processes in a Linux system. Learning the difference between background and foreground jobs is an important distinction and ability.
Thanks For Reading
Thank you for reading this, I really appreciate it.
If you would like to join my newsletter, you can do so here:
If you need a suggestion on what to read next, then try these Linux articles:
Managing Input and Output Streams in the Linux Shell
Managing Files In A Linux Environment