Managing Processes - PowerPoint PPT Presentation

1 / 48
About This Presentation
Title:

Managing Processes

Description:

Allocated to each process by kernel ... Type ampersand (&) after name of command. Shell forks new process without pausing itself ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 49
Provided by: pbcc
Category:

less

Transcript and Presenter's Notes

Title: Managing Processes


1
Managing Processes
  • Chapter Six

2
The Linux Multitasking Model
  • Process
  • Program running on system
  • Started from
  • Command line
  • Graphical desktop
  • Kernel itself
  • Another process
  • Kernel maintains information about processes

3
The Linux Multitasking Model (continued)
  • Linux is multitasking operating system
  • Single microprocessor can really only perform one
    task at a time
  • Time slice
  • A few microseconds
  • Allocated to each process by kernel
  • Common to all operating systems that dont have
    multiple microprocessors

4
Creating Processes
  • Kernel starts process called init
  • When Linux first started
  • Every process running on Linux is descendant of
    init process
  • Process id (PID)
  • Unique number identifying process within Linux
    kernel
  • init PID 1

5
Creating Processes (continued)
  • Fork
  • Create new process in Linux
  • Exit
  • When process ends
  • Information about process that kernel was
    maintaining discarded
  • Resources that kernel had allocated to process
    released

6
Process States
  • Running on run queue
  • Sleeping waiting for a resource (e.g., CPU)
  • Stopped (stopped from terminal, waiting on a
    pipe, completion of I/O)
  • Zombie (child process whose parent did not free)

7
Starting Processes from the Shell
  • When you start program
  • Program takes control of command line
  • Parent process pauses to wait for new process to
    finish
  • Type ampersand () after name of command
  • Shell forks new process without pausing itself
  • Called placing process in background
  • Can start another command immediately

8
Starting Processes from the Shell (continued)
  • Job
  • Process associated with shell
  • jobs command
  • Lists all jobs or processes running as
    descendants of current shell
  • Also called child processes
  • CtrlZ key combination
  • Suspend job that shell is running

9
Starting Processes from the Shell (continued)
  • CtrlZ stop program (suspended)
  • bg command
  • Run suspended program in background
  • fg command
  • Place suspended job in foreground
  • Must specify
  • Job number using
  • Or PID

10
Starting Processes from the Shell (continued)
  • Virtual console
  • One type of login screen
  • Start multiple text-based login sessions on same
    computer
  • Assigned to function keys, typically F1 through
    F6
  • Logged in using text-mode console instead of
    graphical login screen
  • Start working in first virtual console
  • AltF2
  • Access second virtual console

11
Learning about Processes via the Command Line
  • ps command
  • Lists processes currently running on system
  • Output
  • PID
  • Terminal that process is using for output
  • CPU time that process has used so far
  • Command that started process
  • a and x options show
  • Processes started by all users
  • Processes started by system at boot time
  • Other processes that have no controlling terminal

12
Learning about Processes via the Command Line
(continued)
  • Daemon
  • Background process
  • Doesnt have any screen output but waits for
    certain system activity then acts on it
  • ps command
  • u option shows how each process is using system
  • f option
  • Displays relationship between different processes
  • Shows which processes start other processes
  • Processes presented in tree diagram

13
Learning about Processes via the Command Line
(continued)
  • Administrators track how processes consume system
    resources, particularly
  • CPU time
  • Memory
  • CPU field
  • Compares amount of CPU time used by process with
    total time elapsed since previous computation of
    CPU field
  • Form of percentage

14
Learning about Processes via the Command Line
(continued)
  • CPU field
  • Does not show average amount of CPU time used by
    process since it was started
  • WCPU field
  • Weighted to show 30-second average of percentage
    of CPU time used by process
  • Helpful for showing overall usage pattern

15
Learning about Processes via the Command Line
(continued)
  • TIME field
  • Provides cumulative measure of amount of CPU time
    consumed by process
  • /proc file system
  • Collection of information about Linux kernel
  • Accessed as if it were data files stored in
    subdirectories of /proc
  • Need PID to access information
  • Accessed using /proc/PID

