Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structure of Processes

Similar presentations


Presentation on theme: "Structure of Processes"— Presentation transcript:

1 Structure of Processes
Chapter 6 Structure of Processes Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM Maurice J. bach Prentice Hall

2 The kernel contains a process table with an entry that describes the state of every active process in the system. The uarea contains additional information that controls the operation of a process. The process table entry and the uarea are part of the context of a process.

3 Process states and Transitions
The complete set of process states The process is executing in user mode The process is executing in kernel mode The process is not executing but is ready to run as soon as the kernel schedules it. The process is sleeping and resides in main memory. The process is ready to run, but the swapper (prcoess 0) must swap the process into main memory before the kernel can schedule it to execute.

4 6. The process is sleeping, and the swapper has swapped the process to secondary storage to make room for other processes in main memory. 7. The process is returning from the kernel to user mode, but the kernel preempts it and does a context switch to schedule another process. The distinction between this state and state 3 (" ready-to-run ") will be brought shortly. 8. The process is newly created and is in a transition state; the process exists, but it is not ready to run, nor is it sleeping. This state is the start state for all processes except process 0.

5 9. The process executed the exit system call and is in the zombie state. The process no longer exists, but it leaves a record containing an exit code and some timing statics for its parent process to collect. The zombie state is the final state of a process. 

6 Process States and Transitions
1 2 9 7 3 4 6 5 8 User Running Preempted Zombie Asleep in Memory Sleep, Swapped Ready to Run, Swapped fork Created Ready to Run in Memory Kernel Running not enough mem (swapping system only) swap out wakeup enough mem sleep reschedule process preempt return to user system call, interrupt interrupt, interrupt return

7 Data Structures for Process
Two kernel data structures describe the state of a process: the process table entry and the uarea. The process table contains fields that must always be accessible to the kernel, but the uarea contains fields that need to be accessible only to the running process.  Therefore, the kernel allocates space for the uarea only when creating a process: It does not need uareas for process table entries that do not have processes.

8 Data Structures for Process Cont..
Kernel has a process table that keeps track of all active processes Each entry in the process table contains pointers to the text, data, stack and the U Area of a process. The traditional kernel allocates several process regions, called pregions, for each process. The collection of pregions of a process form the per process region table, proc->*p_region.

9 The pregion data structure is used to record the following information of a pregion:
Pointer to an entry of the system region table it refers to. The virtual address of the region. Whether the region is read-only. The region types (e.g. text, data, stack, etc.)

10 Kernel Support for Process
Text Stack Data File Descriptor Table Per Process Region Table Kernel Process Table Kernel Region Table A Process U Area The traditional kernel allocates several process regions, called pregions, for each process.

11 Process: Region Table Region table entries describes the attributes of the region, such as whether it contains text or data, whether it is shared or private The extra level from the per process region table to kernel region table allows independent processes to share regions.

12 State of a Process Process table entry U area
Contains general fields of processes that must be always be accessible to the kernel U area further characteristics of the process only need to be accessible to the running process itself

13 Process table entry State field: user running, kernel running etc.
Fields that allow the kernel to locate the process and u area. Requires while context switch Process size : kernel know how much space to allocate for the process. User ID Process ID

14 Process table entry (contd.)
Event descriptor. Used when the process is in the "sleep" state. Scheduling parameters. Allow the kernel to determine the order in which processes move to the states "kernel running" and "user running” A signal field. keeps the signals sent to a process but not yet handled. Various timers: process execution time, resource utilization etc.

15 U Area A pointer to the process table entry User IDs various Timer:
Execution time in user mode Execution Time in kernel mode An error field: keeps error during system call Return value field: result of system call I/O parameters Amount of data transfer Address of source and target etc.

16 U Area (contd.) The current directory and current root
User file descriptor table Limit fields Restrict process size Restrict size of the file it can write The control terminal field: login terminal associated with the process, if one exists An array indicates how the process wishes to react to signal

17 Per Process Region Table (Pregion)
Each pregion entry points to the kernel region table Starting virtual (absolute) address of the region Permission filed: read-only, read-write, read-execute

18 Kernel Region table Kernel region table contains the pointer to the page table which keeps the physical memory address

19 Layout of System Memory
A process on the unix system consists of three logical sections: text, data and stack. The text section contains the set of instructions the machine executes for the process; address in the text section includes. text addresses (for branch instructions or subroutines calls) data addresses (for access to global data variables) or stack addresses (for access to data structures local to subroutines).

20 The following picture shows a possible split between OS kernel and user mode virtual memory spaces on a typical 32-bit Linux OS.

21 the picture below shows how a program looks like in main memory, in fact how a process looks like within the User Mode portion of the virtual address space! Let us inspect each memory segment, independently.

