1 / 8

Operating Systems 3 - Processes

Operating Systems 3 - Processes. PIETER HARTEL. Principle of concurrency - giving a process the illusion that it owns the whole machine. A process has: Identifier Priority Program State + Control (what?). Process switch. User mode ↔ Kernel mode Synchronous: System call

clint
Télécharger la présentation

Operating Systems 3 - Processes

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. Operating Systems 3 - Processes PIETER HARTEL

  2. Principle of concurrency -giving a process the illusion that it owns the whole machine • A process has: • Identifier • Priority • Program • State + Control (what?)

  3. Process switch • User mode ↔ Kernel mode • Synchronous: System call • Asynchronous: Interrupt

  4. UNIX process creation example #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <wait.h> int main(intargc, char *argv[]) { pid_tpid=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; } • Output? • gccFork.c • strace ./a.out • strace -f ./a.out • Which system call?

  5. Process creation in the shell

  6. UNIX signal example #include <stdio.h> #include <stdlib.h> #include <signal.h> void sigsegv_handler(int sig) { printf("SIGSEGV received.\n"); exit(0); } int main() { int *null_pointer=(int *)NULL; signal(SIGSEGV,sigsegv_handler); printf("About to segfault:\n"); *null_pointer=0; printf("Why didn't we crash?\n"); return 1; } • Output? • gcc Signal.c • ./a.out

  7. More realistic state diagram & queue • 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

More Related