Linux Bible. Christopher Negus. Читать онлайн. Newlib. NEWLIB.NET

Автор: Christopher Negus
Издательство: John Wiley & Sons Limited
Серия:
Жанр произведения: Зарубежная компьютерная литература
Год издания: 0
isbn: 9781119578895
Скачать книгу
virtual memory allocated (vsz), resident memory used (rss), and the full command line that was run (comm). By default, output is sorted by process ID number.

       $ ps -eo pid,user,uid,group,gid,vsz,rss,comm | less PID USER UID GROUP GID VSZ RSS COMMAND 1 root 0 root 0 187660 13296 systemd 2 root 0 root 0 0 0 kthreadd

      If you want to sort by a specific column, you can use the sort= option. For example, to see which processes are using the most memory, I sort by the vsz field. That sorts from lowest memory use to highest. Because I want to see the highest ones first, I put a hyphen in front of that option to sort (sort=-vsz).

       $ ps -eo pid,user,group,gid,vsz,rss,comm --sort=-vsz | head PID USER GROUP GID VSZ RSS COMMAND 2366 chris chris 1000 3720060 317060 gnome-shell 1580 gdm gdm 42 3524304 205796 gnome-shell 3030 chris chris 1000 2456968 248340 firefox 3233 chris chris 1000 2314388 316252 Web Content

      Refer to the ps man page for information on other columns of information by which you can display and sort.

      Listing and changing processes with top

      The top command provides a screen-oriented means of displaying processes running on your system. With top, the default is to display processes based on how much CPU time they are currently consuming. However, you can sort by other columns as well. After you identify a misbehaving process, you can also use top to kill (completely end) or renice (reprioritize) that process.

      General information about your system appears at the top of the top output, followed by information about each running process (or at least as many as will fit on your screen). At the top, you can see how long the system has been up, how many users are currently logged in to the system, and how much demand there has been on the system for the past 1, 5, and 10 minutes.

Screenshot of the top window displaying the output of running processes and information about each process.

      The following list includes actions that you can do with top to display information in different ways and modify running processes:

       Press h to see help options, and then press any key to return to the top display.

       Press M to sort by memory usage instead of CPU, and then press P to return to sorting by CPU.

       Press the number 1 to toggle showing CPU usage of all your CPUs if you have more than one CPU on your system.

       Press R to reverse sort your output.

       Press u and enter a username to display processes only for a particular user.

      A common practice is to use top to find processes that are consuming too much memory or processing power and then act on those processes in some way. A process consuming too much CPU can be reniced to give it less priority to the processors. A process consuming too much memory can be killed. With top running, here's how to renice or kill a process:

       Renicing a process Note the process ID of the process you want to renice and press r. When the PID to renice message appears, type the process ID of the process you want to renice. When prompted to Renice PID to value, type in a number from –20 to 19. (See “Setting processor priority with nice and renice” later in this chapter for information on the meanings of different renice values.)

       Killing a process Note the process ID of the process you want to kill and press k. Type 15 to terminate cleanly or 9 to just kill the process outright. (See “Killing processes with kill and killall” later in this chapter for more information on using different signals you can send to processes.)

      Listing processes with System Monitor

      If you have GNOME desktop available on your Linux system, System Monitor (gnome-system-monitor) is available to provide a more graphical way of displaying processes on your system. You sort processes by clicking columns. You can right-click processes to stop, kill, or renice them.

Screenshot of the System Monitor window, displaying the list of running processes for the current user in order by memory use to change them.

      By default, only running processes associated with your user account are displayed. Those processes are listed alphabetically at first. You can resort the processes by clicking any of the field headings (forward and reverse). For example, click the %CPU heading to see which processes are consuming the most processing power. Click the Memory heading to see which processes consume the most memory.

      Here are some of the things you can do to a process from the menu you clicked:

       Stop: Pauses the process so that no processing occurs until you select Continue Process. (This is the same as pressing Ctrl+Z on a process from the shell.)

       Continue: Continues running a paused process.

       End: Sends a Terminate signal (15) to a process. In most cases, this terminates the process cleanly.

       Kill: Sends a Kill signal (9) to a process. This should kill a process immediately, regardless of whether it can be done cleanly.FIGURE 6.3 Renice, kill, or pause a process from the System Monitor window.

       Change Priority: Presents a list of priorities from Very Low to Very High. Select Custom to see a slider bar from which you can renice a process. Normal priority is 0. To get better processor priority, use a negative number from –1 to –20. To have a lower processor priority, use a positive number (0 to 19). Only the root user can assign negative priorities, so when prompted you need to provide the root password to set a negative nice value.

       Memory Maps: Lets you view the system memory map to see which libraries and other components are being held in memory for the process.

       Open Files: Lets you view which files are currently being held open by the process.