Linux+ Guide to Linux Certification, Third Edition Chapter 9 Managing Linux Processes

  • Published on
    20-Jan-2016

  • View
    216

  • Download
    0

Embed Size (px)

Transcript

  • Linux+ Guide to Linux Certification, Third EditionChapter 9Managing Linux Processes

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*ObjectivesCategorize the different types of processes on a Linux systemView processes using standard Linux utilitiesExplain the difference between common kill signalsDescribe how binary programs and shell scripts are executed

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*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, 3e

  • Linux+ Guide to Linux Certification, 3e*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, 3e

  • Linux+ Guide to Linux Certification, 3e*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): PID of the parent processThe init daemon has a PID of 1 and a PPID of 0

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Linux Processes (continued)Figure 9-1: Parent and child processes

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Linux Processes (continued)Figure 9-2: Process genealogy

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Viewing Processesps command: view processesMost versatile and 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-e option: displays the entire list of processes across all terminals including daemons

    Linux+ Guide to Linux Certification, 3e

  • Viewing Processes (continued)Process flag: indicates particular features of the processProcess state: current processor state of processMost processes sleeping (S) or running (R)Zombie process: process finished, but parent has not released child processs PIDDefunct processProcess state is ZLinux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Viewing Processes (continued)Process priority (PRI): priority used by the kernel for the processHigher value means lower priorityNice value (NI): can be used to affect the process priority indirectlyHigher value means a greater chance of low prioritypstree command: displays the lineage of a process by tracing its PPIDs until the init daemon

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Viewing Processes (continued)Table 9-1: Common options to the ps command

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*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 processesRogue processes can be killed immediately when identified

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Killing Processeskill command: sends a kill signal to a process to terminate it64 types of kill signalsAffect processes in different ways -l option: displays list of kill signal names and associated numbers To kill a process, give kill signal and PIDIf no kill signal given, the default kill signal, SIGTERM, is used

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Killing Processes (continued)Table 9-2: Common administrative kill signals

    Linux+ Guide to Linux Certification, 3e

  • Killing Processes (continued)Trapping: ignoring a kill signalThe SIGKILL signal cannot be trapped by any processUse only as last resortWhen parent process receives a kill signal, parent process terminates all child processes before terminating itselfTo kill several related processes send signal to parent processKill parent process in order to kill zombie processesLinux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Killing Processes (continued)killall command: kills multiple processes of the same name in one commandTakes kill signal number as an optionUses process name instead of PIDIf no kill signal given, the default kill signal, SIGTERM, is usedCan use top command to kill processes

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Process ExecutionThree main types of executable commandsBinary programse.g., ls, find, grepShell scriptsShell functionse.g., cd, exit

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Process Execution (continued)Forking: act of creating new BASH shell or subshellCarried out by fork 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, 3e

  • Linux+ Guide to Linux Certification, 3e*Process Execution (continued)Figure 9-3: Process forking

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Running Processes in the BackgroundForeground processes: BASH shell must wait for termination to display prompt and accept new commandsBackground processes: BASH shell does not wait for terminationAppend & metacharacter to commandUpon execution, user receives BASH shell prompt immediately

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Running Processes in the Background (continued)jobs command: lists background job IDs for processes running in current shellTo terminate background process:Send kill signal to PIDSend kill signal to background job IDPrefix job ID with % character

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Running Processes in the Background (continued)foreground (fg) command: move a background process to the foregroundUse Ctrl+z to pause a foreground processAssigns the process a background job IDbackground (bg) command: send an existing process to the backgroundProvide background job ID as argumentjobs command indicates the two most recent background processesBy default, commands apply to most recent process

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*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, 3e

  • Linux+ Guide to Linux Certification, 3e*Process Priorities (continued)PRI dictates number of time slices a process getsLow PRI is likely to get more time slices than high PRICannot change PRI value directlySet NI to indirectly affect priorityNegative NI value, more time slices; positive NI value, less time slicesProcesses start with NI of 0nice command: change a processs priority as it starts

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Process Priorities (continued)Figure 9-4: The nice value scale

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Process Priorities (continued)renice command: alter NI of a process after it has been startedOnly root user may change NI to a negative value-u option: change the NI for all processes owned by the specified user or groupMay also change NI of running processes using top utility

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Scheduling CommandsTo schedule commands to execute in the future:at 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, 3e

  • Linux+ Guide to Linux Certification, 3e*Scheduling Commands with atdat command: schedule commands and tasks to run at a preset timeSpecify the time as an argumentl option: view a list of at job IDs (regular users see only their own jobs)atq command: alias to at -lc option: view content of a specified at jobd option: delete the specified at jobf option: list commands to be scheduled by at from a shell script

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Scheduling Commands with atd (continued)Table 9-3: Common at commands

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Scheduling Commands with atd (continued)at 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 a file, it is mailed to user

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*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 daemonIf both files exist, only /etc/at.allow file is processedOn Fedora Linux systems, only /etc/at.deny file exists by defaultInitially left blank, all users allowed to use at daemon

    Linux+ Guide to Linux Certification, 3e

  • Scheduling Commands with crondSuitable for scheduling repetitive tasksCron tables: configuration files specifying when commands should be executedSix fields separated by space or tab charactersFirst five specify times to run the commandSixth absolute pathname to command to be executedLinux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Scheduling Commands with crond (continued)User cron tables: represent tasks scheduled by individual usersSystem 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

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Scheduling Commands with crond (continued)Figure 9-5: User cron table format

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Scheduling Commands with crond (continued)Figure 9-6: Sample user cron table entry

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*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 daemonIf both files exist, only /etc/cron.allow file is processedOn Fedora Linux systems, only /etc/cron.deny file exists by defaultInitially left blank, all users allowed to use cron daemon

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*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 cron table and all scheduled jobs-u option: used by root user to edit, list, or remove a specified users cron table

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*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, 3e

  • Linux+ Guide to Linux Certification, 3e*The System Cron Table (continued)Initial section of cron table specifies execution environmentRemainder similar to user cron table entriesCron tables located in the /etc/cron.d directory are run by the system as a specified userCan 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/

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*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, 3e

  • Linux+ Guide to Linux Certification, 3e*Summary (continued)Process information is stored in the /proc filesystem; the ps, pstree and top commands can be used to view this informationZombie and rogue processes that exist for long periods of time use up system resources and should be killed to improve system performanceYou can send kill signals to a process using the kill, killall, and top commands

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Summary (continued)The BASH shell creates, or 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 nice valueCommands can be scheduled to run at a later time using the at and cron daemons

    Linux+ Guide to Linux Certification, 3e

Recommended

View more >