Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Operating Systems - A Primer<br />
Introduction<br />
# who am i<br />Saumil Shah<br />CEO Net-square.<br />Hacker, Speaker, Trainer, Author.<br />M.S. Computer Science<br />Pu...
Preview<br />
CPU and Registers<br />
The CPU<br />We shall discuss the Intel x86 32-bit CPU.<br />
The CPU<br />We shall discuss the Intel x86 32-bit CPU.<br />The CPU has REGISTERS.<br />
The CPU<br />We shall discuss the Intel x86 32-bit CPU.<br />The CPU has REGISTERS.<br />"Variables" on the CPU, hard-wire...
What do Registers do?<br />
What do Registers do?<br />Registers hold data.<br />
What do Registers do?<br />Registers hold data.<br />They may be numbers...<br />...or memory addresses (pointers)<br />
What do Registers do?<br />Registers hold data.<br />They may be numbers...<br />...or memory addresses (pointers)<br />Us...
x86 Registers - the basics<br />EAX<br />ESI<br />EBX<br />EDI<br />ECX<br />ESP<br />EDX<br />EBP<br />EIP<br />EFLAGS<br...
x86 Registers - General Purpose<br />EAX<br />Accumulator<br />EBX<br />Base<br />ECX<br />Count<br />EDX<br />Data<br />
x86 Registers - General Purpose<br />EAX<br />Accumulator<br />EBX<br />Base<br />ECX<br />Count<br />EDX<br />Data<br />U...
x86 Registers - Pointers<br />ESI<br />Source Index<br />EDI<br />Destination Index<br />
x86 Registers - Pointers<br />ESI<br />Source Index<br />EDI<br />Destination Index<br />These are POINTERS, used for bloc...
x86 Registers - Stack Related<br />Stack Pointer<br />ESP<br />Frame Pointer (Base Pointer)<br />EBP<br />
x86 Registers - Stack Related<br />Stack Pointer points to the top of the process stack.<br />Stack Pointer<br />ESP<br />...
x86 Registers - Stack Related<br />Stack Pointer points to the top of the process stack.<br />Stack Pointer<br />ESP<br />...
x86 Registers - EIP<br />EIP<br />Instruction Pointer (program counter)<br />
x86 Registers - EIP<br />A very important register. Points to a memory address from where the CPU fetches and executes the...
x86 Registers - Flags<br />EFLAGS<br />Bit Flags<br />
x86 Registers - Flags<br />Individual bits indicate status of operations. Boolean values. Never treated as a full register...
Operating System Basics<br />
The Operating System<br />Modern Operating Systems are very complex and do many things.<br />We shall discuss only the bas...
The Operating System<br />Modern Operating Systems are very complex and do many things.<br />We shall discuss only the bas...
What is Multiprogramming?<br />
What is Multiprogramming?<br />The ability to store and execute multiple programs in the memory<br />
What is Multiprogramming?<br />The ability to store and execute multiple programs in the memory<br />...and what is Multit...
What is Multiprogramming?<br />The ability to store and execute multiple programs in the memory<br />...and what is Multit...
So what is a "Process"?<br />
So what is a "Process"?<br />A PROCESS is termed as a program that is EXECUTING. A running program.<br />
So what is a "Process"?<br />A PROCESS is termed as a program that is EXECUTING. A running program.<br />A process is an i...
How do multiple processes run simultaneously?<br />
How do multiple processes run simultaneously?<br />By TIME SLICING and CONTEXT-SWITCHING<br />
How do multiple processes run simultaneously?<br />By TIME SLICING and CONTEXT-SWITCHING<br />Each process runs for a shor...
Processes and Multitasking<br />
Multitasking<br />Process Queue<br />P2<br />P3<br />P4<br />P1<br />CPU<br />Process P1 is running. It shall continue to ...
Multitasking<br />P2<br />P3<br />P4<br />P1<br />Time Slice<br />Interrupt<br />CPU<br />An INTERRUPT is triggered at the...
Multitasking<br />P2<br />P3<br />P4<br />P1<br />CPU<br />P1 is then PRE-EMPTED. It is brought back into the process queu...
Multitasking<br />P2<br />P3<br />P4<br />P1<br />CPU<br />It is P2's turn now. P2's context is loaded into the CPU's regi...
Multitasking<br />P1<br />P3<br />P4<br />P2<br />CPU<br />P2 is scheduled to execute on the CPU.<br />
Multitasking<br />P1<br />P3<br />P4<br />P2<br />CPU<br />P2 runs for the next quantum.<br />
Multitasking<br />P1<br />P3<br />P4<br />P2<br />Time Slice<br />Interrupt<br />CPU<br />P2's context is now saved.<br />
Multitasking<br />P1<br />P3<br />P4<br />P2<br />CPU<br />P2 is PRE-EMPTED. It is brought back into the process queue. Ne...
Virtual Machines and Process Memory Maps<br />
What is a Virtual Machine?<br />
What is a Virtual Machine?<br />A view of ABSTRACTED HARDWARE as presented to a PROCESS by the OS.<br />
What is a Virtual Machine?<br />A view of ABSTRACTED HARDWARE as presented to a PROCESS by the OS.<br />A process sees its...
Do processes have their OWN view of the memory?<br />Yes. Processes see "Virtual Memory"<br />
Do processes have their OWN view of the memory?<br />Yes. Processes see "Virtual Memory"<br />Physical memory is divided i...
Pages from P1's memory are mapped from physical memory. P1 sees a "virtual address space".<br />Physical Memory<br />P1's ...
Physical and Virtual Memory<br />Similarly for P2.<br />Physical Memory<br />P1's memory<br />P2's memory<br />
Can one process access another's memory?<br />No. A process can only access its own virtual memory space.<br />
Can one process access another's memory?<br />No. A process can only access its own virtual memory space.<br />A process C...
The Process' view of memory<br />Process Memory has its own VIRTUAL ADDRESS SPACE. Typically 2 to 3 GB.<br />Binary<br />H...
Linux Process Memory Map<br />0x08000000<br />Binary<br />Heap<br />Lib<br />3GB<br />Lib<br />Lib<br />Stack<br />0xbffff...
An example<br />Here's how to view a process' memory map in Linux. The process here is PID 1110.<br />saumil@localhost:$ p...
The Big Picture<br />
CPU<br />NIC<br />Storage<br />Physical Memory<br />
File System<br />Network Stack<br />Scheduler<br />MMU<br />Driver<br />Driver<br />CPU<br />NIC<br />Storage<br />Physica...
kernel space<br />System Calls<br />File System<br />Network Stack<br />Loader<br />Scheduler<br />MMU<br />Driver<br />Dr...
user space<br />Virtual Memory<br />PROCESS<br />Virtual Memory<br />PROCESS<br />Virtual Memory<br />PROCESS<br />CPU<br ...
user space<br />Virtual Memory<br />PROCESS<br />Virtual Memory<br />PROCESS<br />Virtual Memory<br />PROCESS<br />CPU<br ...
Key Concepts<br />
Review<br />
END<br />
Upcoming SlideShare
Loading in …5
×

