The structure of a process

Please download to get full document.

View again

of 72
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Similar Documents
Information Report
Category:

Education

Published:

Views: 0 | Pages: 72

Extension: PDF | Download: 0

Share
Description
Process states and transitions fields of u area and process table Layout of system memory-regions, pages and page table, layout of the kernel, u area The context of a process saving the context of a process algorithm inthand and syscall, context switch, saving context for abortive returns Manipulation of the process address space- fields of region,locking and unlocking region Algorithms allocreg, attachreg, growreg, loadreg, freereg, detachreg and dupreg Sleeping and wakeup of process algorithm sleep
Transcript
  • 1. 5. The structure of a process Process states and transitions  fields of u area and process table Layout of system memory-regions, pages and page table, layout of the kernel, u area The context of a process saving the context of a process algorithm inthand and syscall,  context switch, saving context for abortive returns Manipulation of the process address space- fields of region,locking and unlocking region Algorithms allocreg, attachreg, growreg, loadreg, freereg, detachreg and dupreg Sleeping and wakeup of process algorithm sleep
  • 2. Process States an transition
  • 3. Process states 1. The process is executing in user mode. 2. The process is executing in kernel mode. 3. The process is currently not executing but it is in “READY TO RUN” state as soon as the kernel schedules it. 4. The process is sleeping but it is present in main memory. 5. The process is “READY TO RUN”, but the swapper (process 0) must swap the process into main memory before the kernel can schedule it to execute. 6. The process is sleeping ,and the swapper has swapped the process to secondary storage to male room for other processes in main memory. 7. The process is returning from the kernel to user mode ,but the kernel pre-empts it and does a context switch to schedule another process. The distinction between this state and state 3 will be brought out shortly.
  • 4. 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. 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 statistics for its parent process to collect .The zombie state is the final state of a process.
  • 5. The fields in the process table are the following 1.The state field identifies the process state. 2.The process table entry contains fields that allow the kernel to locate the process and its u area in main memory or in secondary storage. The kernel uses the information to do a context switch to the process when the process moves from state “ready to run in memory” to the state “kernel running” or from the state “pre-empted” to the state “user running”. In addition ,it uses this information when swapping (or paging) processes to and from main memory (between the two “in memory” states and the two “swapped “ states).The process table entry also contains a field that gives the process size, so that the kernel knows how much space to allocate for the process.
  • 6. 3. Several user identifiers (user ID or UIDs) determine various process privileges. For example, the user ID fields delineate the sets of processes that can send signals to each other . 4.Process identifiers (process IDs or PIDs) specify the relationship of processes to each other. These ID fields are set up when the process enters the state "created" in the fork system call. 5. The process table entry contains an event descriptor when the process is in the "sleep" state.
  • 7. 6. Scheduling parameters allow the kernel to determine the order in which processes move to the states "kernel running" and "user running." 7. A signal field enumerates the signals sent to a process but not yet handled 8.Various timers give process execution time and kernel resource utilization, used for process accounting and for the calculation of process scheduling priority. One field is a user-set timer used to send an alarm signal to a process
  • 8. The fields in the u area are the following 1. A pointer to the process table identifies the entry that corresponds to the u area. 2. The real and effective user IDs determine various privileges allowed the process, 3. such as file access rights (see Section 7.6). 4. Timer fields record the time the process (and its descendants) spent executing in 5. user mode and in kernel mode. 6. An array indicates how the process wishes to react to signals. 7. The control terminal field identifies the "login terminal" associated with the 8. process, if one exists, 9. An error field records errors encountered during a system call.
  • 9. 10. A return value field contains the result of system calls. 11. I/O parameters describe the amount of data to transfer, the address of the source (or target) data array in user space, file offsets for I/0, and so on. 12. The current directory and current root describe the file system environment of the process. 13. The user file descriptor table records the files the process has open.
  • 10. Layout of system memory  A process when loaded in memory ,has three parts text, data and stack. The “TEXT” section consists of binary- formed addresses of instructions. The “DATA” section consists of addresses of global data variables. The “STACK” section consists of addresses of local data variables functions.  When compiler compiles source code of a program, it creates above addresses of “VIRTUAL MACHINE” .Means these addresses are machine independent and thus irrespective of machine’s actual physical memory. So compiler generated addresses are for “VIRTUAL ADDRESS SPACE” having some finite range 0 to some compiler limited value
  • 11.  The physical memory is also finite ranged ,from 0 to the max byte offset equal to the amount of memory on the machine, minus 1.  It is the duty of operating system (OS) to convert “COMPILER GIVEN” virtual addresses in to actual physical addresses . The part of the OS i.e. the part of the kernel, which does this translation of “VIRTUAL ADDRESSES” to “ACTUAL PHYSICAL ADDRESSES", is called as “MEMORY MANAGEMEN SUBSYSEM”  Several instances of one program may exist at a time.As compiler generated virtual addresses are same for all theses instances, kernel has to map every “INSTANCE ADDRESS” at different physical location in RAM so that all instances will run independently.
  • 12.  Though several instances of same program co-exists, it does not mean that Text, Data and stack parts of all these instances are separate .Tex and Data have unique place for all above instances but local data (i.e. stack) and local functions are separate for every instance
  • 13. Regions  UNIX SYSTEM V divides “COMPILER GIVEN VIRTUAL ADDRESSS SPACE” in to logical space known as regions.  Regions is a contiguous area of a process, so if a process has Text ,Data and stack parts, there will be “TEXT REGION “ of common process in to memory of other processes. This is called as sharing of a region.
  • 14. Data Structures of a process The U area  When the system is installed, its source code is compiled and loader created a variable called as “U” which is the name of “U AREA". Compiler also gives a fixed virtual address to it. Kernel dynamically tell memory management system to map “U AREA’S VIRTUAL ADDRESS” to some other physical memory location.  Every process when gets executed has its own private “U AREA". It also has some “VIRTUAL ADDRESS” and corresponding mapped “PHYSICAL ADDRESS” too.
  • 15.  When process enters in kernel mode ,kernel maps its global virtual address of “U AREA” to physical memory address of process’s local “U AREA” ,by telling the previously mentioned part of memory management system.
  • 16. Per Process region table  This contains pointer to the “REGION TABLE” entry of this process .  This data structure is local to every process.  As it contains pointer to region table entry of this process ,it has addresses of Text, Data and stack part of this process.  “PER PROCESS REGION TABLE” is called as pregion for the sake of simplicity.
  • 17. The process table This is global, process table contains pointer to “PER PROCESS REGION TABLE” entry of this process. this entry is called as pregion entry. This entry contains 2 things…. 1. Pointer of “REGION TABLE” entry ,which in turn contains starting virtual address of text, Data and stack regions of this process. 2. A permission field ,which indicates the type of access given to the process. Thus it has one of the three values “READ ONLY”,”READ-WRITE” and “READ-EXECUTE”.
  • 18. Context of a process The context of process is the union of its user-level context ,register context and system-level context. User-level context User level context consist of ... The user-level context consists of the process text, data, user stack, and shared memory that occupy the virtual address space of the process. Parts of the virtual address space of a process that periodically do not reside in main memory because of swapping or paging stilt constitute a part of the user-level context.
  • 19. Register-level context Register level context consist of ... The program counter specifies the address of the next instruction the CPU will execute; the address is a virtual address in kernel or in user memory space. The processor status register (PS) specifies the hardware status of the machine as it relates to the process. PS contains sub fields which indicate.... 1. whether the result of a recent computation resulted in a zero, positive or negative result. 2.Whether that a register overflowed and a carry bit is set. 3. the current processor execution level (for interrupts) 4. the current and most recent modes of execution (such as kernel, user)
  • 20. The stack pointer contains the current address of the next entry in the kernel or user stack, determined by the mode of execution.  The general-purpose registers contain data generated by the process during its execution.
  • 21. System-level context System level context of a process has a “static part” and a “dynamic part” ... Static part includes.....  The process table entry .As global it is accessible to kernel. The U area of the process. Pregion entries, region tables and page tables. If several processes share common regions, the regions are considered part of the context of each process, because each process manipulates the regions independently. Which part of the process’s address space is not residing in main memory(if any). The kernel stack contains stack frames of kernel’s procedures done during the process in “KERNEL MODE”.
  • 22. Dynamic part includes..... The kernel stack contains stack frames of kernel’s procedures done during the process in “KERNEL MODE”.  A set of layers ,visualized as a last-in-first out each system level context layer contains the necessary information to recover the previous layer, including the resister context of previous level.
  • 23. Process of context switch The kernel pushes a context layer when an interrupt occurs, when a process makes a system call, or when a process does a context switch.  kernel pops a context layer when the kernel returns from handling an interrupt, when a process returns to user mode after the kernel completes execution of a system call, or when a process does a context switch. Kernel always pushes the context layer of new process and pops the context layer of new process.  All things are possible because process’s “PROCESS TABLE” stores the necessary information to recover the current context layer. A process runs within its current context layer.
  • 24. The number of context layers depends upon… a) How many interrupts level are supported by machine. b) One layer for system calls c) One layer for “user level context” For instance.... if a machine supports different interrupt levels for software interrupts, terminals, disks, all other peripherals, and the clock, it supports 5 interrupt levels, and hence, a process can contain at most 7 context layers: 1 for each interrupt level, I for system calls, and 1 for user-level. The 7layers are sufficient to hold all context layers even if interrupts occur in the "worst“ possible sequence, because an interrupt of a given level is blocked (that is, the CPU defers it) while the kernel handles interrupts of that level or higher.
  • 25. Saving the context of a pocess the kernel saves the context of a process whenever it pushes a new system context layer. Saving of context layer happens when..... 1. the system receives an interrupt. 2. when a process executes a system call . 3. when the kernel does a context switch.
  • 26. 1. Interrupts and exceptions The system is responsible for handling interrupts, whether they result from hardware(such as clock), from a programmed Interrupt(i.e. Software interrupts), or from exceptions (such as page faults). If the CPU is executing at a lower processor execution level than the level of the interrupt, it accepts the interrupt before decoding the next instruction and raises the processor execution level, so that no other interrupts of that level (or lower) can happen while it handles the current interrupt, preserving the integrity of kernel data structures
  • 27. The handling of interrupts occurs in following sequence… 1. Kernel saves the current register context of the executing process and creates (pushes) a new context layer. 2. Then It determines the "source" or cause of the interrupt, identifying the type of interrupt (such as clock or disk) and the unit number of the interrupt . When the system receives an interrupt, it gets a number from the machine that it uses as an offset into a table, commonly called an interrupt vector.
  • 28. The contents of interrupt vectors vary from machine to machine. usually it contain ...... -> Interrupt number -> the address of the interrupt handler for the corresponding interrupt source -> a way of finding a parameter for the interrupt handler 3. The kernel invokes the interrupt handler and completes the task of desired function of desired function of the interrupt. 4. The kernel executes a machine-specific sequence of instructions that restores the register context and kernel stack of the previous context layer as they existed at the time of the interrupt and then resumes execution of the restored context layer.
  • 29. Algorithm for handling Interrupts(inthand)
  • 30. 2. System call interface The C compiler uses a predefined library of functions (the C library) that have the names of the system calls. The library functions typically invoke an instruction(i.e. operating system trap) that changes the process execution mode to kernel mode and causes the kernel to start executing code for system calls. The library functions pass the kernel a unique number per system call. Passing of this unique number takes place by one of the 2 ways.. a) Either as a parameter to instruction b) or on the stack. Kernel thus determines the specific system call user is invoking.
  • 31. Handling of “Operating system trap” by kernel occurs in following sequence… 1. kernel looks up the system call number in a table to find the address of the appropriate kernel routine that is the entry point for the system call and to find the number of parameters the system call expects. 2. The kernel calculates the (user) address of the first parameter to the system call by adding (or subtracting, depending on the direction of stack growth) an offset to the user stack pointer, corresponding to the number of parameters to the system call. 3. Then it copies the user parameters to the u area and calls the appropriate system call routine.
  • 32. 4. after executing the code for the system call, the kernel determines whether there was error. a) If there is error, it adjusts register locations in the saved user register context, typically setting the "carry" bit for the PS register and copying the error number into the register 0 location. b) there were no errors in the execution of the system call, the kernel clears the "carry" bit in the PS register and copies the appropriate return values from the system call into the locations for registers 0 and 1 in the saved user register context.
  • 33. Algorithm to handle system calls syscall()
  • 34. When the kernel returns from the operating system trap to user mode, it returns to the library instruction after the trap. The library interprets the return values from the kernel and returns a value to the user program.
  • 35. Context switch kernel permits a context switch under four circumstances… 1. when a process puts itself to sleep 2. when process exits 3. When a process returns from a system call to user mode but is not the most eligible process to run 4. when it returns to user mode after the kernel completes handling an interrupt but is not the most eligible process to run.
  • 36. While making “context switch” kernel strongly maintains integrity of its data structures by … 1. prohibiting arbitrary context switch. 2. all appropriate update of kernel’s data structures are properly done, that queues are properly linked. 3. Appropriate locks are set so as to prevent other processes to use same resource. 4. Ensuring that no un-necessary data structures are locked.
  • 37. Process of context switch 1. Decide whether to do a context switch (i.e. whether one of the four situations arrived or not) also decide ,whether the context switch is permissible or not . 2. Save context of “OLD” process . 3. Find the best process to schedule for execution using “PROCESS SCHEDULING ALGORITHM” . 4. And restored the context of that best process.
  • 38. Saving context for abortive returns  Situations arise when the kernel must abort its current execution sequence and immediately execute out of a previously saved context.  The algorithm to save a context is setjmp and the algorithm to restore the context is longjmp. The setjmp() algorithm stores the saved context in process’s U area and continues to execute in the old context layer.  When kernel wants to resume to the previously saved context, it uses longjmp(), which restores its context from U area.
  • 39. Copying of data between user address space And kerenel address space A process executes in kernel mode or in user mode with no overlap of modes. many system calls move data between kernel and user space, such as when copying system call parameters from user to kernel space or when copying data from I/O buffers in the read system call. Many machines allow the kernel to reference addresses in user space directly. Kernel must ensure that the address, which is going to be read, or which is going to be written ,must lie within a specified address space range. Otherwise page fault or exception may occur
  • 40. Manipulation of process’s address space Many system calls manipulate virtual address space of process . Manipulation of virtual address space includes operations on regions as... 1. Locking and Unlocking a region 2. Allocating region 3. Attaching a region to a process 4. Changing a size of a region 5. Loading a region 6. Freeing a region 7. Detaching a region for a process 8. Duplicating region
  • 41. Memory management triples for a process There are two sets of memory management triples, one for kernel addresses and one for user addresses, and each triple points to a page table that contains the physical page numbers corresponding to the virtual page addresses. The system allows address references via the kernel register triples only when in kernel mode; hence, switching mode between kernel and user requires only that the system permit or deny address references via the kernel register triples.
  • 42. 1. Locking and Unlocking a region  The kernel has operations to lock and unlock a region, independent of the operations to allocate and free a region.  The kernel can lock and allocate a region and later unlock it without having to free the region.  If it wants to manipulate an allocated region, it can lock the region to prevent access by other processes and late
  • Recommended
    We Need Your Support
    Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

    Thanks to everyone for your continued support.

    No, Thanks
    SAVE OUR EARTH

    We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

    More details...

    Sign Now!

    We are very appreciated for your Prompt Action!

    x