www.9slide.vn
Chapter 3.1
PROCESSES MANAGEMENT
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.2
The system call fork() belongs to which
category?
A. File management
B. Device management
C. Process control
D. Communication
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.3
When calling printf("Hello"), which system call is
typically invoked at the lowest level?
A. write()
B. read()
C. open()
D. exec()
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.4
When a user types the command ls in a Linux terminal, what
happens?
A. The kernel directly executes the ls command
B. The shell parses the command → runs the program → the
program invokes system calls
C. The BIOS handles the command
D. The hardware processes the command
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.5
OUTLINE
1. Process Concept
2. Process Scheduling
3. Operations on Processes
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.7
PROCESS CONCEPT
An operating system executes a variety of programs that run as a process
Process a program in execution; process execution must progress in sequential
fashion. No parallel execution of instructions of a single process
Multiple parts
The program code, also called text section
Current activity including program counter, processor registers
Stack containing temporary data
Function parameters, return addresses, local variables
Data section containing global variables
Heap containing memory dynamically allocated during run time
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.8
PROCESS CONCEPT
Program is passive entity stored on disk (executable file); process is active
Execution of program started via GUI mouse clicks, command line entry of its
name, etc
One program can be several processes
Consider multiple users executing the same program
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.9
LAYOUT OF A PROCESS OF MEMORY
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.10
MEMORY LAYOUT OF A C PROGRAM
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.11
PROCESS STATE
As a process executes, it changes state
New: The process is being created
Running: Instructions are being executed
Waiting: The process is waiting for some event to occur
Ready: The process is waiting to be assigned to a processor
Terminated: The process has finished execution
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.12
DIAGRAM OF PROCESS STATE
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.13
DIAGRAM OF PROCESS STATE
Compile the program on Linux:
gcc test.c o test
Execute the test program: ./test
In the system, a process named
test is created, executed, and
then terminated.
Process state sequence of the test program
(best-case scenario)
New
Ready
Running
Waiting (waiting for I/O when calling
printf)
Ready
Running
Terminated
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.14
DIAGRAM OF PROCESS STATE
After the program finishes executing, how
many times does the process enter the waiting
queue?
New ready running waiting ready
running waiting ready running waiting
ready running waiting ready running
terminated
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.15
PROCESS CONTROL BLOCK (PCB)
Information associated with each process (also called task control block)
Process state running, waiting, etc.
Program counter location of instruction to next execute
CPU registers contents of all process-centric registers
CPU scheduling information- priorities, scheduling queue pointers
Memory-management information memory allocated to the process
Accounting information CPU used, clock time elapsed since start,
time limits
I/O status information I/O devices allocated to process, list of open
files
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.16
THREADS
So far, process has a single thread of execution
Consider having multiple program counters per process
Multiple locations can execute at once
Multiple threads of control threads
Must then have storage for thread details, multiple program counter in PCB
Explore in detail in Chapter 4
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.17
PROCESS REPRESENTATION IN LINUX
Represented by the C structure task_struct
pid t_pid; /* process identifier */
long state; /* state of the process */
unsigned int time_slice /* scheduling information */
struct task_struct *parent; /* this processs parent */
struct list_head children; /* this processs children */
struct files_struct *files; /* list of open files */
struct mm_struct *mm; /* address space of this process */
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.18
PROCESS SCHEDULING
Process scheduler selects among available processes for next execution on CPU
core
Goal Maximize CPU use, quickly switch processes onto CPU core
Maintains scheduling queues of processes
Ready queue set of all processes residing in main memory, ready and waiting
to execute
Wait queues set of processes waiting for an event (i.e., I/O)
Processes migrate among the various queues
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.19
READY AND WAIT QUEUES
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.20
REPRESENTATION OF PROCESS SCHEDULING
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts 10
th
Edition 3.21
CPU SWITCH FROM PROCESS TO PROCESS
A context switch occurs when the CPU switches from one process to
another

Preview text:

