Download presentation
Presentation is loading. Please wait.
Published byAugust Bryan Modified over 5 years ago
1
Section 2 Processes January 27rd, 2017 Taught by Joshua Don
2
Quick 61C Review char *string = “hello”;
0xFFF..FF 0x Stack Heap Text char *string = “hello”; int main(int argc, char* argv[]) { int x = 10; char *another_string = malloc(10); } Where is string? argc? x? another_string?
3
Quick 61C Review char *string = “hello”;
0xFFF..FF 0x Stack Heap Text char *string = “hello”; int main(int argc, char* argv[]) { int x = 10; char *another_string = malloc(10); } Where is string? Text argc? Stack x? Stack another_string? Stack, but it points to a loc on the heap
4
Dual Mode Operation Two modes of operation. User and kernel mode.
We want to protect ourselves from user programs which can’t be trusted and other processes from each other. Examples of procedures that are in kernel mode? How do we get in kernel mode?
5
Dual Mode Operation Two modes of operation. User and kernel mode.
We want to protect ourselves from user programs which can’t be trusted and other processes from each other. Examples of procedures that are in kernel mode? Scheduling Handling interrupts Filesystem management How do we get in kernel mode? Syscall (a programmatic interface to the kernel) Interrupt (asynchronous event ie. Timer going off) Exception (synchronous event ie. Divide by 0)
6
Fork
7
Fork Process A 0xFFF..FF Stack int main() { . . . pid_t p = fork() }
Heap Text int main() { . . . pid_t p = fork() }
8
Fork continued Process A 0xFFF..FF Stack int main() { . . .
Heap Text int main() { . . . pid_t p = fork() } Fork!!!!
9
Fork continued Process A Process B (PID = 1) 0xFFF..FF 0x000..00 Stack
Heap Text 0xFFF..FF 0x Stack Heap Text int main() { . . . pid_t p = fork() } int main() { . . . pid_t p = fork() }
10
Fork continued Process A Process B (PID = 1) 0xFFF..FF 0x000..00 Stack
Heap Text 0xFFF..FF 0x Stack Heap Text int main() { . . . pid_t p = fork() } int main() { . . . pid_t p = fork() } 1
11
Wait
12
wait() function signature is wait(int *status)
“waits” for any child process to terminate. wait(&status) same as waitpid(-1, &status, 0) waitpid generally used to wait on a specific child (first argument to waitpid is the PID of the process to wait on) -1 in this case means “any child”, so it is equivalent to wait()
13
Wait continued int main() { int status; pid_t p = fork() if (p != 0){
Process A Process B (PID = 1) 0xFFF..FF 0x Stack Heap Text 0xFFF..FF 0x Stack Heap Text int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0); int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0);
14
Wait continued int main() { int status; pid_t p = fork() if (p != 0){
Process A Process B (PID = 1) 0xFFF..FF 0x Stack Heap Text 0xFFF..FF 0x Stack Heap Text int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0); int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0);
15
Wait continued int main() { int status; pid_t p = fork() if (p != 0){
Process A Process B (PID = 1) 0xFFF..FF 0x Stack Heap Text 0xFFF..FF 0x Stack Heap Text int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0); int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0);
16
Wait continued int main() { int status; pid_t p = fork() if (p != 0){
Process A Process B (PID = 1) 0xFFF..FF 0x Stack Heap Text 0xFFF..FF 0x Stack Heap Text int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0); int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0);
17
Wait continued int main() { int status; pid_t p = fork() if (p != 0){
Process A Process B (PID = 1) 0xFFF..FF 0x Stack Heap Text 0xFFF..FF 0x Stack Heap Text int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0); int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0);
18
Wait continued int main() { int status; pid_t p = fork() if (p != 0){
Process A Process B (exit code = 0) 0xFFF..FF 0x Stack Heap Text int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } exit(0);
19
Exec
20
Exec Process B Process A 0xFFF..FF 0x000..00 Stack Heap Text 0xFFF..FF
int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } else { exec(“/bin/ls”); } exit(0); int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } else { exec(“/bin/ls”); } exit(0);
21
Exec continued Process B Process A 0xFFF..FF 0x000..00 Stack Heap Text
int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } else { exec(“/bin/ls”); } exit(0); int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } else { exec(“/bin/ls”); } exit(0);
22
Exec continued Process B Process A 0xFFF..FF 0x000..00 Stack Heap Text
int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } else { exec(“/bin/ls”); } exit(0); int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } else { exec(“/bin/ls”); } exit(0);
23
Exec continued Process B Process A int main() { // code for // /bin/ls
0xFFF..FF 0x Stack Heap Text 0xFFF..FF 0x Stack Heap Text Process A Process B int main() { int status; pid_t p = fork() if (p != 0){ // parent wait(&status); } else { exec(“/bin/ls”); } exit(0); int main() { // code for // /bin/ls exit(0); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.