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

advertisement
Chapter 10
Managing System
Resources
Guide to Linux Installation and Administration, 2e
1
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
Guide to Linux Installation and Administration, 2e
2
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
3
Viewing Device Information
Guide to Linux Installation and Administration, 2e
4
System Information in the
KDE Control Center
Guide to Linux Installation and Administration, 2e
5
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
6
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
7
Ps Options Used to Select Processes
Guide to Linux Installation and Administration, 2e
8
Process Information Fields Available
from ps
Guide to Linux Installation and Administration, 2e
9
Process Information Fields Available
from ps (continued)
Guide to Linux Installation and Administration, 2e
10
Combination Process Information
Fields Available from ps
Guide to Linux Installation and Administration, 2e
11
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
12
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
13
Interactive Commands in top
Guide to Linux Installation and Administration, 2e
14
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
15
The KDE System Guard Utility
Guide to Linux Installation and Administration, 2e
16
The Gnome System Monitor Utility
Guide to Linux Installation and Administration, 2e
17
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
18
A CPU Load Monitor
Guide to Linux Installation and Administration, 2e
19
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
20
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
21
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
22
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
23
Memory Usage
Guide to Linux Installation and Administration, 2e
24
The Preferences Dialog Box in the
Gnome System Monitor
Guide to Linux Installation and Administration, 2e
25
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
26
Graphical Memory Map Tab for a
Single Process
Guide to Linux Installation and Administration, 2e
27
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
28
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
29
Valued Gateway
Client:
Identifying and Removing Bottlenecks
• Use various utilities
• Test many programs
• Review performance measurements and
system status
Guide to Linux Installation and Administration, 2e
30
Valued Gateway
Client:
Using Benchmarks
• To identify bottlenecks a benchmark program can
be used
• Benchmarks provide a numeric measurement of
one aspect of system performance
Guide to Linux Installation and Administration, 2e
31
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
32
Commonly Logged Events and Their
Log Files
Guide to Linux Installation and Administration, 2e
33
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
34
How syslogd and klogd Work together
to Process Log Messages
Guide to Linux Installation and Administration, 2e
35
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
36
The Facilities
Guide to Linux Installation and Administration, 2e
37
The Priorities
Guide to Linux Installation and Administration, 2e
38
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
39
Configuration File Syntax
Guide to Linux Installation and Administration, 2e
40
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
41
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
42
Interpreting Sample Log File Entries
Guide to Linux Installation and Administration, 2e
43
Valued Gateway
Client:
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
Guide to Linux Installation and Administration, 2e
44
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
Guide to Linux Installation and Administration, 2e
45
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
Guide to Linux Installation and Administration, 2e
46
Download