






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of process management concepts, including definitions of key terms like process, user mode, kernel mode, user state, and kernel state. It also discusses scheduling and the historical development of multiprogramming in unix. The second part of the document delves into the specifics of the freebsd process structure, including its main entries, substructures, and states. It covers process id, signal state, tracing information, real-time timer and cpu utilization, process group id, credentials, memory management, file descriptors, system call vector, resource accounting, statistics, and signal actions.
Typology: Study notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Process: program under executionProcess: program under execution
User mode:User mode: ““normalnormal”” execution modeexecution mode
Kernel mode: privileged execution mode; required for,Kernel mode: privileged execution mode; required for,
e.g., I/O operationse.g., I/O operations
User state: registers, PC, PSW, stack pointers, plusUser state: registers, PC, PSW, stack pointers, plus
memory contentsmemory contents
Kernel state:Kernel state:
Process structure (always resident)Process structure (always resident)
User structure (only resident when process is; very little left inUser structure (only resident when process is; very little left in
FreeBSD 5.2.1) FreeBSD 5.2.1)
Context switching: changing the currentlyContext switching: changing the currently
running process (changing execution context)running process (changing execution context)
Hardware dependent; some ISA define instructions
Hardware dependent; some ISA define instructions
to save processor context; others must explicitly to save processor context; others must explicitly
save save
Kernel software state saved/loaded explicitlyKernel software state saved/loaded explicitly
Optimization is a very good idea
Optimization is a very good idea …
…
Scheduling: deciding which process to run nextScheduling: deciding which process to run next
Related to CS, in that the CS just picks the process
Related to CS, in that the CS just picks the process
at the head of the ready queue; scheduler maintains at the head of the ready queue; scheduler maintains
ready queue ready queue
Early UEarly UNIXNIX didndidn’’t have multiprogrammingt have multiprogramming
support: only one process in memory at a timesupport: only one process in memory at a time
MMU support allowed multiple processes, butMMU support allowed multiple processes, but
synchronous disk I/O meant no multitasking
synchronous disk I/O meant no multitasking
(no automatically switching between(no automatically switching between
processes)processes)
In 1972 asynchronous disk I/O made itIn 1972 asynchronous disk I/O made it
possible to switch between processes, sopossible to switch between processes, so
UUNIXNIX got real multitasking.got real multitasking.
Processes haveProcesses have ““burstsbursts”” of activity (both CPUof activity (both CPU
bursts and I/O bursts)bursts and I/O bursts)
We characterize processes by the ratio of
We characterize processes by the ratio of
these bursts:
these bursts:
Lots of I/O, little CPU: I/O bound (interactive)Lots of I/O, little CPU: I/O bound (interactive)
Lots of CPU, little I/O: CPU bound (
Lots of CPU, little I/O: CPU bound ( noninteractive
noninteractive )
)
Real-time processes must haveReal-time processes must have subportionssubportions
completed by particular deadlines; think ofcompleted by particular deadlines; think of
factory-floor automation.factory-floor automation.
Complete your time slice: priority dropsComplete your time slice: priority drops
Give up the CPU before the end: priority
Give up the CPU before the end: priority
stays the same
stays the same
Inactive processes have priority increasedInactive processes have priority increased
Process
Structure
Thread list
process group
credential
VM space
file descriptors
resource limits
statistics
signal actions
process control block
process kernel stack
session
region list
file entries
syscall vector user structure
Pointer from
Process Struct
Scheduling info
Thread control block
Thread kernel stack
Machine-dependent
Thread information
Scheduling info
Thread control block
Thread kernel stack
Machine-dependent
Thread information
System call vector: FreeBSD supports systemSystem call vector: FreeBSD supports system
call numbering for Linux, OSF/1, SVR4.call numbering for Linux, OSF/1, SVR4.
Resource Accounting: system/user time used,
Resource Accounting: system/user time used,
memory allocation, paging and disk I/O, etc.memory allocation, paging and disk I/O, etc.
Statistics (kept in user structure): accountingStatistics (kept in user structure): accounting
informationinformation
Signal actions (kept in user structure): pointersSignal actions (kept in user structure): pointers
to signal handlers, list of blocked signals, etc.to signal handlers, list of blocked signals, etc.
RUNNABLE: threads ready to runRUNNABLE: threads ready to run
SLEEPING: threads awaiting eventSLEEPING: threads awaiting event
STOPPED: threads stopped by signal orSTOPPED: threads stopped by signal or
parent process parent process
224-255224-255IDLEIDLE Idle userIdle user
160-223160-223TIMESHARETIMESHARE Time-sharing userTime-sharing user
128-159128-159REALTIMEREALTIME Real-time userReal-time user
64-12764-127 KERNKERN Top half of kernelTop half of kernel
Bottom half of kernel
Bottom half of kernel
(interrupt)(interrupt)
RangeRange ClassClass TypeType
AA thread running in the kernel (e.g., afterthread running in the kernel (e.g., after
system call) has its priority temporarily system call) has its priority temporarily
changed to be in KERN class changed to be in KERN class
When asleep, and immediately afterWhen asleep, and immediately after
awakened awakened
Priority for service over user-priority threadsPriority for service over user-priority threads
Run queues: hold threads ready to executeRun queues: hold threads ready to execute
Not a single ready queue;
Not a single ready queue; 64 queues
64 queues
All
All threads in same queue
threads in same queue are treated as same
are treated as same
priority priority
Sleep queues: hold threads waiting on events
Sleep queues: hold threads waiting on events
Hashed data structure, optimized for searching onHashed data structure, optimized for searching on
wait channel wait channel
In older versions of the OS, these heldIn older versions of the OS, these held
processes, notprocesses, not threadsthreads
LOOKUP(x) hashes an identifier to a sleep
LOOKUP(x) hashes an identifier to a sleep
queue (
queue ( kern_synch
kern_synch .c)
.c)
IdentIdent can be a void *,can be a void *, intint, or other (generally a, or other (generally a
pointer).pointer).
The sleep routines do not determine howThe sleep routines do not determine how
many identifiers there are in the systemmany identifiers there are in the system
Threads can give up the CPU by
Threads can give up the CPU by making a
making a
sleep() call (passing wait channel ID and
sleep() call (passing wait channel ID and
priority at which to be awakened)priority at which to be awakened)
1.1. AcquireAcquire sched_mutexsched_mutex locklock
Record the wait channel in the thread
Record the wait channel in the thread
structure, and hash the channel to find a
structure, and hash the channel to find a
sleep queuesleep queue
3.3. Set the threadSet the thread’’s prioritys priority for when it isfor when it is
awakened, set SLEEPING flagawakened, set SLEEPING flag
4.4. Place thread at end of sleep queuePlace thread at end of sleep queue
5.5. CallCall mi_switchmi_switch() to context switch() to context switch
((sched_locksched_lock automatically released)automatically released)
From proc.h:From proc.h:
kg_estcpukg_estcpu provides estimate of recent CPU utilizationprovides estimate of recent CPU utilization
kg_nicekg_nice user-settable weighting factor betweenuser-settable weighting factor between – – 2020
and 20 (default 0)
and 20 (default 0)
Recalculate every 4 ticks:Recalculate every 4 ticks:
kg_user_prikg_user_pri = PRI_MIN_TIMESHARE += PRI_MIN_TIMESHARE +
((kg_estcpukg_estcpu / 4) + 2 x/ 4) + 2 x kg_nicekg_nice;;
kg_user_pri
kg_user_pri = max(
= max( kg_user_pri
kg_user_pri , PRI_MIN_TIMESHARE)
, PRI_MIN_TIMESHARE)
kg_user_prikg_user_pri = min(= min(kg_user_prikg_user_pri, PRI_MAX_TIMESHARE), PRI_MAX_TIMESHARE)
PRI_MIN_TIMESHAREPRI_MIN_TIMESHARE = 160,= 160, PRI_MAX_TIMESHAREPRI_MAX_TIMESHARE = 223= 223
Load_weight = (2 * load) / (2 * load + 1);Load_weight = (2 * load) / (2 * load + 1);
kg_estcpukg_estcpu = Load_weight *= Load_weight * kg_estcpukg_estcpu ++ kg_nicekg_nice;;