0% found this document useful (0 votes)
9 views

Process

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Process

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 48

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
• Schedule delayed execution of processes

The Complete Guide to Linux System 2


Administration
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 3


Administration
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 4


Administration
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 5


Administration
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 6


Administration
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 7


Administration
Process States
• Runnin
g
• Sleepin
g
• Stoppe
d
• Zombi
e

The Complete Guide to Linux System 8


Administration
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 9


Administration
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 10


Managing Linux Processes
• View information about Linux
processes
• Control status of processes

The Complete Guide to Linux System Administration 11


StartingProcesses 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 12
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 13


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 14


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
The Complete second
Guide to virtual
Linux System console
Administration 15
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
The Complete Guideprocesses that
to Linux System have no controlling
Administration 16
terminal
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
The Complete which
Guide to processes
Linux System start other
Administration 17
Learning about Processes via
the Command Line
• (continued)
Administrators track how processes
consume system resources,
particularly:
—CPU time
—Memory
• % C P U field
— Compares amount of CPU time used
by process with total time elapsed since
previous computation of O›tCPU field
— Form of percentage
The Complete Guide to Linux System Administration 18
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 19
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 20
Learning about Processes via
the Command Line
• top(continued)
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 21


Learning about Processes via
the Command Line
(continued)
v
a
C to: oe:u3 up z:o7,
lertnâtd a W
users, load average : o. so, o. s6, o. •
2r
cpupzoceaaes:
71 s c cta-c cpu user , 2 ztlce
7Z s Ieep1ng sy ,s t 0
mzaaTng e c cmhce, 0 stopped Ldte
total o.as o.as 1 r q s o ft L r q l o x c tt a . a s o. as
ten: 32gsc0k 4v, 493Z8& uced, a1e5O0k
.Is Iz'ae, o.air Ok c l u b , £33Beék buIY
178658k o. zc
l824BTk
aetive, inactive BJlIBE
CnChed

126Z coat US 0 38284 Z1N 6758 5 6.0 1.2 25:31 0


z¥3e nwelJc 1s 0 9 9ti ¥5sO S X
13B4 rt e1Ia 8 5880 S 4.9 0.rI 0:DO 0 aie
1457 rneeJ3s 15 0 e260
7352 8260
Z352 77z4 s 1.6 1.I 0:03 tac1ty
1167 sla JS 0 584B SB4t 812 S a.7 1.7 0:01 O xfa
2242 n e 1 I s 17 00 24T28 23B 14478 5 0.5 1.L 0:00 0 zoa111a—b14
23B1 one1Ia TB 88B X 0.5 4.B 0t04 0 tog
2333 Awe 13s 17 D 18328 015d 3018 S 0.5 0.Z 0:00 0 gj4tp
1470 O HN 7412 0 . 8 9. 1 0•O1
xwslls 1QW SMB IS
I19OO 5 O.l 2.3 0:02 O tnlt
2 zoot 1]
IN 0 0 O O S¥f 0 .O O. 0:00 0 kexent4
0 O kapmtd
4 root 3t IB 0 0 O GYM 0 .0 0:0£i
6 z•oo £ Z 5 0 0 0 0 .0 D •DO O bd€1uab
S root 16 0 0 0 O 5¥ O.O 0 .0 0:00
O SW 0 .O
0 .0
Figure 6-1 The top utility

The Complete Guide to Linux System Administration 22


Controlling Processes

• kill command
— Controls any process
— Sends signals to
processes
— -I option views all
signals
— Examples:
• kill -9 1482
• kill -SIGTERM 1482

The Complete Guide to Linux System Administration 23


Controlling Processes
(continued)
• Signals
— Messages sent between processes
— About 30 diflerent 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
The — Almost
Complete allto programs
Guide respond
Linux System Administration 24
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 25


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
Thepriority
Complete Guide to Linux System Administration 26
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 27


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 28
Controlling Processes
(continued)
Table 6-4 Interactive Commands in top
Descript ion Press this key Notes
Updete the process list Spacebar
dispby immediately
Show a help screen with h or 7
a command llsttng
XIII a process k You will be prompted for the PID
Change the number of n or # You will be prompted for the number of
processes induded in proœsses to include
the display
Quit the top program q
Renice a process r You will be prompted for the PID and
new nice level
Change the aulomatic s You will be prompted for a Yalue (in sec-
update interval onds) for the update interval

The Complete Guide to Linux System Administration 29


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 30


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
The —
Complete Guide to Linux System Administration 31
Add memory
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 32


Understanding Shared
• Library
Librarie s
— 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
• Idd command
— Lists all libraries that program requires
The Complete Guide to Linux System Administration 33
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 34


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 35
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 36


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
The Complete Guide to Linux System Administration 37
— Relies on background process called
Automating One-Time Tasks

• Using at command enter commands


— Directly at command line
• at now + 5 hours
— Or listed in file
• at -f <fiIename> <time specifications
• 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 38


Automating One-Time
Tasks (continued)

Table 6- Example Time Specifications Using the at


5Time specification
Command Description
at -I file now + 5 Execute the commands in file five minutes
minutes after the at mand is entered
at - f file 4Pm + 5 Execute the commands in file at 4:00 p.m., five days
days from now
at -f file noon Jul 31 Execute the commands in file at noon on July 31
at -I ///e 10am Execute the commands in file at 10:00 a.m. on 15
08f 15f05 August
20 ›5
at -f file 5.75 tomor- Execute the commands in file at 5:15 a.m. tomorrow

The Complete Guide to Linux System 3


Administration 9
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 40


Administration
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 41
Administration
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
Theinteractively
Complete Guide to Linux System 42
Administration
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 43


Administration
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 44


Administration
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 45


Administration
Summary

• Linux is a multiprocessing operating


system
• New processes are created by forking
existing process
• ps command displays many diñerent
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 46
Administration
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 47


Administration
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 48


Administration

You might also like