16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Process Scheduling<br />

12. PROCESS SCHEDULING<br />

The Scheduler<br />

The kernel is responsible for sharing CPU time between competing processes.<br />

Multi-Level Priority Queue<br />

- linked list of runnable processes<br />

Processes are allocated CPU time in proportion to <strong>the</strong>ir importance. Time is allocated in fixed size units called<br />

"time quantums" (~ 1/10 second).<br />

Process Table<br />

Next PID PPID Stat<br />

MLPQ ---> . 36 12 R . ---> Process 34<br />

| -- free entry<br />

0 .-- | - 18 1 S<br />

1 .-- | free entry<br />

2 - | -> - 12 1 R . ---> Process 12<br />

3 - | free entry<br />

4 - | -> - 48 1 S<br />

----> - 1 - R . ---> Process 1<br />

Scheduling Rules<br />

- Every second, scheduler recalculates priority of all runnable processes - organizes <strong>the</strong>m into priority<br />

queues.<br />

- Every 1/10 sec, <strong>the</strong> scheduler selects highest priority process in priority queue and allocates it <strong>the</strong> CPU.<br />

- If process is runnable at end of time quantum, it is placed at end of its priority queue.<br />

- If process sleeps on an event during time quantum, <strong>the</strong> scheduler selects next runnable process.<br />

- If process returns from system call during time quantum, and higher priority process is ready to run, <strong>the</strong><br />

lower priority process is preempted.<br />

- Every hardware clock interrupt (1/100 second), <strong>the</strong> process's clock tick count is incremented, every 4th<br />

tick, scheduler recalculates priority.<br />

priority = K1 / (recent CPU usage) + K2 / (nice setting)<br />

- A process's priority diminishes if it uses a lot of CPU in a window of time.<br />

- An interactive process waits for a user to press a key, it uses no CPU time and thus its priority level rises.<br />

Thus interactive processes obtain good response times.<br />

Memory Management<br />

Sharing of RAM between processes (secure, efficient)<br />

! Memory Pages<br />

Allow processes bigger than RAM capacity to execute. RAM (code, data, stack) divided into fixed-size pages,<br />

analogous to, disk divided into fixed-size blocks.<br />

The size of memory page is set to size of disk block. Only pages of process, currently accessed or recently<br />

accessed are stored in RAM pages, <strong>the</strong> rest are on disk.<br />

169

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!