1 / 48

Chapter 6: Managing Processes

Chapter 6: Managing Processes. The Complete Guide to Linux System Administration. Objectives. Define processes as used by the Linux kernel View and control running processes using command-line and graphical utilities Understand and manage how memory is used by Linux processes

elsu
Télécharger la présentation

Chapter 6: Managing Processes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6:Managing Processes The Complete Guide to Linux System Administration

  2. Objectives • Define processes as used by the Linux kernel • View and control running processes using command-line and graphical utilities • Understand and manage how memory is used by Linux processes • Schedule delayed execution of processes The Complete Guide to Linux System Administration

  3. Defining Processes • Should be familiar with process definition to better understand • How Linux operates • How to manage its resources The Complete Guide to Linux System Administration

  4. The Linux Multitasking Model • Process • Program running on system • Started from: • Command line • Graphical desktop • Kernel itself • Another process • Kernel maintains information about processes The Complete Guide to Linux System Administration

  5. 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 don’t have multiple microprocessors The Complete Guide to Linux System Administration

  6. 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 The Complete Guide to Linux System Administration

  7. 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 The Complete Guide to Linux System Administration

  8. Process States • Running • Sleeping • Stopped • Zombie The Complete Guide to Linux System Administration

  9. 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 system’s RAM • Swapped-out process cannot run until swapped again The Complete Guide to Linux System Administration

  10. 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 The Complete Guide to Linux System Administration

  11. Managing Linux Processes • View information about Linux processes • Control status of processes The Complete Guide to Linux System Administration

  12. 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 The Complete Guide to Linux System Administration

  13. 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 • Ctrl+Z key combination • Suspend job that shell is running The Complete Guide to Linux System Administration

  14. Starting Processes from the Shell (continued) • bg command • Run suspended program in background • fg command • Place suspended job in foreground • Must specify: • Job number using % • Or PID The Complete Guide to Linux System Administration

  15. 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 • Alt+F2 • Access second virtual console The Complete Guide to Linux System Administration

  16. 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 The Complete Guide to Linux System Administration

  17. Learning about Processes via the Command Line (continued) • Daemon • Background process • Doesn’t 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 The Complete Guide to Linux System Administration

  18. 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 The Complete Guide to Linux System Administration

  19. 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 The Complete Guide to Linux System Administration

  20. 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 The Complete Guide to Linux System Administration

  21. 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 The Complete Guide to Linux System Administration

  22. Learning about Processes via the Command Line (continued) The Complete Guide to Linux System Administration

  23. Controlling Processes • kill command • Controls any process • Sends signals to processes • -l option views all signals • Examples: • kill -9 1482 • kill -SIGTERM 1482 The Complete Guide to Linux System Administration

  24. 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 signal • Number 15 • Requests that program end • Almost all programs respond The Complete Guide to Linux System Administration

  25. Controlling Processes (continued) • SIGKILL signal • Number 9 • Handled by Linux kernel • Shuts down indicated process • Unsaved data in program lost • Renegade program virtually never crashes Linux kernel The Complete Guide to Linux System Administration

  26. 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 • Each process assigned priority determines how much CPU time granted to process • Normally all processes have same priority The Complete Guide to Linux System Administration

  27. Controlling Processes (continued) • Nice level • Another name for process priority • Standard level is 0 • Highest level 20 • System administrator can make any process nicer • User can raise nice level of process that he or she started The Complete Guide to Linux System Administration

  28. Controlling Processes (continued) • Alter process priority • nice command • nice -5 analyze • renice command • renice +10 1776 • Can issue nice and renice while top running The Complete Guide to Linux System Administration

  29. Controlling Processes (continued) The Complete Guide to Linux System Administration

  30. Using Graphical Process Management Tools • KDE System Guard utility • Graphically displays process list • Interact with list to rearrange or kill processes • GNOME System Monitor • Manage processes graphically • Gkrellm • View system status information on desktop continuously The Complete Guide to Linux System Administration

  31. 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 The Complete Guide to Linux System Administration

  32. Managing Memory • Other key system resources • Physical memory (RAM) • Virtual memory (swap space) • More RAM always leads to better performance on busy system The Complete Guide to Linux System Administration

  33. 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 • ldd command • Lists all libraries that program requires The Complete Guide to Linux System Administration

  34. 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 The Complete Guide to Linux System Administration

  35. Tracking Memory Usage • Free command • Displays information about both RAM and virtual memory • All information displayed is in kilobytes • Buffer • Memory used by application for data storage • Several fields of ps command output also provide information about memory usage The Complete Guide to Linux System Administration

  36. 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 The Complete Guide to Linux System Administration

  37. 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 The Complete Guide to Linux System Administration

  38. Automating One-Time Tasks • Using at command enter commands • Directly at command line • at now + 5 hours • Or listed in file • at -f <filename> <time specification> • atd daemon checks once per minute for any jobs that scheduled using at command • Output of commands e-mailed to user The Complete Guide to Linux System Administration

  39. Automating One-Time Tasks (continued) The Complete Guide to Linux System Administration

  40. 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 The Complete Guide to Linux System Administration

  41. 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 The Complete Guide to Linux System Administration

  42. 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 The Complete Guide to Linux System Administration

  43. 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 The Complete Guide to Linux System Administration

  44. 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 The Complete Guide to Linux System Administration

  45. 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 The Complete Guide to Linux System Administration

  46. Summary • Linux is a multiprocessing operating system • New processes are created by forking existing process • ps command displays many different fields of information about each process • kill command sends signals to processes or to Linux kernel to end process The Complete Guide to Linux System Administration

  47. Summary (continued) • Each process in Linux assigned priority • Called nice level • top command lists processes according to how much CPU time they are using • free and vmstat commands display information about RAM and virtual memory usage The Complete Guide to Linux System Administration

  48. Summary (continued) • at command schedules task for execution by atd at future point • batch command accepts tasks for future execution without fixed time • crontab command schedules tasks to be executed on regular basis The Complete Guide to Linux System Administration

More Related