Professional Documents
Culture Documents
Chapter 6
Process and Memory
Control
ITP3901 OPERATING SYSTEMS FUNDAMENTALS
(AY 2019/20)
2
Process
Management
Process
A program running on system
Started from:
Command line
Graphical desktop
Kernel itself
Another process
Kernel maintains information about processes
Running (R)
Sleeping (S)
Stopped (T)
Multi-threaded (I)
Zombie (Z)
e.g. myprocess&
run in background
What is 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
bg command
Run suspended program in background
fg command
Place suspended job in foreground
Must specify:
Job number using %
Or PID
Option Description
-e Display all processes running on terminals as well as processes that
do not run on a terminal (i.e. daemons)
-f Display a full list of information about each process, including the
UID, PID, PPID, CPU utilization, start time, terminal, processor time
and command name
-l Display a long list of information about each process, including flag,
state, UID, PID, PPID, CPU utilization, priority, nice value, address,
size, WCHAN, terminal and command name
The -l option generates a long listing. and when used together with the -e
and -f options creates a table with 15 columns
ps –el
Process ID of the parent process
Process ID
Nice Value
Option Description
a Display all processes running on terminals
An alternative set of options for viewing all the processes running on a system
is
ps -ef | more
The -e option generates a list of information about every process currently
running. The -f option generates a listing that contains fewer items of
information for each process than the -l option (explained in next slide).
Among the columns displayed by ps -ef, UID contains the username of the
account that owns the process (which is usually the same user that started the
process) and STIME displays the time the process started, or the starting date if
it started more than 24 hours ago.
top command
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
Can be used to monitor the processes of only one user
Can be used to kill processes
%CPU field
Compares amount of CPU time used by process with total time elapsed since
previous computation of %CPU field
Form of percentage
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
TIME field
Provides cumulative measure of amount of CPU time consumed by
process
Process ID
Chapter 6 - Process and Memory Control ITP3901 Operating Systems Fundamentals
25
Controlling Processes - kill
command (Cont.)
Signals
Messages sent between processes
About 30 different 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
Almost all programs respond
SIGKILL signal
Number 9
Handled by Linux kernel
Shuts down indicated process
Unsaved data in program will be lost
Renegade program virtually never crashes Linux kernel
SIGKILL 9 Also known as the absolute kill signal, it forces the Linux
kernel to stop executing the process by sending the process’s
resources to a special device file called /dev/null.
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
The assigned priority of a process determines how much CPU time granted
to process
Normally all processes have same priority
Nice Level
Another name for process priority
Standard level is 0
Highest level 19 (Large value means slower)
For general user, nice value is in the range of 0 to 19.
For superuser/root, it can be negative value (up to -20)
System administrator can make any process nicer (by nice and
renice commands)
User can raise nice level of process that he or she started
PID
System Monitor is a GUI system monitoring utility that will display running
processes, memory usage, file system usage. Apart from monitoring, you can
also take several actions from the system monitor user interface — such as
killing a running process.
Memory
Management
When a program runs in a computer, data are read from hard disk drive and
placed into the temporary storage of RAM. The computer uses its memory to
execute the program and frees the memory space once the program exits.
Since memory is a limited system resource, the administrator may solve the
lack of memory by using virtual memory.
Although Windows uses a swap file, it does not have to be configured. The
swap file is created as a file in the NOS partition.
Linux system typically dedicates an entire partition to swap space.
This partition is called the swap partition.
Usually the size of the swap partition should be equal to twice the computer RAM on
a Red Hat (including Fedora) Linux system.
Swap space in Linux is used when the amount of physical memory is full. If
the system needs more memory resources and the physical memory is full,
inactive pages in memory are moved to the swap space.
While swap space can help machines with a small amount of RAM, it should
not be considered a replacement for more RAM.
Swap space is located on hard drives, which have a slower access time than
physical memory.