46
Guide to Linux Installation and Administration, 2e 1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Embed Size (px)

Citation preview

Page 1: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

1

Chapter 10

Managing System Resources

Page 2: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

2

Objectives

In this chapter, you will:

• Access the /proc file system to manage system status

• Control how processes use system resources

• Track physical and virtual memory usage

• Locate and relieve system bottlenecks

• Manage system logs

Page 3: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

3

Viewing System Status in /proc

• The /proc file system is a specialized file system that lets you view and control system resources such as processes, memory, and kernel networking parameters

• When you query a filename in /proc, the Linux kernel responds with live information about the status of a process, memory, or other resource

Page 4: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

4

Viewing Device Information

Page 5: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

5

System Information in the KDE Control Center

Page 6: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

6

Viewing Process Information

• The /proc file system contains detailed information about each process running on Linux

• Before you can access information in /proc regarding a specific process, you need to find the process’s PID number

• To find the PID for a running process, use the ps command

Page 7: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

7

Managing Processes

• To manage your system effectively, you will often need to display detailed information about specific processes

• The ps command has many options to select processes to be included in the command output

• You can select what information is displayed about each process

Page 8: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

8

Ps Options Used to Select Processes

Page 9: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

9

Combination Process Information Fields Available from ps

Page 10: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

10

Process Information Fields Available from ps

Page 11: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

11

Process Information Fields Available from ps (continued)

Page 12: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

12

Changing Process Priorities

• Each process in Linux is assigned a priority, called a nice level

• The root user can change the priority of any process; other users can raise the nice level of processes they have started

• The nice and renice commands set a process’s nice level; other command-line and graphical programs also let you change a process’s nice level

Page 13: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

13

Viewing Processor Usage with top

• The top command lists processes according to how much CPU time they are using

• The output of top is updated every few seconds• The top command can also be used to control

processes by sending them signals

Page 14: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

14

Interactive Commands in top

Page 15: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

15

Using Graphical Process Managing Tools

• KDE System Guard and the Gnome System Monitor are two powerful graphical process management utilities

• Graphical process managing tools display many fields of information about each process and can be used to send signals to a process

Page 16: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

16

The KDE System Guard Utility

Page 17: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

17

The Gnome System Monitor Utility

Page 18: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

18

Actively Monitoring the CPU Load

• You can display a small CPU load monitor on the Panel of your desktop to keep an eye on system load

• When the CPU load is consistently high, you can begin checking for processes that may need attention

Page 19: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

19

A CPU Load Monitor

Page 20: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

20

Managing Memory

• The Gnome System Monitor provides memory management features

• You can manage physical memory (RAM) and virtual memory

• The Linux kernel and Linux programs can only interact with information stored in RAM

Page 21: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

21

Understanding Shared Libraries

• Shared libraries let many Linux programs access the same programming functionality without loading it into memory multiple times

• Dynamically linked applications use shared libraries

• Statically linked applications have a copy of the programming libraries they need built into the application itself

Page 22: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

22

Understanding Paged Memory

• A page of memory is a block of 4 KB of RAM

• The Linux kernel moves data to and from swap space in pages

Page 23: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

23

Tracking Memory Usage

• The free command displays information about RAM and virtual memory usage

• All the information displayed by free is in kilobytes

• A buffer is memory used by an application for data storage

Page 24: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

24

Memory Usage

Page 25: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

25

The Preferences Dialog Box in the Gnome System Monitor

Page 26: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

26

Tracking Per-Application Memory Use

• You can use the Gnome System Monitor to view how a single process is using memory

• Right-click on any process and choose Memory Maps from the pop-up menu

Page 27: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

27

Graphical Memory Map Tab for a Single Process

Page 28: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

28

Viewing Virtual Memory Information

• You can use the vmstat command to view detailed information about how swap space is used

• When vmstat is run as a regular command, its output is based on information averaged over time since the system was booted

Page 29: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

29

Locating System Bottlenecks

• A bottleneck is the part of a computer system that significantly slows down completion of the task at hand

• Bottlenecks reduce system performance when one component, such as a slow network connection or disk drive, can’t keep up with the rest of the system

Page 30: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

30

Identifying and Removing Bottlenecks

• Use various utilities• Test many programs• Review performance measurements and

system status

Page 31: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

31

Using Benchmarks

• To identify bottlenecks a benchmark program can be used

• Benchmarks provide a numeric measurement of one aspect of system performance

Page 32: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

32

Managing System Logs

• Log files record the activities of Linux programs

• The main system log used by the kernel and many daemons is /var/log/messages

• A message is a description of what is happening within a program

Page 33: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

33

Commonly Logged Events and Their Log Files

Page 34: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

34

The syslogd and klogd Daemons

• Any program running on Linux can call the shared programming function syslog and pass it a message

• syslogd watches for messages submitted by programs

• The klogd daemon (kernel logging daemon) watches for messages submitted by the Linux kernel

Page 35: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

35

How syslogd and klogd Work together to Process Log Messages

Page 36: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

36

Configuring the System Log

• Both syslogd and klogd rely on a single configuration file: /etc/syslog.conf

• Each line in syslog.conf defines a set of messages and what action to take with those messages

• Messages are defined using a selector, which is made up of a facility and a priority

• The facility defines the type of program that generated the message

• The priority defines the severity or type of message

Page 37: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

37

The Facilities

Page 38: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

38

The Priorities

Page 39: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

39

The Actions

• Once you set up a selector (consisting of a facility and a priority), you can assign an action to that selector

• The action determines what syslogd and klogd do with the messages defined by the selector

Page 40: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

40

Configuration File Syntax

Page 41: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

41

Using the logger Utility

• The logger utility lets you send a message to the system logging daemon

• You can use the logger utility from a command line or from a script

• You can specify selectors with the logger command

Page 42: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

42

Analyzing Log Files

• Log files contain a valuable record of what has occurred on your Linux system

• A system administrator should regularly check log files for indications of trouble

• You can use standard Linux tools like grep to search for information in the log files

Page 43: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

43

Interpreting Sample Log File Entries

Page 44: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

44

Rotating Log Files

• A common log rotation system stores log files for a month, with a separate archive file for each week

• Red Hat Linux provides a utility called logrotate to manage many types of log files

• The configuration file /etc/logrotate.conf defines how log files are rotated

Page 45: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

45

Summary

• The /proc file system lets you view details about the kernel, running processes, and other system information

• You can view process information using /proc or using the ps and top commands

• Each process in Linux is assigned a priority, called a nice level

• The nice and renice commands set a process’s nice level

• KDE System Guard and the Gnome System Monitor display information about each process and can be used to send signals to a process

Page 46: Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources

Guide to Linux Installation and Administration, 2e

46

Summary

• The Linux kernel moves data to and from swap space in pages—4 KB pieces

• The free and vmstat commands display information about RAM and virtual memory usage

• Bottlenecks reduce system performance, but benchmarks can help identify bottlenecks

• System and kernel messages are logged by the syslogd and klogd daemons using the configuration in /etc/syslog.conf

• Log files must be maintained by rotating them using the logrotate command