CSE-451 Processes1 Applications, Address Spaces, and Processes Separating Units of Computation.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Processes and Threads Prof. Sirer CS 4410 Cornell University.
CSE 451: Operating Systems Winter 2007 Module 4 Processes Ed Lazowska Allen Center 570.
Chapter 6 Limited Direct Execution
IT344 – Operating Systems Winter 2011, Dale Rowe.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
CSE 451: Operating Systems Winter 2006 Module 4 Processes Ed Lazowska Allen Center 570.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Processes CSCI 444/544 Operating Systems Fall 2008.
Processes. Announcements First homework is due this Wednesday by midnight First CS 415 project is up Contact me by 3:30 if you don’t have CSUGLab account.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSE-451 Processes1 Applications, Address Spaces, and Processes Separating Units of Computation.
Processes and Interprocess Communication. Announcements.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
CSE 451: Operating Systems Spring 2012 Module 4 Processes Ed Lazowska Allen Center 570.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
Lecture Topics: 11/3 Address spaces Memory protection Creating a process –NT style –Unix style.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
CSE 451: Operating Systems Winter 2012 Processes Mark Zbikowski Gary Kimura.
Protection and the Kernel: Mode, Space, and Context.
Processes and Threads Prof. Van Renesse and Sirer CS 4410 Cornell University.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Creating and Executing Processes
Processes. Announcements All office hours have been finalized. Available on web. CS 414 Homework will be available Wednesday –Due following Wednesday,
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
Computer Studies (AL) Operating System Process Management - Process.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
Operating Systems Process Creation
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Process Abstractions. Announcements First homework is due this Wednesday by midnight First CS 415 project is up Contact Bill Hogan
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Introduction to Operating Systems
Process Tables; Threads
Protection of System Resources
CSE 451: Operating Systems Autumn 2013 Module 4 Processes
Processes in Unix, Linux, and Windows
IT 344: Operating Systems Module 4 Processes
Processes in Unix, Linux, and Windows
More on UART Interrupts; System Calls
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
System Structure and Process Model
Process Tables; Threads
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Tutorial: The Programming Interface
Jonathan Walpole Computer Science Portland State University
Lecture 6: Multiprogramming and Context Switching
October 7, 2002 Gary Kimura Lecture #4 October 7, 2002
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
CSE 451: Operating Systems Autumn 2009 Module 4 Processes
IT 344: Operating Systems Winter 2008 Module 4 Processes
CSE 451: Operating Systems Winter 2007 Module 4 Processes
Processes in Unix and Windows
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
CSE 451: Operating Systems Autumn 2010 Module 4 Processes
CS703 – Advanced Operating Systems
Presentation transcript:

CSE-451 Processes1 Applications, Address Spaces, and Processes Separating Units of Computation

CSE-451 Processes2 Definitions User mode –when the system is executing with the privileged bit off Kernel mode –when the system is executing with the privileged bit on Address space –the range of addresses available for a program to use Legal address space –the range of addresses that a program can use right now

CSE-451 Processes3 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 for the kernel But, when the mode bit is off, the user program can only see its own memory –the kernel’s address space is OFF LIMITS –what happens if the user tries? Good for the OS, and good for the user program

CSE-451 Processes4 OS/User Protection User Program The Operating System 0x x7fffffff 0xffffffff main() { int fd = open(“/tmp/foo”); close(fd); } Syscall dispatch File system VM system /* Syscall Dispatcher */ // determine requested routine // transfer control to requested routine // return result Address Space 0x

CSE-451 Processes5 Privileged Memory Protection Address low bits high bits Mode bit Protection Fault To memory C = AB

CSE-451 Processes6 Inside the User Program User Program The code we wrote Some code we didn’t write _open: load $v0, #SyscallOpen syscall cmp $v0, 0 jneError move $a0, $v0 ret Error: …. Syscall dispatch syscall_ent: cmp $v0, #0// check if good system call jlt Error cmp $v0, #MaxSysCall jgt Error jsr SaveAllNonLinkRegisters load $v0, $v0(SyscallTable) // if so, get api entry point jsr $v0 // go there move $v0, $a0 // result in $a0 load $v0, #0 RestoreAllNonLinkRegisters retsys Error:...

CSE-451 Processes7 What Happens on Syscall? Automatic –Hardware MODE bit flips (go from nonpriv to priv) –Minimal save and restore of context SP <- Kernel Syscall SP PC <- Kernel Syscall PC *SP++ <- User SP *SP++ <- User PC –What happens on retsys?

