Transcript
Page 1: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Linux+ Guide to Linux Certification

Chapter Eleven

Managing Linux Processes

Page 2: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

BatchBatch

Page 3: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

CTSSCTSS

Page 4: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

MultiprogrammingMultiprogramming

• DMA & relocation

• Multics

Page 5: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

ObjectivesObjectives

• Categorize the different types of processes on a Linux system

• View processes using standard Linux utilities

• Illustrate the difference between common kill signals

• Describe how binary programs and shell scripts are executed

Page 6: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

ObjectivesObjectives

• 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

Page 7: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Linux ProcessesLinux Processes

• Program– Structured set of command stored in an

executable file on a filesystem– It may be executed to create a process

• Process– A program that is running in memory and on the

CPU

Page 8: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Linux ProcessesLinux Processes

• User process– Process begun by a user that runs on a terminal

• Daemon process– System process that is not associated with a

terminal

• Process ID (PID)– Unique identifier assigned to every process as it

begins

Page 9: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Linux ProcessesLinux Processes

• Child processes– Refers to a process that was started by another

process (parent process)

• Parent processes– Process that has started other processes (child

processes)

• Parent Process ID (PPID)– The PID of the parent process that created the

current process

Page 10: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Linux ProcessesLinux Processes

Figure 11-1: Parent and child processes

Page 11: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Linux ProcessesLinux Processes

Figure 11-2: Process genealogy

Page 12: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Viewing ProcessesViewing Processes

• There are several Linux utilities that can view processes

• ps command– The most versatile and common Linux utility that

can view processes– Without arguments, the ps command simply

displays a list of processes that are running in the current shell

Page 13: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Viewing ProcessesViewing Processes

• Process state– Current state of the process on the processor– Most processes are in the sleeping or running

state

• Zombie process– Process that has finished executing, but whose

parent has not yet released its PID– Also know as defunct processes

Page 14: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Viewing ProcessesViewing Processes

• Process priority (PRI)– Number assigned to a process, used to determine

how many time slices on the processor it will receive

• Nice value (NI)– Value that indirectly represents the priority of a

process• The higher the value, the lower the priority

Page 15: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Viewing ProcessesViewing Processes

Table 11-1: Common options to the ps command

Page 16: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Viewing ProcessesViewing Processes

• top command– Most common command used to display

processes aside from ps– Displays its interactive screen listing processes

organized by processor time• Processes that use the most processor time are listed at

the top of the screen

Page 17: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Viewing ProcessesViewing Processes

• Rogue processes– Process that has become faulty in some way and

continues to consumes far more system resources than it should

• The top command can be used to change the priority of processes or kill them

Page 18: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Killing ProcessesKilling Processes

• Kill signal– Type of signal sent to a process by the kill

command– Different kill signals affect processes in different

ways

• kill command– Command that kills all instances of a process by

command name

Page 19: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Killing ProcessesKilling Processes

Table 11-2: Common administrative kill signals

Page 20: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Killing ProcessesKilling Processes

• Trapping– The process of ignoring a kill signal

• killall command– The command that kills all instances of a process

by command name

Page 21: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Process ExecutionProcess Execution

• The three main types of Linux commands that you may execute:– Binary programs– Shell scripts– Shell functions

Page 22: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Process ExecutionProcess Execution

• Forking– The act of creating a new BASH shell child

process from a parent– Carried out by the fork function in the BASH

shell

Page 23: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Process ExecutionProcess Execution

Figure 11-3: Process forking

Page 24: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Running Processes in the Running Processes in the BackgroundBackground

• Foreground processes– Process for which the BASH shell that executed it

must wait for its termination

• Background processes– Process that does not require the BASH shell to

wait for its termination– Upon execution, the user receives the BASH shell

prompt immediately

Page 25: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Running Processes in the Running Processes in the BackgroundBackground

• jobs command– Command used to see the list of background

processes running in the current shell

• foreground (fg) command– Command used to run a background process in the

foreground

• background (bg) command– Command used to run a foreground process in the

background

Page 26: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Process PrioritiesProcess Priorities

• Time slice– The amount of time a process is given on a CPU

in a multiprocessing operating system– The more time slices a process has, the more time

it has to execute on the CPU and the faster it will execute

– Time slices are usually measured in milliseconds

Page 27: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Process PrioritiesProcess Priorities

Figure 11-4: The nice value scale

Page 28: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Process PrioritiesProcess Priorities

• Processes are started with a nice value of 0 by default– On some Linux systems, background processes

are given a nice value of 4 by default to lower the chance they will receive time slices

• nice command– The command used to change the priority of a

process as it is started

Page 29: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Process PrioritiesProcess Priorities

• renice command– The command used to alter the nice value of a

process currently running on the system

• As with the nice command, only the root user may change the nice value to a negative value using the renice command

Page 30: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Scheduling CommandsScheduling Commands

• The at daemon (atd)– The system daemon that executes tasks at a future

time– It is configured with the at command

• The cron daemon (crond)– The system daemon that executes tasks

repetitively in the future– It is configured using cron tables

Page 31: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Scheduling Commands with atdScheduling Commands with atd

• at command– The command used to schedule commands and tasks to run at a

preset time in the future

Table 11-3: Common at commands

Page 32: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Scheduling Commands with atdScheduling Commands with atd

Table 11-3 (continued): Common at commands

Page 33: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Scheduling Commands with atdScheduling Commands with atd

• /etc/at.allow– A file listing all users who can use the at

command

• /etc/at.deny– A file listing all the users who cannot access the

at command

Page 34: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Scheduling Commands with crondScheduling Commands with crond

• Cron tables– A file specifying tasks to be run by the cron

daemon– There are user cron tables and system cron tables– They have six fields separated by space or tab

characters

Page 35: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Scheduling Commands with crondScheduling Commands with crond

Figure 11-5: User cron table format

Page 36: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Scheduling Commands with crondScheduling Commands with crond

Figure 11-6: Sample user cron table entry

Page 37: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Scheduling Commands with crondScheduling Commands with crond

• /var/spool/cron– A directory that stores user cron tables

• /etc/cron.d– A directory that contains additional system cron

tables

• /etc/crontab– The default system cron table

Page 38: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

User Cron TablesUser Cron Tables

• /etc/cron.allow– A file listing all users who can use the cron command

• /etc/cron.deny– A file listing all users who cannot access the cron

command

• crontab command– The command used to view and edit user cron tables

Page 39: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

The System Cron TableThe System Cron Table

• Linux systems are typically scheduled to run many commands during non-business hours

• These commands may perform system maintenance, back up data, or run CPU-intensive programs

• Most of these commands are scheduled by the cron daemon from entries in the system cron table /etc/crontable

Page 40: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Chapter SummaryChapter Summary

• Processes are programs that are executing on the system

• User processes are run in the same terminal as the user who has 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

• Process information is stored in the /proc filesystem

Page 41: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Chapter SummaryChapter Summary

• Zombie and rogue processes that exist for long periods of time use up system resources and should be killed to improve system performance

• You may send kill signals using the kill, killall, and top commands

• The BASH shell forks a subshell to execute most commands

Page 42: Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes

Chapter SummaryChapter Summary

• Processes may be run in the background by appending an & to the command name

• The priority of a process may be affected indirectly by altering its nice value

• Commands may be scheduled to run at a later time using the at and cron daemons


Recommended