Linux Guide to Linux Certification, Third Edition - PowerPoint PPT Presentation

1 / 42
About This Presentation
Title:

Linux Guide to Linux Certification, Third Edition

Description:

Title: Linux+ Guide to Linux Certification Subject: Chapter Eleven Author: anat Last modified by: Rita Created Date: 9/27/2002 11:29:22 PM Document presentation format – PowerPoint PPT presentation

Number of Views:139
Avg rating:3.0/5.0
Slides: 43
Provided by: Anat49
Category:

less

Transcript and Presenter's Notes

Title: Linux Guide to Linux Certification, Third Edition


1
Linux Guide to Linux Certification, Third Edition
  • Chapter 9
  • Managing Linux Processes

2
Objectives
  • Categorize the different types of processes on a
    Linux system
  • View processes using standard Linux utilities
  • Explain the difference between common kill
    signals
  • Describe how binary programs and shell scripts
    are executed

3
Objectives (continued)
  • Create and manipulate background processes
  • Use standard Linux utilities to modify the
    priority of a process
  • Schedule commands to execute in the future using
    the at daemon
  • Schedule commands to execute repetitively using
    the cron daemon

4
Linux Processes
  • Program structured set of commands stored in an
    executable file
  • Executed to create a process
  • Process program running in memory and on CPU
  • User process process begun by user on a terminal
  • Daemon process system process
  • Not associated with a terminal

5
Linux Processes (continued)
  • Process ID (PID) unique identifier assigned to a
    process
  • Child process process started by another process
    (parent process)
  • Parent process process that has started other
    processes (child processes)
  • Parent Process ID (PPID) PID of the parent
    process
  • The init daemon has a PID of 1 and a PPID of 0

6
Linux Processes (continued)
Figure 9-1 Parent and child processes
7
Linux Processes (continued)
Figure 9-2 Process genealogy
8
Viewing Processes
  • ps command view processes
  • Most versatile and common process viewing utility
  • No arguments lists all processes running in
    current shell
  • PID, terminal, command that started process, CPU
    time
  • f (full) option more complete information
  • User identifier (UID), PPID, start time, CPU
    utilization
  • -e option displays the entire list of processes
    across all terminals including daemons

9
Viewing Processes (continued)
  • Process flag indicates particular features of
    the process
  • Process state current processor state of process
  • Most processes sleeping (S) or running (R)
  • Zombie process process finished, but parent has
    not released child processs PID
  • Defunct process
  • Process state is Z

10
Viewing Processes (continued)
  • Process priority (PRI) priority used by the
    kernel for the process
  • Higher value means lower priority
  • Nice value (NI) can be used to affect the
    process priority indirectly
  • Higher value means a greater chance of low
    priority
  • pstree command displays the lineage of a process
    by tracing its PPIDs until the init daemon

11
Viewing Processes (continued)
Table 9-1 Common options to the ps command
12
Viewing Processes (continued)
  • top command displays interactive screen listing
    processes
  • Organized by processor time
  • Processes using most processor time listed first
  • Rogue process faulty process
  • Consumes excessive system resources
  • top command can be used to change PRI or kill
    processes
  • Rogue processes can be killed immediately when
    identified

13
Killing Processes
  • kill command sends a kill signal to a process
    to terminate it
  • 64 types of kill signals
  • Affect processes in different ways
  • -l option displays list of kill signal names and
    associated numbers
  • To kill a process, give kill signal and PID
  • If no kill signal given, the default kill signal,
    SIGTERM, is used

14
Killing Processes (continued)
Table 9-2 Common administrative kill signals
15
Killing Processes (continued)
  • Trapping ignoring a kill signal
  • The SIGKILL signal cannot be trapped by any
    process
  • Use only as last resort
  • When parent process receives a kill signal,
    parent process terminates all child processes
    before terminating itself
  • To kill several related processes send signal to
    parent process
  • Kill parent process in order to kill zombie
    processes

16
Killing Processes (continued)
  • killall command kills multiple processes of the
    same name in one command
  • Takes kill signal number as an option
  • Uses process name instead of PID
  • If no kill signal given, the default kill signal,
    SIGTERM, is used
  • Can use top command to kill processes

17
Process Execution
  • Three main types of executable commands
  • Binary programs
  • e.g., ls, find, grep
  • Shell scripts
  • Shell functions
  • e.g., cd, exit

18
Process Execution (continued)
  • Forking act of creating new BASH shell or
    subshell
  • Carried out by fork function in BASH shell
  • Subshell executes program or shell script using
    exec function
  • Original shell waits for subshell to complete
  • When done, subshell kills itself
  • Control returns to original shell

19
Process Execution (continued)
Figure 9-3 Process forking
20
Running Processes in the Background
  • Foreground processes BASH shell must wait for
    termination to display prompt and accept new
    commands
  • Background processes BASH shell does not wait
    for termination
  • Append metacharacter to command
  • Upon execution, user receives BASH shell prompt
    immediately

21
Running Processes in the Background (continued)
  • jobs command lists background job IDs for
    processes running in current shell
  • To terminate background process
  • Send kill signal to PID
  • Send kill signal to background job ID
  • Prefix job ID with character

