suse linux enterprise server administration (course 3037) chapter 6 manage linux processes and...

Post on 16-Jan-2016

237 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

SUSE Linux Enterprise Server Administration (Course 3037)

Chapter 6Manage Linux Processes and Services

SUSE Linux Enterprise Server Administration (Course 3037) 2

Objectives

• Manage Processes

• Describe Startup Shell Scripts and Services

• Schedule Jobs

• Use System Logging Services

SUSE Linux Enterprise Server Administration (Course 3037) 3

Manage Processes

• Objectives– Process Definitions– Jobs and Processes– How to Manage Foreground and Background

Processes– How to Prioritize Processes– How to End a Process– Processes and Services (Daemons)– How to Manage a Daemon Process

SUSE Linux Enterprise Server Administration (Course 3037) 4

Process Definitions

• Program– Structured set of commands stored in an executable

file• Process

– Program that is running in memory and on the CPU• User process

– Process launched by a user that runs from a terminal• Daemon process

– System process that is not associated with a terminal

SUSE Linux Enterprise Server Administration (Course 3037) 5

Process Definitions (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 6

Process Definitions (continued)

• init daemon– Launches other daemons (daemon processes)

• BASH shell– Lets user start processes manually (user processes)– Process ID

• Unique identifier assigned to every process– Child Process

• Process that is started by another process– Parent Process

• Process that starts other processes– Parent Process ID (PPID)

SUSE Linux Enterprise Server Administration (Course 3037) 7

Process Definitions (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 8

Jobs and Processes• Job identifier (job ID)

– Shell-specific numeric value that identifies the running program

– Used to refer to processes when using commands– Use job ID to switch a process from background to

foreground• Process ID

– Unique across the entire system– All jobs have a PID

• But not all processes have a usable job identifier– Use PID to change priority level of a running program

SUSE Linux Enterprise Server Administration (Course 3037) 9

How to Manage Foreground and Background Processes

• Processes executed in the foreground– Started in a terminal window– Run until the process completes– Terminal window does not return to a prompt

• Until the program’s execution is complete

• Processes executed in the background– Terminal window returns to a prompt

• Before the process finishes executing

• Processes can be switched from foreground to background

SUSE Linux Enterprise Server Administration (Course 3037) 10

How to Manage Foreground and Background Processes (continued)

• Ctrl+Z– Stops a process running in foreground

• bg– Continues running a stopped process in the

background

• Ampersand (&)– Starts the process in the background

• Command jobs– List the contents of job control

SUSE Linux Enterprise Server Administration (Course 3037) 11

How to Manage Foreground and Background Processes (continued)

• fg job_ID– Switches a process to the foreground

• Process termination status– Done– Terminated– Killed

SUSE Linux Enterprise Server Administration (Course 3037) 12

How to Prioritize Processes

• ps– Lists all running processes

• pstree– Lists processes in the form of a tree structure

• nice– Assigns a process a specific nice value

• That affects the calculation of the process priority

– Nice level is used by the scheduler• To determine how frequently to service a running

process

SUSE Linux Enterprise Server Administration (Course 3037) 13

How to Prioritize Processes (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 14

How to Prioritize Processes (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 15

How to Prioritize Processes (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 16

How to Prioritize Processes (continued)

• renice– Changes the nice value of a running process– Only root can reduce nice value of a running process

• top– Combines the functionality of commands ps and

renice– Information displayed

• Can be filtered by a specific user

• Can be sorted on any displayed field

SUSE Linux Enterprise Server Administration (Course 3037) 17

How to Prioritize Processes (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 18

How to Prioritize Processes (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 19

How to Prioritize Processes (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 20

How to End a Process

• kill and killall– Terminate a process– killall

• Kills all processes with an indicated command name

• Needs the command name of the process– kill

• Kills only the indicated process• Needs the PID of the process

– Signals handled by the kernel• SIGKILL and STOP

SUSE Linux Enterprise Server Administration (Course 3037) 21

How to End a Process (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 22

How to End a Process (continued)

• KDE System Guard– Started from KDE Desktop– Used to view and kill processes– Steps

• Select the process from the Process Table• Select Kill

SUSE Linux Enterprise Server Administration (Course 3037) 23

How to End a Process (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 24

Processes and Services (Daemons)

• Service– Also called a daemon (Disk And Execution MONitor)

– Process or collection of processes • That wait for an external event to trigger an action

• Listener– Waits for an event to occur and informs the program– Network listeners are common examples

SUSE Linux Enterprise Server Administration (Course 3037) 25

How to Manage a Daemon Process

• Daemons – Run in the background– Usually started when the system is booted– Terminal-independent processes– Usually their names terminate in “d”

• Types of daemons– Signal-controlled

• Activated when a corresponding task exists– Interval-controlled

• Activated at certain intervals

SUSE Linux Enterprise Server Administration (Course 3037) 26

How to Manage a Daemon Process (continued)

• For each daemon, there is a script in /etc/init.d/• For many scripts

– There is a symbolic link in the directory /usr/sbin/• Or in the directory /sbin/

• Some important daemons:– cron– cupsd– httpd– sshd– syslogd

SUSE Linux Enterprise Server Administration (Course 3037) 27

How to Manage a Daemon Process (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 28

Exercise 6-1: Manage Linux Processes and Services

• In this exercise, you do the following:– Part I: Move Processes in the Background– Part II: Modify Process Priorities– Part III: Enable Services– Part IV: Enable Services Using YaST

SUSE Linux Enterprise Server Administration (Course 3037) 29

Describe Startup Shell Scripts and Services

• Objectives– Startup Scripts– Startup Script Directory Structure– Startup Script Structure

SUSE Linux Enterprise Server Administration (Course 3037) 30

Startup Scripts

• Run as soon as the system is switched to a new runlevel– As long as their dependencies are met

• Scripts for network-based services – Need to run after the network script is run

• Network script is not run in runlevel 1– You cannot use network-based services scripts in

runlevel 1

SUSE Linux Enterprise Server Administration (Course 3037) 31

Startup Scripts (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 32

Startup Script Directory Structure

• Directory entries– /etc/init.d/– /etc/init.d/rcn.d/

• Link name is prefixed with S (Start) or K (Kill) – And a two-digit numeric value

• During system startup– Links with an S in front of them are accessed

• During a clean system shutdown– Scripts with a K in front of them are accessed

SUSE Linux Enterprise Server Administration (Course 3037) 33

Startup Script Directory Structure (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 34

Startup Script Structure

• /etc/init.d/skeleton file– Skeleton file for startup scripts

• Some of the most important parts include:– General Section– Start Section– Stop Section– Restart Section– Force-Reload Section– Reload Section– Status Section– Last Option (*)

SUSE Linux Enterprise Server Administration (Course 3037) 35

Startup Script Structure (continued)

• General Section– Contains commands that are executed regardless of

the parameter passed to the script• Start Section

– Parameters are evaluated using a case statement– Compares the first parameter to the value start

• Stop Section– Compares the first parameter to the value stop

• And shuts down the process by sending the SIGTERM signal

SUSE Linux Enterprise Server Administration (Course 3037) 36

Startup Script Structure (continued)

• Restart Section– Used to unconditionally restart the service

• Force-Reload Section– Commonly used to cause a service to reload its

configuration files• Reload Section

– Like the force-reload parameter

– If the service does not support the HUP signal, it does nothing

SUSE Linux Enterprise Server Administration (Course 3037) 37

Startup Script Structure (continued)

• Status Section– Used to verify the service is running

• Last Option (*)– Used for anything that has not been matched up to

this point

SUSE Linux Enterprise Server Administration (Course 3037) 38

Schedule Jobs

• Objectives– Schedule a Job (cron)– Run a Job One Time Only (at)

SUSE Linux Enterprise Server Administration (Course 3037) 39

Schedule a Job (cron)

• Service cron (/usr/sbin/cron)– Schedules jobs to be carried out on a regular basis

– Runs as a daemon – Checks once a minute for scheduled jobs

• crontab– File that contains the list of jobs

• Types of jobs– System Jobs– User Jobs

SUSE Linux Enterprise Server Administration (Course 3037) 40

Schedule a Job (cron) (continued)

• System jobs– Control system jobs with the file /etc/crontab– /var/spool/cron/lastrun/ directory

• Contains files with information about the last time jobs were run

– Script /usr/lib/cron/run-crons• Evaluates script time stamp• Determines if scripts have to be run or not

– Scripts in /etc/cron.daily/• Standard shell scripts• Overwritten when you update your system

SUSE Linux Enterprise Server Administration (Course 3037) 41

Schedule a Job (cron) (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 42

Schedule a Job (cron) (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 43

Schedule a Job (cron) (continued)

• User jobs– Configure user cron jobs with the following files:

• /var/spool/cron/allow• /var/spool/cron/deny

– Stored in the directory /var/spool/cron/tabs/• In files matching the user names• Use crontab to edit them• Each line in a file defines a job

– There are six fields in a line– Sixth field contains the command to run

SUSE Linux Enterprise Server Administration (Course 3037) 44

Schedule a Job (cron) (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 45

Schedule a Job (cron) (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 46

Run a Job One Time Only (at)

• Use command at

• Configuration files– /etc/at.allow– /etc/at.deny

• at command syntax– at launch_time (interactive version)– at –f file launch_time

SUSE Linux Enterprise Server Administration (Course 3037) 47

Run a Job One Time Only (at) (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 48

Exercise 6-2 Schedule Jobs With cron and at

• In this exercise, you do the following:– Part I: Schedule Jobs with at– Part II: Schedule Jobs with cron

SUSE Linux Enterprise Server Administration (Course 3037) 49

Use System Logging Services

• Objectives– The syslog Daemon– Important Log Files– How to View Log Files with YaST– How to Archive Log Files (logrotate)– How to Monitor Hard Drive Space

SUSE Linux Enterprise Server Administration (Course 3037) 50

The syslog Daemon

• The syslog daemon (syslogd)– Used by many services to log system events

• Configuration file– /etc/syslog.conf– Contains one rule per line– Each rule has two fields separated by spaces or tabs– Components

• Categories• Priorities• Second Field Options• Additional Priority Parameters

SUSE Linux Enterprise Server Administration (Course 3037) 51

The syslog Daemon (continued)

• Categories– Refer to the subsystem that provides the corresponding

message

• Priorities– Give details about the urgency of the message

• Second Field Options– Determine what will be done with the corresponding

message– Options

• Output of a file• Specifying the device file for a text console

SUSE Linux Enterprise Server Administration (Course 3037) 52

The syslog Daemon (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 53

The syslog Daemon (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 54

The syslog Daemon (continued)• Second Field Options

– Options• Specifying a FIFO file• Specifying a user list• Specifying a computer name with a prefixed @• Using an asterisk (*)

• Additional Priority Parameters– An equal sign (=) before the priority– An exclamation mark (!) before the priority– Add an asterisk (*)– Set none as the priority

SUSE Linux Enterprise Server Administration (Course 3037) 55

Important Log Files

• /var/log/messages– Most commonly used log file– -- MARK -- is written by syslog daemon every 20

minutes• If no other messages to log exist

• Command tail– Used to read log file– Exit using Ctrl+C

SUSE Linux Enterprise Server Administration (Course 3037) 56

Important Log Files (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 57

Important Log Files (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 58

How to View Log Files with YaST

• Steps– Start YaST View Start-up Log or View System Log

module– Select a log to view from the drop-down list– Close the dialog by selecting OK

SUSE Linux Enterprise Server Administration (Course 3037) 59

How to View Log Files with YaST (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 60

How to Archive Log Files (logrotate)

• Ensure log files do not get too large or too complex• logrotate program

– Monitors the size and age of log files– Run daily by the cron daemon

• /etc/cron.daily/logrotate

• /etc/logrotate.conf– Configuration file of logrotate

• RPM packages contain preconfigured files for evaluation by logrotate– Stored in /etc/logrotate.d/

SUSE Linux Enterprise Server Administration (Course 3037) 61

How to Archive Log Files (logrotate) (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 62

How to Archive Log Files (logrotate) (continued)

• Settings in logrotate.d supersede settings in logrotate.conf

• syslogd– Configure how log files written by syslog will be

treated

SUSE Linux Enterprise Server Administration (Course 3037) 63

How to Archive Log Files (logrotate) (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 64

How to Monitor Hard Drive Space

• Command /bin/df (disk free)– Shows how much space is occupied and available

• Command /usr/bin/du (disk usage)– Shows how large individual files or directories are

• Info Center (Storage Devices) or KDiskFree– Utilities from the KDE desktop– Provide a high-level view of disk space usage

• Tree View or Detailed List View in Konqueror– Monitor disk space usage by directory or file– Show only individual directory and file sizes

SUSE Linux Enterprise Server Administration (Course 3037) 65

How to Monitor Hard Drive Space (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 66

How to Monitor Hard Drive Space (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 67

How to Monitor Hard Drive Space (continued)

SUSE Linux Enterprise Server Administration (Course 3037) 68

Exercise 6-3 Manage System Logging

• In this exercise, you do the following:– Part I: Modify the Syslog Configuration– Part II: Configure Logrotate

SUSE Linux Enterprise Server Administration (Course 3037) 69

Summary

• Processes are programs that are executing on the system– Every process has a PID and a PPID– Can possibly start an unlimited number of child

processes

• init daemon– First process loaded by the kernel during system

initialization

• Background processes have a job ID– Commands: job, bg, fg

SUSE Linux Enterprise Server Administration (Course 3037) 70

Summary (continued)

• View processes using– KDE System Guard– Commands ps, pstree, and top

• Stop processes using– KDE System Guard– Commands kill, killall, and top

• Command nice– Changes process priority

• Daemon process names typically end with d– Start it with appropriate script in the /etc/init.d directory

SUSE Linux Enterprise Server Administration (Course 3037) 71

Summary (continued)

• init daemon– Loads daemons during system startup

• Commands may be scheduled to run at a later time– Using at daemon

• cron daemon– Used to schedule tasks to occur regularly in the future

• Most log files are stored in the /var/log directory– And created by the syslog daemon– logrotate program is run daily to archive log files

• Monitor disk usage with df, du, and KDE utilities

top related