16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Introduction to kernel<br />

Fields in <strong>the</strong> process table:<br />

- a state field<br />

- identifiers indicating <strong>the</strong> user who owns <strong>the</strong><br />

process<br />

- an event descriptor set when a process is<br />

suspended<br />

The u area contains:<br />

- a pointer to <strong>the</strong> process table slot of <strong>the</strong><br />

currently executing process<br />

- parameters of <strong>the</strong> current system call, return<br />

values and error codes<br />

- file descriptors for all open files<br />

- internal I/O parameters<br />

- current directory and current root<br />

- process and file size limits<br />

Figure 1. Data Structures for Processes<br />

Context of a Process<br />

The context of a process is it state, as defined by its text, <strong>the</strong> values of its global user variables and data structures,<br />

<strong>the</strong> values of machine registers it uses, <strong>the</strong> values stored in its process table slot and u area, and <strong>the</strong> contents of its<br />

user and kernel stacks.<br />

When <strong>the</strong> kernel decides that it should execute ano<strong>the</strong>r process, it does a context switch.<br />

Moving between user and kernel mode is a<br />

change in mode.<br />

! Process states<br />

- executing in user mode<br />

- executing in kernel mode<br />

- not executing, ready to run<br />

- sleeping, e.g. waiting for I/O to<br />

complete<br />

" Process States and Transitions<br />

Directed graph<br />

- nodes - states a process can enter<br />

- edges - events that move from<br />

one state to ano<strong>the</strong>r<br />

Figure 2. Process States and Transitions<br />

The kernel allows a context switch only when a process moves from state "kernel running" to "asleep in memory".<br />

Critical sections of code are executed by at most one process at a time.<br />

Figure 3. Sample Code Creating Doubly linked List<br />

struct queue {<br />

…<br />

}*bp, *bpl;<br />

bpl->forp = bp->forp;<br />

bpl->backp = bp;<br />

bp->forp = bpl;<br />

/*consider possible context switch here */<br />

bpl->forp->backp = bpl;<br />

85

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

Saved successfully!

Ooh no, something went wrong!