CSE-451 Processes8 And then we pick it up... Sycall handler checks to make sure we’re asking for a good service Control is transferred to the service Result is passed back

CSE-451 Processes9 Understanding the Stack User stack main int fd main+12 SP Kernel stack 0x40040 USP=0x40040 UPC=_open+12 SPstack at syscall $a0 $a1 $a2… syscall_ent+24 SP stack at entry to open New stuff Old stuff 0x

CSE-451 Processes10 Concepts So Far User programs operate out of a different portion of the address space than the kernel There is a context switch that occurs every time we enter the kernel Inside the kernel we have expanded privileges A combination of hardware and software is responsible for this behavior

CSE-451 Processes11 Multiple Address Spaces Nearly all operating systems support the abstraction of multiple address spaces EmacsMail Kernel mode User mode 0x xffffffff CC 0x x7fffffff 0x x7fffffff 0x x7fffffff

CSE-451 Processes12 A Process Each address space contains a process –a bunch of text & data –a “thread” in execution A thread represents the flow of control that is active inside a program –deterministic change of state prescribed by the current state and the PC (which is actually part of the current state)

CSE-451 Processes13 A Process is a Program in Execution static int z = 5; main(int argc, char **argv) { int x = foo(); printf(“%d\n”, x); } int foo() { return z=23;} Source Code File Executable File (Program) a.out cc text header: “size, start PC” Create Process text start PC z=5 static data heap stack 0x x7fffffff Process In Memory 1st instruction thread

CSE-451 Processes14 The Thread Of Control static int z = 5; main(int argc, char **argv) { int x = foo(); printf(“%d\n”, x); } int foo() { return z=23;} argc, argv are on the stack call main call foo set z to 23 return 23 set x to 23 push x push “%d\n” call printf return argc argv _exit main+4 23 stack argc argv _exit 23 “%d\n” main+16 Thread

CSE-451 Processes15 Where do Processes Come From? Remember, a process is an address space with some stuff in it and a thread of control All operating systems have facilities for creating new processes Some of them (eg, NT) are quite simple: –CreateAddressSpace, WriteAddressSpace, CreateThreadInAddressSpace, StartThread Others (eg, UNIX) are more subtle, but quite elegant

CSE-451 Processes16 Processes Under UNIX In Unix, the fork() system call is the only way to create a new process int fork() does many things at once: –creates a new address space (called the child) –copies the parent’s address space into the child’s –starts a new thread of control in the child’s address space –parent and child are equivalent -- almost in parent, fork() returns a non-zero integer in child, fork() returns a zero. difference allows parent and child to distinguish int fork() returns TWICE!

CSE-451 Processes17 Example 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); } What does this program print?

CSE-451 Processes18 Bizarre But Real lace:tmp cc a.c lace:tmp./a.out foobar The child of foobar is My child is Parent Child Operating System fork() retsys v0=0v0=23874

CSE-451 Processes19 Even More Bizarre lace:tmp cc a.c lace:tmp./a.out foobar The child of foobar is My child is lace:tmp./a.out foobar My child is The child of foobar is lace:tmp Parent Child Operating System fork() retsys v0=0v0=24266 Why do we get a different answer??

CSE-451 Processes20 Fork is half the story Fork() gets us a new address space, but not one that’s all that different. –parent and child share EVERYTHING memory, operating system state int exec(char *programName) completes the picture –throws away the contents of the calling address space –replaces it with the program named by programName –starts executing at header.startPC

CSE-451 Processes21 Starting a new program main(int argc, char **argv) { char *myName = argv[1]; char *progName = argv[2]; int cpid = fork(); if (cpid == 0) { printf(“The child of %s is %d\n”, myName, getpid()); execl(progName, // executable name progName, 0); // null terminated argv printf(“OH NO. THEY LIED TO ME!!!\n”); } else { printf(“My child is %d\n”, cpid); exit(0); }

CSE-451 Processes22 Extra Credit for Friday Write a simple UNIX program to simulate the UNIX shell in a “read/fork/exec” loop –don’t bother with path searches. All commands can be fully qualified CSE451Shell% /bin/cat /etc/motd DEC OSF/1 V3.2 (Rev. 214); Thu Feb 22 08:48:40 PST 1996 DEC OSF/1 V3.2 Worksystem Software (Rev. 214) This is an AFS fileserver. Please run long running jobs (hours) or memory intensive jobs elsewhere. CSE451Shell% /bin/date Sun Apr 5 22:51:50 PDT 1998