22
Running Processes in the Background (continued)
  • foreground (fg) command move a background
    process to the foreground
  • Use Ctrlz to pause a foreground process
  • Assigns the process a background job ID
  • background (bg) command send an existing process
    to the background
  • Provide background job ID as argument
  • jobs command indicates the two most recent
    background processes
  • By default, commands apply to most recent process

23
Process Priorities
  • Time slice amount of time a process is given on
    a CPU
  • More time slices mean more execution time on CPU
  • Executes faster
  • Usually measured in milliseconds

24
Process Priorities (continued)
  • PRI dictates number of time slices a process gets
  • Low PRI is likely to get more time slices than
    high PRI
  • Cannot change PRI value directly
  • Set NI to indirectly affect priority
  • Negative NI value, more time slices positive NI
    value, less time slices
  • Processes start with NI of 0
  • nice command change a processs priority as it
    starts

25
Process Priorities (continued)
Figure 9-4 The nice value scale
26
Process Priorities (continued)
  • renice command alter NI of a process after it
    has been started
  • Only root user may change NI to a negative value
  • -u option change the NI for all processes owned
    by the specified user or group
  • May also change NI of running processes using top
    utility

27
Scheduling Commands
  • To schedule commands to execute in the future
  • at daemon (atd) system daemon that executes
    tasks at a future time
  • cron daemon (crond) system daemon that executes
    tasks repetitively in the future

28
Scheduling Commands with atd
  • at command schedule commands and tasks to run at
    a preset time
  • Specify the time as an argument
  • l option view a list of at job IDs (regular
    users see only their own jobs)
  • atq command alias to at -l
  • c option view content of a specified at job
  • d option delete the specified at job
  • f option list commands to be scheduled by at
    from a shell script

29
Scheduling Commands with atd (continued)
Table 9-3 Common at commands
30
Scheduling Commands with atd (continued)
  • at daemon uses current shells environment for
    execution
  • Shell environment and scheduled commands stored
    in /var/spool/at
  • If stdout of scheduled command has not been
    redirected to a file, it is mailed to user

31
Scheduling Commands with atd (continued)
  • /etc/at.allow file listing all users allowed to
    use the at daemon
  • /etc/at.deny file listing all the users not
    allowed to use the at daemon
  • If both files exist, only /etc/at.allow file is
    processed
  • On Fedora Linux systems, only /etc/at.deny file
    exists by default
  • Initially left blank, all users allowed to use at
    daemon

32
Scheduling Commands with crond
  • Suitable for scheduling repetitive tasks
  • Cron tables configuration files specifying when
    commands should be executed
  • Six fields separated by space or tab characters
  • First five specify times to run the command
  • Sixth absolute pathname to command to be executed

33
Scheduling Commands with crond (continued)
  • User cron tables represent tasks scheduled by
    individual users
  • System cron tables contains system tasks
  • /var/spool/cron stores user cron tables
  • /etc/crontab file contains system cron tables
  • /etc/cron.d directory contains system cron
    tables

34
Scheduling Commands with crond (continued)
Figure 9-5 User cron table format
35
Scheduling Commands with crond (continued)
Figure 9-6 Sample user cron table entry
36
User Cron Tables
  • /etc/cron.allow lists users allowed to use the
    cron daemon
  • /etc/cron.deny lists users not allowed to use
    the cron daemon
  • If both files exist, only /etc/cron.allow file is
    processed
  • On Fedora Linux systems, only /etc/cron.deny file
    exists by default
  • Initially left blank, all users allowed to use
    cron daemon

37
User Cron Tables (continued)
  • crontab command view and edit user cron tables
  • e option edit cron tables in vi editor
  • l option list a user cron table
  • r option remove cron table and all scheduled
    jobs
  • -u option used by root user to edit, list, or
    remove a specified users cron table

38
The System Cron Table
  • System maintenance, backups, and CPU-intensive
    tasks often scheduled for non-business hours
  • Often scheduled by cron daemon
  • Entries in system cron table (/etc/crontab)

39
The System Cron Table (continued)
  • Initial section of cron table specifies execution
    environment
  • Remainder similar to user cron table entries
  • Cron tables located in the /etc/cron.d directory
    are run by the system as a specified user
  • Can schedule administrative task by placing a
    shell script in the appropriate one of the
    following directories /etc/cron.hourly/,
    /etc/cron.daily/, /etc/cron.weekly, and
    etc/cron.monthly/

40
Summary
  • Processes are programs that are executing on the
    system
  • User processes are run in the same terminal as
    the user who executed them, whereas daemon
    processes are system processes that do not run on
    a terminal
  • Every process has a parent process associated
    with it and, optionally, several child processes

41
Summary (continued)
  • Process information is stored in the /proc
    filesystem the ps, pstree and top commands can
    be used to view this information
  • Zombie and rogue processes that exist for long
    periods of time use up system resources and
    should be killed to improve system performance
  • You can send kill signals to a process using the
    kill, killall, and top commands

42
Summary (continued)
  • The BASH shell creates, or forks, a subshell to
    execute most commands
  • Processes can be run in the background by
    appending an to the command name
  • The priority of a process can be affected
    indirectly by altering its nice value
  • Commands can be scheduled to run at a later time
    using the at and cron daemons
Write a Comment
User Comments (0)
About PowerShow.com