Operating Systems - A Primer

24,063 views

Published on

A quick introduction to Operating Systems and how OSes support process execution.

Published in: Technology

Operating Systems - A Primer

  1. 1. Operating Systems - A Primer<br />
  2. 2. Introduction<br />
  3. 3. # who am i<br />Saumil Shah<br />CEO Net-square.<br />Hacker, Speaker, Trainer, Author.<br />M.S. Computer Science<br />Purdue University.<br />Google: "saumil"<br />LinkedIn: saumilshah<br />
  4. 4. Preview<br />
  5. 5. CPU and Registers<br />
  6. 6. The CPU<br />We shall discuss the Intel x86 32-bit CPU.<br />
  7. 7. The CPU<br />We shall discuss the Intel x86 32-bit CPU.<br />The CPU has REGISTERS.<br />
  8. 8. The CPU<br />We shall discuss the Intel x86 32-bit CPU.<br />The CPU has REGISTERS.<br />"Variables" on the CPU, hard-wired.<br />Size is equal to the "machine word". (32 bits)<br />
  9. 9. What do Registers do?<br />
  10. 10. What do Registers do?<br />Registers hold data.<br />
  11. 11. What do Registers do?<br />Registers hold data.<br />They may be numbers...<br />...or memory addresses (pointers)<br />
  12. 12. What do Registers do?<br />Registers hold data.<br />They may be numbers...<br />...or memory addresses (pointers)<br />Using registers, the CPU can perform computations, read and write memory, and execute instructions.<br />
  13. 13. x86 Registers - the basics<br />EAX<br />ESI<br />EBX<br />EDI<br />ECX<br />ESP<br />EDX<br />EBP<br />EIP<br />EFLAGS<br />there are more, but this is good enough for now.<br />
  14. 14. x86 Registers - General Purpose<br />EAX<br />Accumulator<br />EBX<br />Base<br />ECX<br />Count<br />EDX<br />Data<br />
  15. 15. x86 Registers - General Purpose<br />EAX<br />Accumulator<br />EBX<br />Base<br />ECX<br />Count<br />EDX<br />Data<br />Used for Integer operations (arithmetic), returning values (EAX), loops (ECX), or anything the compiler wishes to use them for.<br />
  16. 16. x86 Registers - Pointers<br />ESI<br />Source Index<br />EDI<br />Destination Index<br />
  17. 17. x86 Registers - Pointers<br />ESI<br />Source Index<br />EDI<br />Destination Index<br />These are POINTERS, used for block copy operations.<br />ESI = address of source, EDI = address of destination, ECX = count of bytes/words to be copied.<br />
  18. 18. x86 Registers - Stack Related<br />Stack Pointer<br />ESP<br />Frame Pointer (Base Pointer)<br />EBP<br />
  19. 19. x86 Registers - Stack Related<br />Stack Pointer points to the top of the process stack.<br />Stack Pointer<br />ESP<br />Frame Pointer (Base Pointer)<br />EBP<br />
  20. 20. x86 Registers - Stack Related<br />Stack Pointer points to the top of the process stack.<br />Stack Pointer<br />ESP<br />Frame Pointer (Base Pointer)<br />EBP<br />Frame pointer points to FRAMES within the stack. Frames store data for functions.<br />
  21. 21. x86 Registers - EIP<br />EIP<br />Instruction Pointer (program counter)<br />
  22. 22. x86 Registers - EIP<br />A very important register. Points to a memory address from where the CPU fetches and executes the next instruction. EIP autoincrements after every instruction.<br />EIP<br />Instruction Pointer (program counter)<br />
  23. 23. x86 Registers - Flags<br />EFLAGS<br />Bit Flags<br />
  24. 24. x86 Registers - Flags<br />Individual bits indicate status of operations. Boolean values. Never treated as a full register, just individual bit flags.<br />EFLAGS<br />Bit Flags<br />
  25. 25. Operating System Basics<br />
  26. 26. The Operating System<br />Modern Operating Systems are very complex and do many things.<br />We shall discuss only the basic concepts and functions of an OS.<br />
  27. 27. The Operating System<br />Modern Operating Systems are very complex and do many things.<br />We shall discuss only the basic concepts and functions of an OS.<br />Multitasking and Multiprogramming<br />Processes<br />The Virtual Machine<br />
  28. 28. What is Multiprogramming?<br />
  29. 29. What is Multiprogramming?<br />The ability to store and execute multiple programs in the memory<br />
  30. 30. What is Multiprogramming?<br />The ability to store and execute multiple programs in the memory<br />...and what is Multitasking?<br />
  31. 31. What is Multiprogramming?<br />The ability to store and execute multiple programs in the memory<br />...and what is Multitasking?<br />Running multiple PROCESSES at the SAME TIME.<br />
  32. 32. So what is a "Process"?<br />
  33. 33. So what is a "Process"?<br />A PROCESS is termed as a program that is EXECUTING. A running program.<br />
  34. 34. So what is a "Process"?<br />A PROCESS is termed as a program that is EXECUTING. A running program.<br />A process is an instance of a program.<br />Processes "live" in memory.<br />Programs live on disk. (secondary storage)<br />A program may have multiple processes of its own self.<br />
  35. 35. How do multiple processes run simultaneously?<br />
  36. 36. How do multiple processes run simultaneously?<br />By TIME SLICING and CONTEXT-SWITCHING<br />
  37. 37. How do multiple processes run simultaneously?<br />By TIME SLICING and CONTEXT-SWITCHING<br />Each process runs for a short time and is then PRE-EMPTED to let another process run.<br />This happens so fast, it appears as if all processes are running simultaneously.<br />This is called MULTITASKING<br />
  38. 38. Processes and Multitasking<br />
  39. 39. Multitasking<br />Process Queue<br />P2<br />P3<br />P4<br />P1<br />CPU<br />Process P1 is running. It shall continue to run for a small period of time, called a QUANTUM.<br />
  40. 40. Multitasking<br />P2<br />P3<br />P4<br />P1<br />Time Slice<br />Interrupt<br />CPU<br />An INTERRUPT is triggered at the end of the quantum. A snapshot of P1's registers (P1's CONTEXT) is saved.<br />
  41. 41. Multitasking<br />P2<br />P3<br />P4<br />P1<br />CPU<br />P1 is then PRE-EMPTED. It is brought back into the process queue.<br />
  42. 42. Multitasking<br />P2<br />P3<br />P4<br />P1<br />CPU<br />It is P2's turn now. P2's context is loaded into the CPU's registers. This is called CONTEXT SWITCHING.<br />
  43. 43. Multitasking<br />P1<br />P3<br />P4<br />P2<br />CPU<br />P2 is scheduled to execute on the CPU.<br />
  44. 44. Multitasking<br />P1<br />P3<br />P4<br />P2<br />CPU<br />P2 runs for the next quantum.<br />
  45. 45. Multitasking<br />P1<br />P3<br />P4<br />P2<br />Time Slice<br />Interrupt<br />CPU<br />P2's context is now saved.<br />
  46. 46. Multitasking<br />P1<br />P3<br />P4<br />P2<br />CPU<br />P2 is PRE-EMPTED. It is brought back into the process queue. Next it will be P3's turn, and so on.<br />
  47. 47. Virtual Machines and Process Memory Maps<br />
  48. 48. What is a Virtual Machine?<br />
  49. 49. What is a Virtual Machine?<br />A view of ABSTRACTED HARDWARE as presented to a PROCESS by the OS.<br />
  50. 50. What is a Virtual Machine?<br />A view of ABSTRACTED HARDWARE as presented to a PROCESS by the OS.<br />A process sees its OWN view of the CPU, Memory, Storage, and other devices.<br />Every process runs in its own "virtual" machine.<br />This is how the OS ensures process memory and resource segregation.<br />
  51. 51. Do processes have their OWN view of the memory?<br />Yes. Processes see "Virtual Memory"<br />
  52. 52. Do processes have their OWN view of the memory?<br />Yes. Processes see "Virtual Memory"<br />Physical memory is divided into PAGES.<br />A process is assigned pages as needed. This is done by the Memory Management Unit (MMU)<br />From the process' point of view, it seems to have all the memory to itself.<br />
  53. 53. Pages from P1's memory are mapped from physical memory. P1 sees a "virtual address space".<br />Physical Memory<br />P1's memory<br />Physical and Virtual Memory<br />
  54. 54. Physical and Virtual Memory<br />Similarly for P2.<br />Physical Memory<br />P1's memory<br />P2's memory<br />
  55. 55. Can one process access another's memory?<br />No. A process can only access its own virtual memory space.<br />
  56. 56. Can one process access another's memory?<br />No. A process can only access its own virtual memory space.<br />A process CANNOT access physical memory.<br />
  57. 57. The Process' view of memory<br />Process Memory has its own VIRTUAL ADDRESS SPACE. Typically 2 to 3 GB.<br />Binary<br />Heap<br />It is called a PROCESS MEMORY MAP.<br />Lib<br />3GB (Linux)<br />2GB (Win32)<br />Lib<br />Lower addresses represented at the top of the map. Higher addresses at the bottom.<br />Lib<br />Stack<br />Process' Virtual Memory<br />
  58. 58. Linux Process Memory Map<br />0x08000000<br />Binary<br />Heap<br />Lib<br />3GB<br />Lib<br />Lib<br />Stack<br />0xbfffffff<br />Linux Process<br />Memory Map<br />
  59. 59. An example<br />Here's how to view a process' memory map in Linux. The process here is PID 1110.<br />saumil@localhost:$ pmap 1110<br />1110: /home/nweb/nweb 8181 /home/nweb <br />08048000 8K read/exec /home/nweb/nweb<br />0804a000 4K read/write /home/nweb/nweb<br />0804b000 8K read/write/exec [ anon ]<br />40000000 72K read/exec /lib/ld-2.3.1.so<br />40012000 4K read/write /lib/ld-2.3.1.so<br />40013000 4K read/write [ anon ]<br />40019000 1204K read/exec /lib/i686/libc-2.3.1.so<br />40146000 16K read/write /lib/i686/libc-2.3.1.so<br />4014a000 8K read/write [ anon ]<br />bfffe000 8K read/write/exec [ anon ]<br /> total 1336K<br />
  60. 60. The Big Picture<br />
  61. 61. CPU<br />NIC<br />Storage<br />Physical Memory<br />
  62. 62. File System<br />Network Stack<br />Scheduler<br />MMU<br />Driver<br />Driver<br />CPU<br />NIC<br />Storage<br />Physical Memory<br />
  63. 63. kernel space<br />System Calls<br />File System<br />Network Stack<br />Loader<br />Scheduler<br />MMU<br />Driver<br />Driver<br />CPU<br />NIC<br />Storage<br />Physical Memory<br />
  64. 64. user space<br />Virtual Memory<br />PROCESS<br />Virtual Memory<br />PROCESS<br />Virtual Memory<br />PROCESS<br />CPU<br />FS<br />N/W<br />CPU<br />FS<br />N/W<br />CPU<br />FS<br />N/W<br />kernel space<br />System Calls<br />File System<br />Network Stack<br />Loader<br />Scheduler<br />MMU<br />Driver<br />Driver<br />CPU<br />NIC<br />Storage<br />Physical Memory<br />
  65. 65. user space<br />Virtual Memory<br />PROCESS<br />Virtual Memory<br />PROCESS<br />Virtual Memory<br />PROCESS<br />CPU<br />FS<br />N/W<br />CPU<br />FS<br />N/W<br />CPU<br />FS<br />N/W<br />kernel space<br />System Calls<br />File System<br />Network Stack<br />Loader<br />Scheduler<br />MMU<br />Driver<br />Driver<br />CPU<br />NIC<br />Storage<br />Physical Memory<br />
  66. 66. Key Concepts<br />
  67. 67. Review<br />
  68. 68. END<br />

×