www.9slide.vn Chapter 3.1 PROCESSES MANAGEMENT
The system call fork() belongs to which category? A. File management B. Device management C. Process control D. Communication
Operating System Concepts – 10th Edition 3.2
Silberschatz, Galvin and Gagne ©2018
When calling printf("Hello"), which system call is
typically invoked at the lowest level? A. write() B. read() C. open() D. exec()
Operating System Concepts – 10th Edition 3.3
Silberschatz, Galvin and Gagne ©2018
When a user types the command ls in a Linux terminal, what happens?
A. The kernel directly executes the ls command
B. The shell parses the command → runs the program → the program invokes system calls
C. The BIOS handles the command
D. The hardware processes the command
Operating System Concepts – 10th Edition 3.4
Silberschatz, Galvin and Gagne ©2018 OUTLINE 1. Process Concept 2. Process Scheduling 3. Operations on Processes
Operating System Concepts – 10th Edition 3.5
Silberschatz, Galvin and Gagne ©2018 PROCESS CONCEPT
▪ An operating system executes a variety of programs that run as a process
Process – a program in execution; process execution must progress in sequential
fashion. No parallel execution of instructions of a single process ▪ Multiple parts
▪ The program code, also called text section
▪ Current activity including program counter, processor registers
Stack containing temporary data
▪ Function parameters, return addresses, local variables
Data section containing global variables
Heap containing memory dynamically allocated during run time
Operating System Concepts – 10th Edition 3.7
Silberschatz, Galvin and Gagne ©2018 PROCESS CONCEPT
▪ Program is passive entity stored on disk (executable file); process is active
▪ Execution of program started via GUI mouse clicks, command line entry of its name, etc
▪ One program can be several processes
▪ Consider multiple users executing the same program
Operating System Concepts – 10th Edition 3.8
Silberschatz, Galvin and Gagne ©2018
LAYOUT OF A PROCESS OF MEMORY
Operating System Concepts – 10th Edition 3.9
Silberschatz, Galvin and Gagne ©2018
MEMORY LAYOUT OF A C PROGRAM
Operating System Concepts – 10th Edition 3.10
Silberschatz, Galvin and Gagne ©2018 PROCESS STATE
▪ As a process executes, it changes state
New: The process is being created
Running: Instructions are being executed
Waiting: The process is waiting for some event to occur
Ready: The process is waiting to be assigned to a processor
Terminated: The process has finished execution
Operating System Concepts – 10th Edition 3.11
Silberschatz, Galvin and Gagne ©2018
DIAGRAM OF PROCESS STATE
Operating System Concepts – 10th Edition 3.12
Silberschatz, Galvin and Gagne ©2018
DIAGRAM OF PROCESS STATE
▪ Process state sequence of the test program (best-case scenario) • New • Ready • Running
▪ Compile the program on Linux:
• Waiting (waiting for I/O when calling gcc test.c –o test printf)
▪ Execute the test program: ./test • Ready
▪ In the system, a process named • Running
test is created, executed, and • Terminated then terminated.
Operating System Concepts – 10th Edition 3.13
Silberschatz, Galvin and Gagne ©2018
DIAGRAM OF PROCESS STATE
After the program finishes executing, how
many times does the process enter the waiting queue?
New – ready – running – waiting – ready –
running – waiting – ready – running – waiting –
ready – running – waiting – ready – running – terminated
Operating System Concepts – 10th Edition 3.14
Silberschatz, Galvin and Gagne ©2018
PROCESS CONTROL BLOCK (PCB)
Information associated with each process (also called task control block)
▪ Process state – running, waiting, etc.
▪ Program counter – location of instruction to next execute
▪ CPU registers – contents of all process-centric registers
▪ CPU scheduling information- priorities, scheduling queue pointers
▪ Memory-management information – memory allocated to the process
▪ Accounting information – CPU used, clock time elapsed since start, time limits
▪ I/O status information – I/O devices allocated to process, list of open files
Operating System Concepts – 10th Edition 3.15
Silberschatz, Galvin and Gagne ©2018 THREADS
▪ So far, process has a single thread of execution
▪ Consider having multiple program counters per process
• Multiple locations can execute at once
Multiple threads of control → threads
▪ Must then have storage for thread details, multiple program counter in PCB
▪ Explore in detail in Chapter 4
Operating System Concepts – 10th Edition 3.16
Silberschatz, Galvin and Gagne ©2018
PROCESS REPRESENTATION IN LINUX
Represented by the C structure task_struct pid t_pid; /* process identifier */ long state; /* state of the process */ unsigned int time_slice /* scheduling information */ struct task_struct *parent; /* this process’s parent */ struct list_head children;
/* this process’s children */ struct files_struct *files; /* list of open files */ struct mm_struct *mm;
/* address space of this process */
Operating System Concepts – 10th Edition 3.17
Silberschatz, Galvin and Gagne ©2018 PROCESS SCHEDULING
Process scheduler selects among available processes for next execution on CPU core
▪ Goal – Maximize CPU use, quickly switch processes onto CPU core
▪ Maintains scheduling queues of processes
Ready queue – set of all processes residing in main memory, ready and waiting to execute
Wait queues – set of processes waiting for an event (i.e., I/O)
• Processes migrate among the various queues
Operating System Concepts – 10th Edition 3.18
Silberschatz, Galvin and Gagne ©2018 READY AND WAIT QUEUES
Operating System Concepts – 10th Edition 3.19
Silberschatz, Galvin and Gagne ©2018
REPRESENTATION OF PROCESS SCHEDULING
Operating System Concepts – 10th Edition 3.20
Silberschatz, Galvin and Gagne ©2018
CPU SWITCH FROM PROCESS TO PROCESS
A context switch occurs when the CPU switches from one process to another
Operating System Concepts – 10th Edition 3.21
Silberschatz, Galvin and Gagne ©2018