Software Systems Spring 2005 For today, you should have: 1) worked on Homework 2 2) prepared for a quiz Outline: 1) Homework 2 discussion 2) The process abstraction For next time you should: 1) finish Homework 2 2) read the winner of this week's best chapter competition, Andrew Tanenbaum. Tanenbaum is famous among computer scientists as the author of MINIX, which is the precursor of Linux. In the early days of Linux (1992, if you can believe it), Tanenbaum engaged in a now-famous debate with Linus Torvalds on several points of operating system design. The debate is documented at http://www.oreilly.com/catalog/opensources/book/appa.html Maybe we'll read it (when we are ready to appreciate it)... Homework 2 ---------- What have you seen so far? Why is the cartoon we drew last time not quite right? Do we have to adjust any parameters? The process abstraction ----------------------- What is a process? 1) a program while it is running 2) a program together with its data and hardware state If you have 3 windows running emacs, there are three processes running the same program. To get a list of processes: ps To get a list of _all_ processes: ps -ax To see which processes are using the most CPU: top (type m to sort by memory use) (and then q to exit) Multiprogramming/timesharing ---------------------------- Of all the programs "running" on your computer, only one is actually executing instructions. The others are suspended. The OS has the ability to 1) interrupt a running process, 2) save its state 3) resume a suspended process. This is called a "context switch", and it happens 10-1000 times a second. 1) If the number of processes that need CPU time is relatively small, and 2) they all get a reasonable share of the CPU, then 3) the system behaves as if the processes ran in parallel! A CPU model ----------- To run a program, you have to (somehow) get a program into memory, and load the addess of the beginning of the program into a special register called the PC (program counter). Then: 1) send the address in the PC to the memory model 2) get an instruction back and put it in the IR (instruction register) 3) decode the instruction and execute it, which may involve a) reading values from registers or memory b) performing aritmetic computations c) writing results to registers or memory d) changing the PC 4) increment the PC and go to (1) Why is booting called "booting"? As the CPU runs, it generated a sequence of memory reads and writes. Some of these accesses are intercepted by the caches, but this optimization is invisible to the running program. The address space ----------------- A process is a program PLUS data and hardware state. How is the data organized? Let's do an experiment. Download this program. wget wb/ss/code/address_space.tgz Read it, and run it... typedef struct { int num, den; } Rational; int global; void recurse (int n) { int a[4000]; Rational *rv = (Rational *) malloc (1000 * sizeof (Rational)); printf ("Address of a is 0x%x\n", &a[0]); printf ("Address of rv is 0x%x\n", rv); if (n > 0) recurse (n-1); } int main () { int x = 5; Rational *r1 = (Rational *) malloc (sizeof (Rational)); printf ("Address of x is 0x%x\n", &x); printf ("Address of global is 0x%x\n", &global); printf ("Address of main is 0x%x\n", main); printf ("Address of r1 is 0x%x\n", r1); recurse (1); return 0; }