
Operating Systems Lecture 3: The Process API Nipun Batra Aug 9, 2019 Memory in C 2 Memory in C 2 Process Execution Disk 3 Process Execution Program (hello.c) Disk 3 Process Execution Compile Program (hello.c) Disk 3 Process Execution Compile Program Executable (hello.c) (hello.out) Disk 3 Process Execution Executable Disk (hello.out) 4 Process Execution Executable Disk (hello.out) 5 Process Execution Memory Executable Disk (hello.out) 5 Process Execution Memory Load from Executable disk to memory Disk (hello.out) 5 Process Execution Address Memory Space Load from Executable disk to memory Disk (hello.out) 5 Process Execution Memory Load from Executable disk to memory Disk (hello.out) 5 Process Execution Code Memory Load from Executable disk to memory Disk (hello.out) 5 Process Execution Code Static Memory data Load from Executable disk to memory Disk (hello.out) 5 Process Execution Code Static Memory data Heap Load from Executable disk to memory Disk (hello.out) 5 Process Execution Code Static Memory data Heap Stack Load from Executable disk to memory Disk (hello.out) 5 Process Execution Code Memory CPU Static data Heap Stack Load from Executable disk to memory Disk (hello.out) 5 Process Execution Program Code Counter Memory CPU Static data Heap Stack Load from Executable disk to memory Disk (hello.out) 5 Process Execution Program Code Counter Memory CPU Static data Heap Stack Load from Executable disk to memory Disk (hello.out) 5 Process Execution Program Code Counter Memory CPU Static 1. Fetch data Heap Stack Load from Executable disk to memory Disk (hello.out) 5 Process Execution Program Code Counter Memory CPU Static 1. Fetch data 2. Decode Heap Stack Load from Executable disk to memory Disk (hello.out) 5 Process Execution Program Code Counter Memory CPU Static 1. Fetch data 2. Decode Heap 3. Execute Stack Load from Executable disk to memory Disk (hello.out) 5 Process Execution Program Code Counter Memory CPU Static 1. Fetch data 2. Decode Heap 3. Execute Stack 4. Update PC Load from Executable disk to memory Disk (hello.out) 5 Process Execution Program Code Counter Memory CPU Static 1. Fetch data 2. Decode Heap 3. Execute Stack 4. Update PC Load from Executable disk to memory Disk (hello.out) 5 CPU Virtualisation 6 CPU Virtualisation • Goal: Provide an illusion of many CPUs 6 CPU Virtualisation • Goal: Provide an illusion of many CPUs • How: Time sharing between processes 6 CPU Virtualisation • Goal: Provide an illusion of many CPUs • How: Time sharing between processes P1 P2 P3 P1 6 CPU Virtualisation • Goal: Provide an illusion of many CPUs • How: Time sharing between processes P1 P2 P3 P1 23% P1 P2 51% P3 Unused 19% 7% 6 CPU Virtualisation • Goal: Provide an illusion of many CPUs • How: Time sharing between processes P1 P2 P3 P1 23% P1 P2 Space sharing for 51% P3 memory Unused 19% 7% 6 CPU Virtualisation II P1 Running 7 CPU Virtualisation II Want to run P2 P3 P1 P1 Running 8 CPU Virtualisation II Want to run P2 P3 P1 P1 OS Running Scheduler 9 CPU Virtualisation II Want to run P2 P3 P1 P1 OS Running Scheduler Next P = f(run time, metric, type of process, …) 9 CPU Virtualisation II Want to run P2 P3 P1 P1 P2 OS Running Should Scheduler run 10 CPU Virtualisation II Want to run P2 P3 P1 P1 P2 OS Running Should Scheduler run Low level mechanisms (Context switch) 11 CPU Virtualisation II Want to run How to run P2 P3 P1 P1 P2 OS Running Should Scheduler run Low level mechanisms Which program (Context to run switch) 12 Process API 13 Process API • Create process: 13 Process API • Create process: • Double click 13 Process API • Create process: • Double click • Run on command line 13 Process API • Create process: • Double click • Run on command line • Destroy processes: 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line • Wait: 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line • Wait: • Don’t run process till other process completes 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line • Wait: • Don’t run process till other process completes • Status: 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line • Wait: • Don’t run process till other process completes • Status: • How long run, what state it is in 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line • Wait: • Don’t run process till other process completes • Status: • How long run, what state it is in • Does top, ps give us this info? 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line • Wait: • Don’t run process till other process completes • Status: • How long run, what state it is in • Does top, ps give us this info? • Misc.: 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line • Wait: • Don’t run process till other process completes • Status: • How long run, what state it is in • Does top, ps give us this info? • Misc.: • Suspend 13 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line • Wait: • Don’t run process till other process completes • Status: • How long run, what state it is in • Does top, ps give us this info? • Misc.: • Suspend 13 Process States Scheduled Running Ready Descheduled I/O initiate I/O done Blocked 14 Process States Running Ready Blocked P1 P0 0 1 2 3 4 5 6 7 Time 15 Process States Running Ready Blocked P1 P0 0 1 2 3 4 5 6 7 8 Time 16 Process API • Create process: • Double click • Run on command line • Destroy processes: • Task manager • Command line • Wait: • Don’t run process till other process completes • Status: • How long run, what state it is in • Does top, ps give us this info? • Misc.: • Suspend 17 Process API • Create process: • fork() • exec() • Wait: • wait() 18 The fork() System Call > man fork 19 fork() demo 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 2. fork_demo_2.c : Get the PID of parent process 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 2. fork_demo_2.c : Get the PID of parent process 3. Use ps (man ps to find more) to find what’s the parent process? 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 2. fork_demo_2.c : Get the PID of parent process 3. Use ps (man ps to find more) to find what’s the parent process? 4. See the above in Activity Monitor 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 2. fork_demo_2.c : Get the PID of parent process 3. Use ps (man ps to find more) to find what’s the parent process? 4. See the above in Activity Monitor 5. fork_demo_3.c: Add sleep to view more details in Activity Monitor 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 2. fork_demo_2.c : Get the PID of parent process 3. Use ps (man ps to find more) to find what’s the parent process? 4. See the above in Activity Monitor 5. fork_demo_3.c: Add sleep to view more details in Activity Monitor 6. fork_demo_4.c: Use fork() to create child process 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 2. fork_demo_2.c : Get the PID of parent process 3. Use ps (man ps to find more) to find what’s the parent process? 4. See the above in Activity Monitor 5. fork_demo_3.c: Add sleep to view more details in Activity Monitor 6. fork_demo_4.c: Use fork() to create child process 7. fork_demo_5.c: Add sleep to above and find these processes on Activity Monitor 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 2. fork_demo_2.c : Get the PID of parent process 3. Use ps (man ps to find more) to find what’s the parent process? 4. See the above in Activity Monitor 5. fork_demo_3.c: Add sleep to view more details in Activity Monitor 6. fork_demo_4.c: Use fork() to create child process 7. fork_demo_5.c: Add sleep to above and find these processes on Activity Monitor 8. Show the same using ps command 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 2. fork_demo_2.c : Get the PID of parent process 3. Use ps (man ps to find more) to find what’s the parent process? 4. See the above in Activity Monitor 5. fork_demo_3.c: Add sleep to view more details in Activity Monitor 6. fork_demo_4.c: Use fork() to create child process 7. fork_demo_5.c: Add sleep to above and find these processes on Activity Monitor 8. Show the same using ps command 1. (ps -p 42693 -o pid,ppid) 20 fork() demo 1. fork_demo_1.c : Get the PID of current process 2. fork_demo_2.c : Get the PID of parent process 3. Use ps (man ps to find more) to find what’s the parent process? 4. See the above in Activity Monitor 5. fork_demo_3.c: Add sleep to view more details in Activity Monitor 6.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages96 Page
-
File Size-