Title: SUSE Linux Enterprise Server Administration Course 3037
1SUSE Linux Enterprise Server Administration
(Course 3037)
- Chapter 6
- Manage Linux Processes and Services
2Objectives
- Manage Processes
- Describe Startup Shell Scripts and Services
- Schedule Jobs
- Use System Logging Services
3Manage 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
4Process 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
5Process Definitions (continued)
6Process 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)
7Process Definitions (continued)
8Jobs 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
9How 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 programs 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
10How to Manage Foreground and Background Processes
(continued)
- CtrlZ
- 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
11How to Manage Foreground and Background Processes
(continued)
- fg job_ID
- Switches a process to the foreground
- Process termination status
- Done
- Terminated
- Killed
12How 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
13How to Prioritize Processes (continued)
14How to Prioritize Processes (continued)
15How to Prioritize Processes (continued)
16How 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
17How to Prioritize Processes (continued)
18How to Prioritize Processes (continued)
19How to Prioritize Processes (continued)
20How 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
21How to End a Process (continued)
22How 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
23How to End a Process (continued)
24Processes 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
25How 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
26How 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
27How to Manage a Daemon Process (continued)
28Exercise 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
29Describe Startup Shell Scripts and Services
- Objectives
- Startup Scripts
- Startup Script Directory Structure
- Startup Script Structure
30Startup 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
31Startup Scripts (continued)
32Startup 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
33Startup Script Directory Structure (continued)
34Startup 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 ()
35Startup 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
36Startup 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
37Startup 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
38Schedule Jobs
- Objectives
- Schedule a Job (cron)
- Run a Job One Time Only (at)
39Schedule 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
40Schedule 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
41Schedule a Job (cron) (continued)
42Schedule a Job (cron) (continued)
43Schedule 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
44Schedule a Job (cron) (continued)
45Schedule a Job (cron) (continued)
46Run 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
47Run a Job One Time Only (at) (continued)
48Exercise 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
49Use 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
50The 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
51The 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
52The syslog Daemon (continued)
53The syslog Daemon (continued)
54The syslog Daemon (continued)
- Second Field Options
- Options
- Specifying a FIFO file
- Specifying a user list
- Specifying a computer name with a prefixed _at_
- 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
55Important 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 CtrlC
56Important Log Files (continued)
57Important Log Files (continued)
58How 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
59How to View Log Files with YaST (continued)
60How 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/
61How to Archive Log Files (logrotate) (continued)
62How 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
63How to Archive Log Files (logrotate) (continued)
64How 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
65How to Monitor Hard Drive Space (continued)
66How to Monitor Hard Drive Space (continued)
67How to Monitor Hard Drive Space (continued)
68Exercise 6-3 Manage System Logging
- In this exercise, you do the following
- Part I Modify the Syslog Configuration
- Part II Configure Logrotate
69Summary
- 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
70Summary (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
71Summary (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