SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and...

71
SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services

Transcript of SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and...

Page 1: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037)

Chapter 6Manage Linux Processes and Services

Page 2: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage 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

Page 3: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and 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

Page 4: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 5: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 5

Process Definitions (continued)

Page 6: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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)

Page 7: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 7

Process Definitions (continued)

Page 8: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 9: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 10: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 11: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 12: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 13: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 13

How to Prioritize Processes (continued)

Page 14: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 14

How to Prioritize Processes (continued)

Page 15: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 15

How to Prioritize Processes (continued)

Page 16: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 17: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 17

How to Prioritize Processes (continued)

Page 18: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 18

How to Prioritize Processes (continued)

Page 19: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 19

How to Prioritize Processes (continued)

Page 20: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 21: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 21

How to End a Process (continued)

Page 22: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 23: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 23

How to End a Process (continued)

Page 24: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 25: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 26: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 27: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 27

How to Manage a Daemon Process (continued)

Page 28: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 29: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 29

Describe Startup Shell Scripts and Services

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

Page 30: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 31: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 31

Startup Scripts (continued)

Page 32: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 33: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 33

Startup Script Directory Structure (continued)

Page 34: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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 (*)

Page 35: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 36: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 37: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 38: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 38

Schedule Jobs

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

Page 39: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 40: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 41: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 41

Schedule a Job (cron) (continued)

Page 42: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 42

Schedule a Job (cron) (continued)

Page 43: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 44: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 44

Schedule a Job (cron) (continued)

Page 45: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 45

Schedule a Job (cron) (continued)

Page 46: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 47: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 47

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

Page 48: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 49: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 50: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 51: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 52: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 52

The syslog Daemon (continued)

Page 53: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 53

The syslog Daemon (continued)

Page 54: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 55: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 56: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 56

Important Log Files (continued)

Page 57: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 57

Important Log Files (continued)

Page 58: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 59: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 59

How to View Log Files with YaST (continued)

Page 60: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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/

Page 61: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 61

How to Archive Log Files (logrotate) (continued)

Page 62: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 63: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 63

How to Archive Log Files (logrotate) (continued)

Page 64: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 65: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 65

How to Monitor Hard Drive Space (continued)

Page 66: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 66

How to Monitor Hard Drive Space (continued)

Page 67: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

SUSE Linux Enterprise Server Administration (Course 3037) 67

How to Monitor Hard Drive Space (continued)

Page 68: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 69: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 70: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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

Page 71: SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.

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