Lecture 3: Processes
-
What is a process? (chapter 4, section 4.1, 4.2 and 4.3)
-
a basic way to describe the activities in the computer
-
similar terms: "job", "task"
-
formal definition: a process is an execution of a program
-
example: if you type "vi", and then type "ps", you will see:
PID TT State
TIME COMMAND
8413 pts/0 S
0:00 vi course-notes
-
one user can have many different processes:
example: you can have multiple shells running;
PID TT
State TIME
COMMAND
596 pts/1
S
0:01
tcsh
3928 pts/3
S
0:04
tcsh
7336 pts/4
S
0:02
tcsh
-
multiple users can run the same program:
example:
USER PID TT
State TIME
COMMAND
cao 596
pts/1 S
0:01
tcsh
lfan 6717
pts/6 S
0:04
tcsh
-
what happens when the same program is run in different processes:
- the program is the same, that is, the "text" sections are the
same;
- the data sections are different;
- the program counters are different;
-
analogy with real-life situation: playing a cassette in the walkman, or
a CD in the CD player;
-
also analogous to real-life situation: processes are created, can be stopped,
can be resumed, and terminate (well, most of the time);
-
Process states:
-
ready, running, blocked;
-
new, terminated;
-
transition between states:
- during creation, in the "new" state;
- once created, in the "ready" state;
- if chosen to be run on the CPU, in the "running" state;
- if stopped for some reason, in the "blocked" state;
- once finishes, in the "terminated" state;
-
CPU scheduling:
- the "ready" queue;
- the "blocked" queue;
- simple round-robin: once a clock interrupt occurs, move the current
running process back to the ready queue, and move the process at the head
of the ready queue to run on the CPU;
-
Three types of interrupts:
- clock interrupt: occurs every 10ms, moves processes between
"running" and "ready" states;
- system call interrupts: can potentially move the running process
from "running" to "blocked" state;
- device interrupts: if an I/O request is finished, the interrupt
handler moves the process waiting for the I/O request from the "blocked"
state to the "ready" state;
- clock interrupts and device interrupts are also called "hardware
interrupts";
- system call interrrupts are also called "software interrupts";
-
What constitute a process:
-
program counter, and CPU registers;
-
user address space: text, data, heap, stack;
-
32-bit address space;
-
infinite recursion will exhaust process address space; (review on procedure
calling conventions)
-
file descriptors and file pointers: for reading and writing files, and
for network communications; standard input, standard output, and standard
error;
-
accounting information;
-
I/O request status;