##################################################### ## ## [CS5600] Computer Systems ## Summary of the lecture ## ## Lecture 2 - Processes ## Prof. Peter Desnoyers ## Date & Time : 9/15/2010, 6pm-7pm (1st session) ## ##################################################### 1. Process Concept (1) What is a process? A process is a running program. (a program in excution) The processor is going through its executing instructions from the compiled program. (2) Process layout on memory Classic organization of a process : code / data / heap / stack - code : a compiled program - data : (ex) global variables - heap : (ex) malloc() new dynamically allocated memory a pool of a memory that you can expand to use - stack : (ex) return address, local variables live on the stack This is how we use a recursive function. At any point of time, we can see a function's stack telling where it's called from. (3) Process State Various linked lists with control blocks : - current - active - wait (4) Process Control Block (PCB) A general structure of the process See Fig. 3.3 2. Process Scheduling : How to switch between multiple processes Now, let's think about multiple programs running at the same time. - How to decide what process we should run at a certain point of time? - How should we switch from one to another one? - How to fit processes to a memory? - How to allocate memory for multiple processes? (ex) Editor : while true get key update screen While P1 is waiting for a key input, P2 cannot do anything but stay on a memory and wait. So, context switching is a solution to take advantage of effect of efficienct cpu use. (1) Context switching - Program counter (PC) : an address of the current instruction executed. register of CPU - Stack pointer (SP) : a pointer to memory to push&pop data Switch function abstraction : switch(old, new) save sp -> old sp = new return Every process is called by switch previously. (don't worry about the beggining.) It's like a central hub. (goes out again, enters back again, ...) At any point of time, only one process is running. All other processes are blocked (switch) staying on memory. (2) Multitasking A. Cooperative multitasking (no preemption) B. Preemptive multitasking (assigns the processes a priority.) - The O/S checks the current scheduling everytime returning from interrupt to see if it should change a process.