Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.

  • Published on
    04-Jan-2016

  • View
    214

  • Download
    1

Embed Size (px)

Transcript

  • Linux+ Guide to Linux Certification, Second EditionChapter 10Managing Linux Processes

    Linux+ Guide to Linux Certification, 2e

  • ObjectivesCategorize the different types of processes on a Linux systemView processes using standard Linux utilitiesIllustrate the difference between common kill signalsDescribe how binary programs and shell scripts are executed

    Linux+ Guide to Linux Certification, 2e

  • Objectives (continued)Create and manipulate background processesUse standard Linux utilities to modify the priority of a processSchedule commands to execute in the future using the at daemonSchedule commands to execute repetitively using the cron daemon

    Linux+ Guide to Linux Certification, 2e

  • Linux ProcessesProgram: Structured set of commands stored in an executable fileExecuted to create a processProcess: Program running in memory and on CPUUser process: Process begun by user on a terminalDaemon process: System process Not associated with a terminal

    Linux+ Guide to Linux Certification, 2e

  • Linux Processes (continued)Process ID (PID): Unique identifier assigned to a processChild process: Process started by another process (parent process)Parent process: Process that has started other processes (child processes)Parent Process ID (PPID): Parent processs PID

    Linux+ Guide to Linux Certification, 2e

  • Linux Processes (continued)Figure 10-1: Parent and child processes

    Linux+ Guide to Linux Certification, 2e

  • Linux Processes (continued)Figure 10-2: Process genealogy

    Linux+ Guide to Linux Certification, 2e

  • Viewing Processesps command: View processesMost common process viewing utilityNo arguments: Lists all processes running in current shellPID, terminal, command that started process, CPU timef (full) option: More complete informationUser identifier (UID), PPID, start time, CPU utilization

    Linux+ Guide to Linux Certification, 2e

  • Viewing Processes (continued)Process state: Current processor state of processMost processes sleeping (S) or running (R)Zombie process: Process finished, but parent has not released PIDDefunct processProcess state is Z

    Linux+ Guide to Linux Certification, 2e

  • Viewing Processes (continued)Process priority (PRI): Determines how many processor time slices process will receiveHigher value means lower priorityNice value (NI): Indirectly represents priorityHigher value means lower priority

    Linux+ Guide to Linux Certification, 2e

  • Viewing Processes (continued)Table 10-1: Common options to the ps command

    Linux+ Guide to Linux Certification, 2e

  • Viewing Processes (continued)top command: Displays interactive screen listing processesOrganized by processor timeProcesses using most processor time listed firstRogue process: Faulty process Consumes excessive system resourcestop command can be used to change PRI or kill processes

    Linux+ Guide to Linux Certification, 2e

  • Killing Processeskill signal: Sent to a process by kill command64 types of kill signalsAffect processes in different wayskill command: Kills all instances of a process by command nameTo kill a process, give kill signal and PIDIf no kill signal given, SIGTERM assumed

    Linux+ Guide to Linux Certification, 2e

  • Killing Processes (continued)Table 10-2: Common administrative kill signals

    Linux+ Guide to Linux Certification, 2e

  • Killing Processes (continued)Trapping: Ignore a kill signalKill signals sent to processes having childrenParent process terminates all child processes before terminating itselfOften necessary to kill parent process in order to kill zombie processes

    Linux+ Guide to Linux Certification, 2e

  • Killing Processes (continued)killall command: Kills all instances of a process by command nameUses process name instead of PIDCan use top command to kill processes

    Linux+ Guide to Linux Certification, 2e

  • Process ExecutionThree main types of executable commandsBinary programsShell scriptsShell functions

    Linux+ Guide to Linux Certification, 2e

  • Process Execution (continued)Forking: Act of creating new BASH shell child process from a parentFork function in BASH shellSubshell executes program or shell script using exec functionOriginal shell waits for subshell to completeWhen done, subshell kills itself Control returns to original shell

    Linux+ Guide to Linux Certification, 2e

  • Process Execution (continued)Figure 10-3: Process forking

    Linux+ Guide to Linux Certification, 2e

  • Running Processes in the BackgroundForeground processes: BASH shell must wait for terminationBackground processes: BASH shell does not wait for termination& metacharacterUpon execution, user receives BASH shell prompt immediately

    Linux+ Guide to Linux Certification, 2e

  • Running Processes in the Background (continued)jobs command: Lists background processes running in current shellforeground (fg) command: Run a background process in foregroundForeground process may be paused with ctrl Zbackground (bg) command: Run a foreground process in background

    Linux+ Guide to Linux Certification, 2e

  • Running Processes in the Background (continued)Jobs command marks two most recent background processesCommands operate on most recent process, by default

    Linux+ Guide to Linux Certification, 2e

  • Process PrioritiesTime slice: Amount of time a process is given on a CPUMore time slices mean more execution time on CPUExecutes fasterUsually measured in milliseconds

    Linux+ Guide to Linux Certification, 2e

  • Process Priorities (continued)PRI dictates number of time slices a process getsCannot change PRI value directlySet NI to indirectly affect priorityProcesses start with NI of 0nice command: Change a processs priority as it starts

    Linux+ Guide to Linux Certification, 2e

  • Process Priorities (continued)Figure 10-4: The nice value scale

    Linux+ Guide to Linux Certification, 2e

  • Process Priorities (continued)renice command: Alter NI of a process after it is runningOnly root user may change NI to a negative valueMay also change NI of running processes using top utility

    Linux+ Guide to Linux Certification, 2e

  • Scheduling Commandsat daemon (atd): System daemon that executes tasks at a future timecron daemon (crond): System daemon that executes tasks repetitively in the future

    Linux+ Guide to Linux Certification, 2e

  • Scheduling Commands with atdat command: Schedule commands and tasks to run at a preset timel option: View a list of scheduled jobsRegular users see only their own jobsc option: View system environment at scheduling timed option: Delete a jobf option: Run scheduled jobs from shell script

    Linux+ Guide to Linux Certification, 2e

  • Scheduling Commands with atd (continued)atq command: Alternative method to view scheduled jobsat daemon uses current shells environment for executionShell environment and scheduled commands stored in /var/spool/atIf stdout of scheduled command has not been redirected to file, mailed to user

    Linux+ Guide to Linux Certification, 2e

  • Scheduling Commands with atd (continued)Table 10-3: Common at commands

    Linux+ Guide to Linux Certification, 2e

  • Scheduling Commands with atd (continued)/etc/at.allow: File listing all users able to use at command/etc/at.deny: File listing all the users not able to use at commandOn Fedora Linux systems, no /etc/at.allow file existsEmpty by defaultAll users allowed to use at daemon

    Linux+ Guide to Linux Certification, 2e

  • Scheduling Commands with crondCron tables: Files specifying tasks for cron daemon to run Specify when commands should be executedUser and system cron tablesSix fields separated by space or tab characters

    Linux+ Guide to Linux Certification, 2e

  • Scheduling Commands with crond (continued)Figure 10-5: User cron table format

    Linux+ Guide to Linux Certification, 2e

  • Scheduling Commands with crond (continued)Figure 10-6: Sample user cron table entry

    Linux+ Guide to Linux Certification, 2e

  • Scheduling Commands with crond (continued)/var/spool/cron: Stores user cron tables/etc/crontab: Contains default system cron table /etc/cron.d: Contains additional system cron tables

    Linux+ Guide to Linux Certification, 2e

  • User Cron Tables/etc/cron.allow: Lists users able to use cron command/etc/cron.deny: Lists users not able to access cron command

    Linux+ Guide to Linux Certification, 2e

  • User Cron Tables (continued)crontab command: View and edit user cron tablese option: Edit cron tables in vi editorl option: List a user cron tabler option: Remove all scheduled jobs

    Linux+ Guide to Linux Certification, 2e

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

    Linux+ Guide to Linux Certification, 2e

  • The System Cron Table (continued)Initial section of cron table specifies execution environmentRemainder similar to user cron table entriesSixth field specifies who to run command asRemaining fields represent command to runrun-parts command: Execute all files in a directory

    Linux+ Guide to Linux Certification, 2e

  • SummaryProcesses are programs that are executing on the systemUser 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 terminalEvery process has a parent process associated with it and, optionally, several child processes

    Linux+ Guide to Linux Certification, 2e

  • Summary (continued)Process information is stored in the /proc filesystem; the ps and top commands can be used to view this informationZombie and rogue processes that exist for long periods of time use up system resourcesYou can send kill signals to a process using the kill, killall, and top commands

    Linux+ Guide to Linux Certification, 2e

  • Summary (continued)The BASH shell forks a subshell to execute most commandsProcesses can be run in the background by appending an & to the command nameThe priority of a process can be affected indirectly by altering its NICommands can be scheduled to run at a later time using the at and cron daemons

    Linux+ Guide to Linux Certification, 2e

Recommended

View more >