1 / 18

Lecture Topics: 11/3

Lecture Topics: 11/3. Address spaces Memory protection Creating a process NT style Unix style. Address Spaces. Reserved. An address space is the range of addresses that a process may use The legal address space is the range of addresses that a process may use right now. Text.

eshana
Download Presentation

Lecture Topics: 11/3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture Topics: 11/3 • Address spaces • Memory protection • Creating a process • NT style • Unix style

  2. Address Spaces Reserved • An address space is the range of addresses that a process may use • The legal address space is the range of addresses that a process may use right now Text Static data Dynamic data and stack Operating system

  3. User and Kernel Memory • When the mode bit is set to privileged, the kernel can see all of memory • user program, arguments, etc. • user memory is like a big data structure to the kernel • When the mode bit is off, the user program can only see its own memory • the kernel’s part of the address space is off limits

  4. Enforcing Kernel Memory • To enforce this policy, the hardware must check every reference to make sure it’s OK Address: 010110101011010... Mode bit’: 0 exception

  5. Multiple Address Spaces • Nearly all modern operating systems support the abstraction of multiple address spaces 0x00000000 user mode netscape word tetris 0x7fffffff 0x80000000 kernel mode kernel 0xffffffff

  6. Processes and Address Spaces • Each process has its own address space • Process A’s memory references (loads and stores) are interpreted within process A’s address space • Can Process A load a word from Process B’s address space? • Can Process A load a word from kernel memory?

  7. Memory Protection • We mean two things by memory protection: • user programs can’t access kernel memory • user programs can’t access each other’s memory • In the first case, we’re using hardware support • In the second case, we’re using naming

  8. Process Creation • We’ll see two approaches • The NT way: the directed approach • The parent process issues a series of system calls, setting up the child • The Unix way: fork/exec • The parent clones itself, and the child alters itself to do its task

  9. Directed Process Creation 1/3 • Step 1: Ask the OS to make a new address space

  10. Directed Process Creation 2/3 • Step 2: Ask the OS to write the program image into the new address space

  11. Directed Process Creation 3/3 • Step 3: Ask the OS to start the new process running at some procedure

  12. Unix Process Creation • Only one step: call fork() • How does the OS know what program to run and where to start it?

  13. Unix fork() • Fork() is the Unix system call that creates a new process, but it doesn’t take any arguments • Instead, it makes an exact duplicate of the parent process. The only differences: • The PID (process ID number) • The return value of fork() itself

  14. An Example Using fork() main(int argc, char *argv[]) { char *myName = argv[1]; int cpid = fork(); if(cpid == 0) { printf(“The child of %s is %d\n”, myName, getpid()); exit(0); } else { printf(“My child is %d\n”, cpid); exit(0); }

  15. Bizarre But Real sequoia> gcc -o forkexample forkexample.c sequoia> ./forkexample george The child of george is 23874 My child is 23874

  16. Even More Bizarre sequoia> ./forkexample george The child of george is 23874 My child is 23874 sequoia> ./forkexample george My child is 24266 The child of george is 24266 Why do we get a different answer?

  17. What good is fork()? • By itself, not very useful • You might want to run an entirely different program some day! • Another system call, exec(), completes the picture. • Exec(): • Replaces the program image of the parent with a new image • Starts executing at the beginning

  18. Why is Unix Like That? • The Unix assumption is that the child will have a lot in common with the parent • it will read the same files • the username of the owner is the same • it uses some of the same data, etc. • The Unix approach starts with the parent and alters to suit • The NT approach starts from scratch

More Related