16
Learning about Processes via the Command Line
(continued)
  • top utility
  • Displays list of running processes
  • Arranged by how much CPU time each is using
  • Process consuming greatest amount of CPU time
    shown at top of list
  • Updated regularly
  • Normally started without any options
  • Cannot run in background
  • k kill process
  • r renice
  • q - quit

17
Learning about Processes via the Command Line
(continued)
18
Controlling Processes
  • kill command
  • Controls any process
  • Sends signals to processes
  • -l option views all signals
  • Examples
  • kill -9 1482
  • kill -SIGTERM 1482

19
Controlling Processes (continued)
  • Signals
  • Messages sent between processes
  • About 30 different signals available
  • Has name and number associated with it
  • Software developer decides to which signals
    program responds
  • SIGTERM (15) signal
  • Requests that program end
  • Almost all programs respond
  • Software terminate

20
Controlling Processes (continued)
  • SIGHUP(1) signal
  • Restarts process with the same PID
  • Can occur when editing a daemons configuration
    file
  • SIGINT(2)
  • Weak kill signal
  • Same as CtrlC

21
Controlling Processes (continued)
  • SIGKILL(9) signal
  • Handled by Linux kernel
  • Shuts down indicated process
  • Unsaved data in program lost
  • Rouge programs virtually never crash Linux kernel
  • Use kill -9 3535 or kill SIGKILL 3535
  • PID 3535

22
Controlling Processes (continued)
  • killall command
  • Sends signal to all processes started by given
    command
  • Useful when program makes copies of itself faster
    than you can locate PIDs and use kill to shut
    them down
  • killall gedit
  • Each process assigned priority determines how
    much CPU time granted to process
  • Normally all processes have same priority

23
Controlling Processes (continued)
  • Nice level
  • Another name for process priority
  • Standard level is 0
  • Highest level 20
  • System administrator can make any process more or
    less nice
  • User can raise nice level of process that he or
    she started and lower priority

24
Controlling Processes (continued)
  • Alter process priority
  • nice command
  • nice analyze -5
  • renice command
  • renice 10 1776
  • 0 normal priority
  • 19 lower priority
  • -20 higher priority
  • More chance at slices of time.
  • Can issue nice and renice while top running

25
Controlling Processes (continued)
26
Using Graphical Process Management Tools
  • Gkrellm
  • View system status information on desktop
    continuously
  • KDE System Guard utility
  • Graphically displays process list
  • Interact with list to rearrange or kill processes
  • GNOME System Monitor
  • Manage processes graphically

27
Using Graphical Process Management Tools
(continued)
  • Manage Linux system effectively
  • Keep CPU load monitor visible on Panel
  • Check for processes that might need attention
  • Reduce CPU load
  • Raise nice level of numerous user processes
  • Are not all competing at same level
  • Add second microprocessor
  • Move some tasks to different computer
  • Add memory

28
Understanding Shared Libraries
  • Library
  • Contains prewritten functionality that any
    program can use
  • Statically linked applications
  • Include library functions in main program
  • Dynamically linked applications
  • Assume that needed library files are available on
    Linux system
  • Use shared libraries
  • Location /lib or /usr/lib
  • ldd command
  • Lists all libraries that program requires
  • ldconfig
  • Add library

29
Memory
  • Physical memory (RAM)
  • cat /proc/meminfo
  • Virtual memory (swap space)
  • More RAM always leads to better performance on
    busy system

30
Swap Space
  • Used when system runs out of RAM for currently
    running programs
  • Separate hard disk partition called swap
    partition
  • Also called virtual memory
  • Acts like extension of systems RAM
  • Swapped-out process cannot run until swapped
    again
  • Use free m or vmstat to monitor

31
Swap Space (continued)
  • Thrashing
  • Kernel spends so much time moving processes to
    and from swap space that kernel and processes bog
    down and work inefficiently