22 Regions The system U kernel divides the virtual address space of a process in to logical regions. A region is a contiguous area of the virtual address space of a process that can be treated as a distinct object to be shared or protected. Thus text, data and stack usually from separate region of a process. Several process can share a region: For instance, several processes may execute the same program, and hence they can share one copy the text region. Similarly, several processes may cooperate to share a common shared memory region.

23 The kernel contains a region table and allows an entry from the table for each activate region in the system. Region table contains information such as, to determine where it contents are located in the physical memory. Each process contains a private pre process region table called a pregion. The pregion and the structure are analogous to the file table and the inode structures in the file system.

24 Fig 2; depicts two processes, A and B showing their regions, pregions and the virtual addresses where the regions are connected. The processes share text region ‘a’ at virtual addresses 8k and 4k respectively. If process A reads memory location 8k and process B reads memory location 4k they read the identical memory location in region ‘a’. The data regions and stack regions of the two processes are private.

25 Per Process Region Tables
Regions 8K 16K 32K b a d c e 4K Text Data Stack Process A B Per Process Region Tables (Virtual Addresses) Region <Processes and Regions>

26 The concept of the region is independent of the memory management policies implemented by the operating system. Memory management policy refers to the actions the kernel takes to insure that processes share main memory fairly. e.g. two memory management policies-process swapping and demand paging. The concept of the region is also independent of the memory management implementation. Whether the memory is divided into pages or segments.

27 Pages and Page Tables Memory model – page or segment. (not specific to the unix system) In a memory management architecture based on pages the memory management hardware divides physical memory into a set of equal sized blocks called pages. Typical page sizes range from 512 bytes to 4k byres and are defined by the hardware. Every addressable location in memory is contained in a page and Consequently, every memory location can be addressed by a (page number, byte offset in a page) pair.

28 for e.g.: If a machine has 2^32 bytes of physical memory and a page size of 1k bytes, it has 2^ 22 pages of physical memory, every 32 bit address can be treated as a pair consisting of a 22 bit page number and a 10 bit offset into the page. (refer Fig 3)

29 When the kernel assigns physical pages of memory to a region, it need not assign the pages contiguously or in a particular order. The purpose of paged memory is to allow greater flexibility in assigning physical memory analogous to the assignment of disk blocks to files in a file system.

30 Pages and Page Tables The kernel correlates the virtual addresses of a region to their physical machine addresses by mapping the logical page numbers in the region to the physical page numbers on the machine (Fig 4.) Since a region is a contiguous range of virtual addresses in a program, the logical page number is the index into an array of physical page numbers. The region table entry contains a pointer to a table of physical page numbers called a page table. Logical Page Number Physical Page Number

31 Pages and Page Tables (contd.)
8K 32K 64K Text Data Stack 541K 783K 986K 897K 87K 552K 727K 941K empty 137K 852K 764K . 1096K 2001K 433K 333K Per Proc Region Table Page Tables(Physical Addresses) Virtual Addresses <Mapping Virtual Addresses to Physical Address>

32 Rest of the topics in Chapter-6
6.3: Context of a Process 6.4 Saving Context of a Process 6.5 Region and related 7 algorithms 6.6 Sleep and Wakeup

33 6.3: Context of a Process User-level context Register-level context
System-level context

34 User-level Context Text Data User stack Shared memory
These may be in main memory or in the swap space

35 Register-level Context
Program counter Processor Status (PS) register Stack pointer General purpose registers

36 System-level Context Static part Dynamic part Process table entry
U area of a process Pregion entries, region tables, page tables: Dynamic part Kernel stack: Private copy of kernel stack (of a process) A set of layers Each system-level context layer contains necessary info to recover previous layer (including register-level context of previous layer)

37 Components of Process Context

38 Handling Interrupts

39 Example of Interrupts

40 Algorithm for System Call

41 Steps for a Context Switch

42 6.5 Algorithms on regions Alloc Region Attach region
Grow / Shrink region Load region Freeing region Detaching region Duplicating region

43 Region Table entry A ptr to the inode of the file whose content were originally load into the region Region type (text, data, ..) Region size Location of region in PhyMem Status: Locked, in demand, valid, being loaded into memory Ref count: # of processes referencing the region

44 Allocating a region

45 Example of Attaching an Existing Text Region

46 Changing region size

47 Example: Growing stack by 1K

48 Loading a region

49 Example: Loading a text region

50 Freeing a region

51 Detaching a region

52 Duplicating a region

53 Example: Duplicating a region

54 Sleep and Wakeup Processes sleep on Events
Events are mapped into addresses There are sleep queue based on sleep address

55

56 Sleep Alg. (1)

57 Sleep Alg (2)

58 Wakeup

59 Thank You


Download ppt "Structure of Processes"

Similar presentations


Ads by Google