linux+ guide to linux certification chapter eleven managing linux processes
TRANSCRIPT
Linux+ Guide to Linux Certification
Chapter Eleven
Managing Linux Processes
BatchBatch
CTSSCTSS
MultiprogrammingMultiprogramming
• DMA & relocation
• Multics
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
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
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
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
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
Linux ProcessesLinux Processes
Figure 11-1: Parent and child processes
Linux ProcessesLinux Processes
Figure 11-2: Process genealogy
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
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
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
Viewing ProcessesViewing Processes
Table 11-1: Common options to the ps command
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
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
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
Killing ProcessesKilling Processes
Table 11-2: Common administrative kill signals
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
Process ExecutionProcess Execution
• The three main types of Linux commands that you may execute:– Binary programs– Shell scripts– Shell functions
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
Process ExecutionProcess Execution
Figure 11-3: Process forking
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
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
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
Process PrioritiesProcess Priorities
Figure 11-4: The nice value scale
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
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
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
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
Scheduling Commands with atdScheduling Commands with atd
Table 11-3 (continued): Common at commands
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
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
Scheduling Commands with crondScheduling Commands with crond
Figure 11-5: User cron table format
Scheduling Commands with crondScheduling Commands with crond
Figure 11-6: Sample user cron table entry
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
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
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
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
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
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