Structure of Processes

Slides:



Advertisements
Similar presentations
Chapter 3 Process Description and Control
Advertisements

Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
Unix-v5 Process Structure
Structure of Processes
Memory Management Policies: UNIX
Introduction to Kernel
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
CSCE 351: Operating System Kernels
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Introduction to Processes CS Intoduction to Operating Systems.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Implementing Processes and Process Management Brian Bershad.
Chapter 4. INTERNAL REPRESENTATION OF FILES
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
The Structure of Processes (Chap 6 in the book “The Design of the UNIX Operating System”)
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
CS 390 Unix Programming Environment
1 UNIX – The Kernel. 2 UNIX Internals: Motivations Knowledge of UNIX Internals helps in: –understanding similar systems (for example, NT, LINUX) –designing.
1 Structure of Processes Chapter 6 Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM.
What is a Process ? A program in execution.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Introduction to Kernel
Memory Management.
Processes and threads.
Process Management Process Concept Why only the global variables?
Structure of Processes
Lecture Topics: 11/1 Processes Process Management
Modeling Page Replacement Algorithms
Operating Systems: A Modern Perspective, Chapter 6
Processes A process is a running program.
Intro to Processes CSSE 332 Operating Systems
Processes in Unix, Linux, and Windows
KERNEL ARCHITECTURE.
Structure of Processes
Operating System Concepts
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
System Structure and Process Model
Main Memory Background Swapping Contiguous Allocation Paging
Modeling Page Replacement Algorithms
Process Description and Control
Lecture 3: Main Memory.
Processes Hank Levy 1.
Operating System Chapter 7. Memory Management
Processes and Process Management
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Chapter 8: Memory Management strategies
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix and Windows
System calls….. C-program->POSIX call
Process Description and Control in Unix
CSE 153 Design of Operating Systems Winter 2019
Processes Hank Levy 1.
Process Description and Control in Unix
Memory Management and I/O Subsystem
COMP755 Advanced Operating Systems
Internal Representation of Files
Mr. M. D. Jamadar Assistant Professor
Presentation transcript:

Structure of Processes Mr. M D Jamadar

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

(swapping system only) 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

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

Data Structures for Process

Data Structure for Process (contd.) u area main memory Kernel process table per process region table Kernel region table

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 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.

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. 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

Layout of System Memory A process on the UNIX system consist of three logical sections Text Data (shared memory is considered as a part of data section) Stack The text section contains the set of instruction the machine executes for the process; address in the text section includes text addresses (for branch instructions or subroutine calls),data addresses (for access to global data variables), or stack addresses (for access to data structures local to a subroutines) The compiler generates addresses for a virtual address space with given address range, and the machine memory’s memory management unit translates the virtual addresses into physical memory The subsystem of the kernel and the hardware that cooprate to translate virtual to physical addresses comprise the memory management subsystem

<Processes and Regions> The System V kernel divides the virtual address space of a process into 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. Text, data and stack usually form separate regions of a process Several process can share a region and may execute the same program and they share one copy of text region and also may cooperate to share a common shared memory region. The kernel contains a region table and allocates an entry from the table for each active region in the system Each process contains a private per process region table (U area or a part of process table entry) 8K 16K 32K b a d c e 4K Text Data Stack Process A B Per Proc Region Tables (Virtual Addresses) Region <Processes and Regions>

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

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: number of processes referencing the region

Pages and Page Tables In memory management architecture based on pages, the memory management hardware divides physical memory into a set of equal sized blocks called pages. Page sizes range from 512 bytes to 4K bytes and are defined by the hardware. Every addressable memory is contained in a page and every memory location can be addressed by a 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 (page number, byte offset in page)

Pages and Page Tables Logical Page Number Physical Page Number 0 177 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> Logical Page Number Physical Page Number 0 177 1 54 2 209 3 17 Figure shows a sample mapping of a process into physical memory Assume that the size of a page is 1K bytes, and suppose the process wants to access virtual memory address 68,432 The pregion entry shows that the virtual address is in the stack region(stack starts at 64K=64*1024=65536) Subtracting, address 68432 is at byte offset 2896 in the region As each page consist of 1K bytes, the address is contained at byte offset 848 in page 2 (counting from 0) of the region, located at physical address 986K

Layout of the Kernel The virtual mapping associated with the kernel is independanat of all processes. The code and data resides in the system permanently, and all processes share it. When the system is booted, it loads the kernel code into memory and sets up the necessary tables and registers to map its virtual addresses into physical memory addresses. The mechanism used t map kernel virtual addresses are similar to those used for user addresses. The virtual address space of a process is divided into several classes, including system and user, and each class has its own page tables. When executing kernel mode, the system permits access to kernel addresses, but it prohibits such when executing in user mode.

Manipulation of process address space Locking and unlocking a region Allocating a region Attaching a region to process Changing the size of a region Loading the region Freeing a region Detaching a region from process Duplicating a region

Allocating a region The kernel allocates a new region(algorithm allocreg) during fork, exec, and shmget system calls. The kernel contains a region table whose entries appears either on free linked list or on an active linked list. When it allocates a region table entry, the kernel removes the first available entry from the free list, places it on the active list, locks the region, and marks its type (shared or private). With few exceptions, every process is associated with an executable file as a result of a prior exec call, and allocreg sets the inode field in the region table entry to point to the inode of executable file. Increases reference count of inode

Attaching a region to process The kernel attaches a region during the fork, exec, and shmat system calls to connect it to the address space of a process. The region may be a newly allocated region or an existing region thet the process will share with other processes. The kernel allocates a free pregion entry, sets its type field to text, data or stack or shared memory, and records the virtual address where the region will exist in the process address space. The process must not exceed the system imposed limits for the highest vitual address, and the virtual addresses of new region must not overlap addresses of the existing regions. Attachreg then initializes a new set of memory management register triples for the process: If the region is not already attached to another process, the kernel allocates page table for it in subsequent call to grow region Finally Attachreg returns a pointer to the pregion entry for the newly attached region

Changing the size of a region

Loading the region

Freeing a region

Detaching a region from process

Duplicating a region

Context of a Process The context of a process consists of the contents of its address space and the contents of hardware registers and kernel data structures that relate to the process. The context of a process is the union of following User-level context Register-level context System-level context

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

Register-level Context Program counter (address of next instruction to be executed) Processor Status (PS) register Specifies the hardware status of the machine Usually contains subfields to indicate that the result of a recent computation resulted in 0, positive or negative or that registered overflowed and so on Stack pointer Contains the current address of the next entry in the kernel or user stack General purpose registers Contains data generated by the process during its execution

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)

Components of context of a process

Saving the context of a process Interrupts and exception System call interface Context Switch

Interrupts and exception

Context Switch Context switch under four circumstances: When a process puts its self to sleep When it exits When it return from system call to user mode When it returns to user mode after the kernel completes handling an interrupt

Sleep and Wakeup

Algorithm for sleep

Algorithm for wakeup