32
Understanding Paged Memory
  • Information transferred to and from swap space in
    units known as pages
  • Page of memory
  • Block of 4 KB of RAM
  • Kernel keeps track of which pages of memory are
    moved to swap space

33
Tracking Memory Usage
  • free command
  • Displays information about both RAM and virtual
    memory
  • buffer
  • Memory used by application for data storage
  • Several fields of ps command output also provide
    information about memory usage

34
Viewing Virtual Memory Information
  • vmstat command
  • View detailed information about how swap space is
    being used
  • Displayed information based on information
    averaged over time since system was started
  • Can also run to be continuously updated
  • Like top

35
Scheduling Processes
  • at command
  • Define one or more commands to be executed at
    some future time
  • Command relies on background process called atd
  • crontab command
  • Define one or more commands to be executed
    repeatedly at intervals that you designate
  • Relies on background process called crond

36
Automating One-Time Tasks
  • Using at command enter commands
  • Directly at command line
  • at now 5 hours
  • CtrlD to exit
  • Or listed in file
  • at -f ltfilenamegt lttime specificationgt
  • atd daemon checks once per minute for any jobs
    that scheduled using at command
  • Output of commands e-mailed to user

37
Automating One-Time Tasks (continued)
38
Automating One-Time Tasks (continued)
  • tty command
  • Sends output from command to terminal in which
    you are currently logged in
  • batch command
  • Similar to at
  • Runs commands when system load average drops
    below 0.8 or 1.5.

39
Automating Recurring Tasks
  • Use crontab command
  • To execute commands at regular intervals
  • Red Hat Linux
  • /etc directory contains subdirectories named
    cron.Hourly, cron.Daily, cron.Weekly, and
    cron.Monthly
  • Place file subdirectory
  • Commands in file executed hourly, daily, weekly,
    or monthly

40
Automating Recurring Tasks (continued)
  • Every Linux system should include /etc/crontab
    file
  • Illustrates format of standard entry for crontab
    command
  • crontab specification begins with five fields
    that identify time
  • All five fields must match current time and date
    for command to execute
  • Cannot enter cron job commands interactively

41
Managing Automated Tasks
  • Daemons atd and crond started when Linux booted
  • Commands submit using at or crontab stored in
    subdirectory of /var/spool
  • atq and atrm commands
  • Manage at jobs awaiting execution
  • atq command lists all queued at jobs

42
Managing Automated Tasks (continued)
  • atrm command
  • Cancel command submitted using at
  • Can also use -d option with at command
  • Must include job number
  • Use similar set of commands to manage cron jobs
  • Options to crontab command

43
Review of at commands
  • at l or atq
  • List jobs submitted
  • at d or atrm
  • Delete a job specify job id
  • Running process
  • at c job id
  • Shows contents of job

44
Controlling Access to at and crontab
  • Default settings allow any user to submit
    commands using either at or crontab
  • Can restrict access to only certain users
  • /etc/at.allow and /etc/at.deny
  • /etc/cron.allow and /etc/cron.deny
  • One user name per line
  • Allow list overrides deny list

45
cron command
  • cron daemon is running in the background
  • crontab e
  • Eidt crontab table with nano
  • crontab l
  • List crontab contents

46
cron command
  • cron parameters
  • 1 2 3 4 5 command
  • 1 minutes past hour (0-59)
  • 2 hour (0-23)
  • 3 day of month (1-31)
  • 4 month of year (1-12)
  • 5 day of week
  • 0 or 7 Sunday, 1 Monday, 6 Saturday

47
cron command
  • 10,30,50 10,30,50 minutes
  • - every possible option

48
System cron table
  • Only root may edit
  • /etc/crontab or /etc/cron.d
  • Run-parts executes all files in a particular
    directory
  • Copy scripts to /etc/cron.daily or use a symbloic
    like to shell
  • Runs daily, weekly, or monthly
Write a Comment
User Comments (0)
About PowerShow.com