1 / 33

Processer/tråde

Processer/tråde. Et stykke software der håndtere skiftet af CPU’en. Dispatcher. Et antal selvstændige programmer. Processer. Plus det løse til: Oprettelse af processer. Synkronisering af processer. Kommunikation mellem processer. Proces. Et program der eksekveres. En ressource enhed.

cuyler
Download Presentation

Processer/tråde

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. Processer/tråde • Et stykke software der håndtere skiftet af CPU’en. • Dispatcher. • Et antal selvstændige programmer. • Processer. • Plus det løse til: • Oprettelse af processer. • Synkronisering af processer. • Kommunikation mellem processer.

  2. Proces.Et program der eksekveres. En ressource enhed. • Egen memory. • Egen status for filer. • Egen protection ID. • Administrative data fx. Start tid, Forbrugt CPU-tid osv. • Samt alle alm ting som egen stak, programstatus, CPU’registre, Prioritet Styresystemer og tjenester

  3. Processer/tråde Dispatcher: Et lille progran der skifter til den næste tråd, gør evt. brug af schedulerings algoritmen. Styresystemer og tjenester

  4. Processer/tråde Styresystemer og tjenester

  5. Styresystemerogtjenester

  6. Processer/tråde Styresystemer og tjenester

  7. Proces control blok Styresystemer og tjenester

  8. Proces hieraki • UNIX/LINUX: • En proces er barn af den proces der opretter den. • Processen init fødes ved boot. Alle andre er derfor efterkommere efter init. • Prøv evt. Kommandoen pstree. • Windows: • Ingen hieraki dog får forældre processen en handle til barnet. Styresystemer og tjenester

  9. Proces oprettelse • Boot time: • Init opretter alle de nødvendige processer for at operativsystemet kommer op at køre. • Brug af fork()(UNIX/LINUX) eller CreateProcess(...) (Windows) systemkaldene. • En shell afvikler et program. • Et program/proces oprette en ny proces. • Batch job: • Jobs der står i kø som operativsystemet afvikler efter en bestemt politik. Styresystemer og tjenester

  10. Simpel shell #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> int main (int argc, char *argv[]) { int status, pid; char kommando[80]; while (1) { printf("ppmshell>"); scanf("%s",kommando); pid = fork(); if (pid != 0) while(wait(&status) != pid); else execlp(kommando, (char *)NULL); } } Styresystemer og tjenester

  11. EXEC #include <unistd.h> int execlp( const char *file, /* program name */ const char *arg0, /* first arg (file name) */ const char *arg1, /* second arg (if needed) */ ..., /* remaining args (if needed) */ NULL /* arg list terminator */ ); /* Returns -1 on error (sets errno) */ execlp("echo", "echo", "haj", "du.", NULL); Styresystemer og tjenester

  12. EXEC int execl(const char *path, const char *arg0, const char *arg1,..., NULL); int execlp(const char *file, const char *arg0, const char *arg1,..., NULL); int execle(const char *path, const char *arg0, const char *arg1,..., NULL, char *const envv[]); int execv(const char *path,char *const argv[]); int execvp(const char *file, char *const argv[]); int execve(const char *path, char *const argv[], char *const envv[]); Styresystemer og tjenester

  13. Software interrupts: Signals Styresystemer og tjenester

  14. #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> #include <signal.h> void slut () {printf(" -- Så er det slut\n"); exit(0);} intmain (int argc, char *argv[]) { int status, pid; char kommando[80]; signal (SIGINT, slut); while (1) { printf("ppmshell>"); scanf("%s",kommando); pid = fork(); if (pid != 0) while(wait(&status) != pid); else execlp(kommando, (char *)NULL); } } Simpel shell Styresystemer og tjenester

  15. Software interrupts: Realtime Clock #include <sys/types.h> #include <time.h> #include <sys/time.h> #include <signal.h> struct timeval tv; struct itimerval sample_time; struct sigaction sa; void sampel_pc () { // gør noget } sample_time.it_interval.tv_sec = 0; sample_time.it_interval.tv_usec = 100000; sample_time.it_value.tv_sec = 0; sample_time.it_value.tv_usec = 100000; /* Install timer_handler as the signal handler for SIGVTALRM. */ memset (&sa, 0, sizeof (sa)); sa.sa_handler = &sampel_pc; sigaction (SIGALRM, &sa, NULL); setitimer (ITIMER_REAL, &sample_time, ((struct itimerval *) 0)); while (1) sigpause (0); Styresystemer og tjenester

  16. Short-Term Schedulering/dispatching • Dispatcheren startes af: Hardware: • Clock interrupts • I/O interrupts Kørendeproces/tråd. • Operating system kald • Signals (e.g., semaphores) Styresystemer og tjenester

  17. Preemptive/Nonpreemptive • Nonpreemptive: Når en proces køre fåe den lov at køre til den selv giver afkald på CPU’en. • Preemptive: En proces kan blive afbrugt på et vilkårligd tidspunkt, som følge af et HW-interrupt. Styresystemer og tjenester

  18. w = Ventetid • e = Eksekveringstid • s = Total eksekveringstid tid for proces, Styresystemer og tjenester

  19. Styresystemer og tjenester

  20. First-Come-First-Served (FCFS) • Simplest scheduling policy • Also known as first-in-first-out (FIFO) or a strict queuing scheme • When the current process ceases to execute, the longest process in the Ready queue is selected • Performs much better for long processes than short ones • Tends to favor processor-bound processes over I/O-bound processes

  21. Round Robin • Uses preemption based on a clock • Also known as time slicing because each process is given a slice of time before being preempted • Principal design issue is the length of the time quantum, or slice, to be used • Particularly effective in a general-purpose time-sharing system or transaction processing system • One drawback is its relative treatment of processor-bound and I/O-bound processes

  22. Effect of Size of Preemption Time Quantum

  23. Virtual Round Robin (VRR)

  24. Shortest Process Next (SPN) • Nonpreemptive policy in which the process with the shortest expected processing time is selected next • A short process will jump to the head of the queue • Possibility of starvation for longer processes • One difficulty is the need to know, or at least estimate, the required processing time of each process • If the programmer’s estimate is substantially under the actual running time, the system may abort the job

  25. Shortest Remaining Time (SRT) • Preemptive version of SPN • Scheduler always chooses the process that has the shortest expected remaining processing time • Risk of starvation of longer processes • Should give superior turnaround time performance to SPN because a short job is given immediate preference to a running longer job

  26. Highest Response Ratio Next (HRRN) • Chooses next process with the greatest ratio • Attractive because it accounts for the age of the process • While shorter jobs are favored, aging without service increases the ratio so that a longer process will eventually get past competing shorter jobs

  27. Feedback Scheduling

  28. Feedback Performance

  29. Schedulering. Linux Real-time FIFO. Real-time Round Robin. Alm. Threads og processer. Real-Time prioriteter 0 – 99. Kun SuperUser Alm. prioriteter 100 – 139. Default 120 (nice) nice(0) ~ 120 (Default). nice(1) – nice(19): Nedprioritering fx baggrunds job. nice(-1) – nice(-20): Kun SuperUser. Styresystemer og tjenester

  30. Schedulering af alm. threads og processer Tidskvant tilskrevet en proces/tråd, når den forrige er opbrugt: Tidskvant = (140 – Statisk prioritet) * 20 for Statisk prioritet < 120 (140 – Statisk prioritet) * 5 for Statisk prioritet >= 120 Dvs: nice(-20) ~ 800 mS, nice(0) ~ 100 mS nice(19) ~ 5 mS Dynamisk prioritet: Hvem skal til først ? Dyn. prioritet = max(100, min(sta. prioritet – bonus + 5, 139)) Styresystemer og tjenester

  31. Schedulering. Windows Styresystemer og tjenester

  32. Schedulering. Windows Styresystemer og tjenester

  33. Styresystemer og tjenester

More Related