Download presentation
Presentation is loading. Please wait.
Published byCarmel Copeland Modified over 8 years ago
1
OPERATING SYSTEMS 3 - PROCESSES PIETER HARTEL 1
2
Principle of concurrency - giving a process the illusion that it owns the whole machine A process has: Identifier Priority Program State + Control (what?) 2
3
Process switch User mode ↔ Kernel mode Synchronous: System call Asynchronous: Interrupt 3
4
#include int main(int argc, char *argv[]) { pid_t pid=fork(); printf("%s\n", argv[0]); if (pid==0) { /* child process */ static char *argv[]={"echo","Foo",NULL}; execv("/bin/echo",argv); exit(127); /* only if execv fails */ } else { /* pid!=0; parent process */ waitpid(pid,0,0); /* wait for child exit */ } return 0; } UNIX process creation example Output? gcc Fork.c strace./a.out strace -f./a.out Which system call? 4
5
Process creation in the shell /bin/sh Fork Same /bin/sh Exec New./a.out Write 5
6
UNIX signal example Output? gcc Signal.c ./a.out 6 #include void sigsegv_handler(int sig) { printf("SIGSEGV received.\n"); exit(0); } int main() { int *pointer=(int *)NULL; signal(SIGSEGV,sigsegv_handler); printf("About to segfault:\n"); *pointer=0; printf("Why didn't we crash?\n"); return 1; }
7
More realistic state diagram & queue 7 Pre-emption Round-robin scheduling Swapping
8
Summary Principle of concurrency A process is code+data+state Management involves creation, switching and termination Signals can be used between processes 8
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.