DOC PREVIEW
UNO CSCI 8530 - Processes

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

The Tempo vm Operating System Part 2 Processes 1 Processes Threads 1 Fundamental executable object Currently these are really threads Each process instance has a struct Proc defined in h types h Most processes created by newproca syscall Idle process and first user process created at system startup 2 1 Processes Threads 2 Each process has a state PROCESS FREE unused struct Proc entry PROCESS READY process can run PROCESS CURRENT process is running Others process is blocked for some reason Each process has a priority between LOWEST PRIORITY and HIGHEST PRIORITY Each ready process on a FIFO queue based on its priority 3 Processes Threads 3 Each process identified by a unique int of type pid t called its process ID Each process has its own user mode stack Each process has a set of register values including general regs stack pointer and instruction pointer When running these are real registers When not running these are saved on a stack 4 2 Processes Threads 4 Each process runs in user or supervisor kernel privileged mode User mode used for normal processing Supervisor mode used during system calls When executing a system call a process uses a separate kernel stack 5 Understanding Stack Usage Understanding stack use is crucial to understanding process implementation In IA 32 stacks grow downward in memory Stack pointer register ESP identifies the top element on the stack PUSH decrements ESP by item size and stores an item POP extracts item and increments ESP by item size 6 3 Stack Frames 1 Each function call has a dedicated region of stack called its stack frame Bottom of stack frame or other fixed point in the frame pointed to by EBP register top pointed to by ESP register A C function call pushes arguments in reverse order and then the return address Called function pushes EBP copies ESP to EBP then decrements ESP by size of local variables 7 Stack Frames 2 To return a function places return value in EAX copies EBP to ESP pops EBP and executes the ret instruction which pops the return address into the EIP register GCC uses leave instruction which copies EBP to ESP and pops EBP The calling function then reclaims the stack space used by the arguments and deals with the returned value 8 4 Assembler Basics 1 Tempo assembler uses GNU assembler syntax also called AT T syntax Operands in opposite order from Intel syntax Register names prefixed with Constants prefixed with Comments prefixed with Opcodes suffixed with data type i e b w l Most instructions have two operands Examples movl 5 eax copies 5 to eax register subl eax ebx subtract eax from ebx 9 Assembler Basics 2 Memory references take the form disp base index scale disp is a constant or label of instr data base is a permitted register name index is another permitted register name scale is 1 2 4 or 8 default is 1 Result address is disp base index scale 10 5 Assembler Basics 3 Observations Accessing a parameter 8 ebp references the first 32 bit parameter 12 ebp reference the second 32 bit parameter Accessing a local variable 4 ebp references first local 32 bit variable 8 ebp reference second local 32 bit variable 0 ebp contains caller s ebp register value 4 ebp contains return address 11 Example C Program int f int a1 int a2 int temp temp a1 3 a2 temp return a1 5 main int x y z x 12 z f x y 12 6 Assembler Code for Example f pushl movl subl movl movl sall addl movl movl movl movl movl subl leave ret ebp esp ebp 4 esp 8 ebp edx edx eax eax edx eax eax 4 ebp 12 ebp edx 4 ebp eax eax edx 8 ebp eax 5 eax main pushl movl subl movl leal pushl pushl call addl movl leave ret ebp esp ebp 12 esp 12 4 ebp 8 ebp eax eax 4 ebp f 8 esp eax 12 ebp 13 Stack During Execution of f caller s EBP value main s EBP Storage for main s x Storage for main s y Storage for main s z Addr of main s y Value of main s x Return address from f main s EBP value f s EBP Storage for temp 14 7 Initial Stack for a Process 1 As just seen any function expects a return address at the bottom of the stack when it begins preceded by any arguments The Main function expects two arguments a count of the number of command line arguments usually called argc a pointer to an array with argc nullterminated strings followed by a null pointer these strings contain the command line args 15 Initial Stack for a Process 2 These stack contents are created when the process is created by the newproca system call The return address is to the function processDone which does nothing more than invoke the exit system call Stack space prior to Main s arguments is used for copies of the newproca caller s command line argument values 16 8 struct Proc 1 struct Proc tag t tag pid t pid Process next Process prev struct Queue queue int priority int state int stksize unsigned int stkbase unsigned int kstkbase int signaledOn 0 self identifying tag 4 unique process identification 8 next Proc on this Queue 12 previous Proc on this Queue 16 on which Queue is this Proc found 20 process priority 24 process state 28 user stack size pages 32 base of user stack from allocStack This is the address of the bottom word on the stack not like kstkbase 36 base of kernel stack 1 page always Address of 1st byte of NEXT page 40 which event queue was signaled 17 struct Proc 2 int timedOut Process dnext unsigned int delta unsigned int ksp pid t waitingon int exitstatus unsigned int eventaddr struct m header mfree struct EQ eventQueue NQUEUE struct FD fd NFD 44 set if process timed out 48 next Proc on the delta queue 52 clock ticks left before wakeup 56 kernel esp for ready blocked process 60 process whose termination is awaited 64 exit status of process waitingon 68 address of event for EVENT WAIT 72 address of free list malloc the event queues for the process fd i info for open file i 18 9 struct Proc Notes 1 next and prev are used to link a struct Proc on various queues as necessary queue points to the queue on which a process is linked signaledOn and timedOut are set when a process is signaled or a timer expires dnext links a process on a timer queue delta indicates clock ticks left to wait 19 struct Proc Notes 2 ksp records the kernel stack pointer for a process when it is ready or blocked waitingon identifies the process whose termination this process is awaiting if any exitstatus contains the value returned by a process through the exit system call eventQueue is an array of queues of messages and signals for the process 20 10 struct Proc Notes 3 Note that there is no parent child relationship among …


View Full Document

UNO CSCI 8530 - Processes

Download Processes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Processes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Processes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?