From the course: Cert Prep: LPIC-1 Exam 101 (Version 5.0)

Monitor active processes - Linux Tutorial

From the course: Cert Prep: LPIC-1 Exam 101 (Version 5.0)

Start my 1-month free trial

Monitor active processes

- [Instructor] The PS command shows you up to date process information, but we have to keep running it to get real time data. Linux has another tool used just for displaying real time process information called top. In a terminal, start top by typing in T O P and hitting enter. Note that the display is being updated every couple of seconds. In the summary area at the top of the screen, top shows how long the system has been up, the load average, how many processes are running, how many are waiting for CPU time, the overall CPU usage and memory usage. We can modify this area with a few shortcuts. Press L to show or hide the load average/up time line. Press number 1 if you want to show CPU usage for all CPU cores if you have more than one. Press T if you want to toggle between tasks in CPU states. You can also turn this data off as well. Pressing number 1 and T allows you to have a solid bar for each CPU core. Press M to toggle between different memory displays or turn off memory statistics. In the fields area it shows the same fields as PS. We can change these fields by pressing lowercase F. All the current fields have an asterisk next to them. Select and deselect fields by pressing the spacebar. You can navigate through the list with the up and down arrow keys. For example, if you want to add the parent process ID field, we'd move down with the arrow key and press the spacebar. We can change the sort field by pressing the S key. You'll notice on the top line, our current sort field is now parent process ID. You can move fields around by selecting them and then pressing the right arrow key, and then moving the field to where you want and then press the left arrow key. Press Q to quit the field menu. The next section down shows the processes themselves. We can change the data presented in these fields just like PS. Press C to toggle between command name and command line. Press uppercase U followed by a user's name to show only processes run by that user. I'll type in Grant, which is my username. Press uppercase U again and hit enter to show all processes. We can also scroll through the tasks that are not on the screen using the up and down arrow keys or the page up and page down keys. Not only does top have the ability to show real time process information, but it has the ability to interact with processes as well. One of the most useful things we can do is kill a task. Press K for the kill prompt. We then need to choose a process ID to kill. We can also select a kill signal, sigterm is the default. This is a very friendly way of killing a process. If that doesn't work, we can send it as sigkill signal which forcibly removes the process. To provide a sigkill signal, we'd enter the number 9 when prompted for a signal. If you want to cancel the kill prompt, press escape. We can also renice a command. This changes the nice value of a command which we talk about more in this chapter. The higher the nice value, the nicer the process is to the CPU and thus less priority it gets. Lowering the nice value increases it's priority. To change the nice level of a command, press R then choose a process ID. I'm going to choose 4484, and hit enter. Now we choose a nice level. I'm going to choose 5 and hit enter. If you want to cancel out of the renice prompt, just press escape. A moment ago we looked at changing the sort field. This is useful, but if you quickly wanted to change between sorting by CPU usage and sorting by memory usage, it's too much work to go into the menu and select a different field. To sort by memory usage, press an uppercase M. Press uppercase P to sort by processor or CPU usage. Press an uppercase T to sort by the amount of time a process has been running. And press an uppercase N to sort by process ID number. Top has a ton of features so I encourage you to spend more time with a man page. Press Q to quit and then type in man space top and hit enter.

Contents