פתח דפדפן, נגן מוזיקה ומשחק. יש לך מעבד אחד — אולי כמה ליבות — אך כולם נראים כאילו רצים בו-זמנית. יחד הם שואפים ליותר…
English narration · English + 中文 subtitles burned in · קריאת קול באנגלית · תרגום אנגלי + סינית שרוף בתוך הסרטון
16.1
How an OS maximises use of resources · כיצד מערכת ההפעלה מקסימה את השימוש במשאבים
Syllabus · סיילבוס
English
Candidates should be able to:
Notes and guidance
Show understanding of how an OS can maximise the use of resources
Describe the ways in which the user interface hides the complexities of the hardware from the user
Show understanding of process management
The concept of multi-tasking and a process The process states: running, ready and blocked The need for scheduling and the function and benefits of different scheduling routines (including round robin, shortest job first, first come first served, shortest remaining time) How the kernel of the OS acts as an interrupt handler and how interrupt handling is used to manage low-level scheduling
Show understanding of virtual memory, paging and segmentation for memory management
The concepts of paging, virtual memory and segmentation The difference between paging and segmentation How pages can be replaced How disk thrashing can occur
עברית
המועמדים צריכים להיות מסוגלים:
הערות והנחיות
הוכח הבנה כיצד מערכת הפעלה יכולה למקסם את השימוש במשאבים
תאר את הדרכים שבהן ממשק המשתמש מסתיר את המורכבות של החומרה מהמשתמש
הוכח הבנה של ניהול תהליכים
מושג הרב-תפעול ותהליך מצבי תהליך: פעיל, מזין וחסום הצורך בתזמון ותפקיד ויתרונות של סדרני תזמון שונים (כולל סבב סבבי, תהליך קצר ראשון, ראשון מגיע נטפל ראשון, זמן שנותר הקצר ביותר) כיצד הגרעין של מערכת ההפעלה פועל כמטפל הפרעות וכיצד טיפול בהפרעות משמש לניהול תזמון בשורה תחתונה
הוכח הבנה של זיכרון וירטואלי, חלוקה וניתוח חלקים לניהול זיכרון
מושגי החלוקה, הזיכרון הווירטואלי והניתוח החלקים ההבדל בין חלוקה לניתוח חלקים איך עמודות יכולות להיות מוחלפות כיצד הפרעה דיסק עשויה להתרחש
Source: Cambridge International syllabus · מקור: הסיילבוס הבינלאומי של קמבריד'ג'
English
A computer has many resources (CPU time, memory, disk, I/O) and many programs competing for them. The OS shares them fairly and efficiently so each is well used and the system stays responsive:
multi-tasking 多任务 — switch the CPU quickly between processes so several seem to run at once.
memory management — give each process the memory it needs; use disk paging 分页 when RAM runs out.
spooling 假脱机 and buffering — print jobs queue on disk so the CPU never waits for the printer.
caching — keep recently-used disk data in cache 高速缓存 / RAM.
עברית
למחשב ישנם משאבים רבים (זמן מעבד, זיכרון, דיסק, I/O) ותוכניות רבות המתחרות עליהם. מערכת ההפעלה משתפת אותם באופן הוגן ויעיל כך שכל אחד יהיה מנוצל היטב והמערכת תישאר מגיבה:
מערכת ההפעלה משתפת את המעבד, הזיכרון, הדיסק ו-I/O בין תוכניות
ריבוי משימות — מעבר מהיר של המעבד בין תהליכים כך שמספר תהליכים נראים כאילו רצים בו-זמנית.
ניהול זיכרון — הענקת כל תהליך בזיכרון שהוא זקוק לו; שימוש בדיסק החלפה (Paging) כאשר RAM נגמר.
Spooling ובאפורה (Buffering) — תורות משימות הדפסה מועלות לדיסק כדי שהמעבד לעולם לא ימתין להדפסן.
שמירה במטמון (Caching) — שמירת נתוני דיסק שהיו בשימוש לאחרונה ב-Cache / RAM.
המעבד הוא משאם מרכזי שמערכת ההפעלה מחלקת בין משימות מתחרותמערכת ההפעלה מנהלת גם את הזיכרון (RAM), וקובעת מה לשמור בו ומה להעביר לדיסק כ"עמודים"
The user interface hides the hardware behind friendly abstractions: the user sees windows, menus and folders, not addresses or sectors. One click on an icon makes the OS find the program on disk, allocate memory, load it and start it. A CLI (command line) is powerful and scriptable for experts; a GUI (graphical) is easier to learn. Most systems offer both.
"Describe two ways in which the complexities of the hardware are hidden from the user." (1) The user works with files and folders by name, and the OS translates them into the tracks, sectors and blocks of the disk; (2) the user runs a program with a click or a command, and the OS loads it, allocates memory and schedules it without the user knowing any addresses; (3) device drivers let the user print or save without knowing how the printer or disk is controlled; (4) a graphical interface replaces machine-level commands with icons, windows and menus. The benefit to a student, with an example: the OS makes the hardware usable without technical knowledge, for instance saving a document to a USB drive by dragging its icon.
"Show how an OS maximises the use of resources." It schedules the processor so that it is never idle while a process is ready; it manages memory, allocating it to processes, reclaiming it and extending it with virtual memory; it manages input and output, using buffers and spooling so that fast and slow devices overlap their work; and it manages storage, keeping track of free space and files. Each point names a resource and what the OS does with it.
עברית
הממשק למשתמש מסתיר את החומרה מאחורי אבסטרקציות נוחות: המשתמש רואה חלונות, תפריטים ותיקיות, ולא כתובות או סקטורים. לחיצה אחת על אייקון גורמת למערכת ההפעלה למצוא את התוכנית בדיסק, לקצות לה זיכרון, לטעון אותה ולהפעיל אותה. CLI (שורת פקודות) הוא עוצמתי וניתן לתכנות עבור מומחים; GUI (גרפי) קל יותר ללמידה. רוב המערכות מציעות שניהם.
"תאר שתי דרכים בהן מורכבות החומרה מסתירה מהמשתמש." (1) המשתמש עובד עם קבצים ותיקיות לפי שמם, ומערכת ההפעלה ממירה אותם לערוצים, סקטורים וחסימות בדיסק; (2) המשתמש מפעיל תוכנית באמצעות לחיצה או פקודה, ומערכת ההפעלה טוענת אותה, מקצה לה זיכרון ומזמנת אותה מבלי שהמשתמש ידע כל כתובות; (3) דרייברים של מכשירים מאפשרים למשתמש להדפיס או לשמור מבלי לדעת כיצד המדפסת או הדיסק מופעלים; (4) ממשק גרפי מחליף פקודות ברמת המכונה באייקונים, חלונות ותפריטים. היתרון לסטודנט, עם דוגמה: מערכת ההפעלה הופכת את החומרה לשימושית ללא ידע טכני, לדוגמה שמירת מסמך לכונן USB על ידי גרירת האייקון שלו.
"הראה כיצד מערכת הפעלה מינימזציה את השימוש במשאבים." היא מזמנת את המעבד כך שהוא לעולם לא יהיה פעיל כשהליכה מוכנה; היא מנהלת את הזיכרון, מקצה אותו להליכים, משחזרת אותו ומרחיבה אותו באמצעות זיכרון וירטואלי; היא מנהלת כניסה ויציאה, באמצעות בופרים ו-Spooling כך שמכשירים מהירים ואיטיים יעשו עבודה במקביל; והיא מנהלת אחסון, ועוקבת אחרי מקום פנוי וקבצים. כל נקודה מזהה משאם ומתארת מה מערכת ההפעלה עושה איתו.
16.1
Process management · ניהול תהליכים
English
A process 进程 is a program in execution — its code, current state, memory and open files.
Scheduling
The scheduler 调度器 chooses which ready process runs next, and for how long:
round robin 轮转 — each process gets a fixed time slice 时间片, then goes to the back of the queue.
first-come-first-served; shortest job first; shortest remaining time (run the job with the least work left); priority; multilevel feedback queues.
The trade-off is responsiveness vs throughput vs fairness.
"Describe what is meant by multi-tasking and how it benefits process management."Several processes are held in memory at the same time and the processor switches between them so quickly that they appear to run simultaneously, each given a share of processor time in turn. The benefit: the processor is never left idle while one process waits for input or output, so throughput is higher and the user can work on several programs at once. "Explain the need for scheduling." There are more processes than processors, so a decision must be made about which process runs next and for how long; scheduling makes sure every process makes progress, that the processor is fully used, that response times are acceptable, and that priorities can be respected.
The scheduling routines, as the exam wants them described.
Routine
Function
Benefit
Drawback
first come first served (FCFS)
processes run in the order in which they arrive in the ready queue, each to completion
simple; every process is dealt with in turn, none is starved
a long process holds up all the short ones behind it; poor response
shortest job first (SJF)
the ready process with the shortest estimated run time runs next, to completion
minimises the average waiting time; many short jobs finish quickly
run times must be known in advance; a long job may never run (starvation)
shortest remaining time (SRT)
pre-emptive 抢占式 version of SJF: if a new process arrives with less time left than the running one, it takes over
short processes are served even faster; good throughput
more context switches; a long job can be interrupted repeatedly and starve
round robin (RR)
each ready process gets a fixed time slice in turn; when it expires the process goes to the back of the queue
fair; every process responds within a bounded time, good for interactive use
context-switch overhead; a very short slice wastes time, a long one delays others
priority
the ready process with the highest priority runs first
important or time-critical work is done first
low-priority processes may starve unless priorities age
Worked example. Three processes arrive together with CPU times of 8, 4 and 2 ms. Compare the average waiting time under FCFS (in arrival order A, B, C) and under shortest job first.
FCFS: A waits 0, B waits 8, C waits 12; average $(0 + 8 + 12)/3 = 6.7\ \text{ms}$. SJF runs C, B, A: C waits 0, B waits 2, A waits 6; average $2.7\ \text{ms}$. The total work is the same 14 ms either way; the order decides who waits. Round robin with a 2 ms slice would give A, B and C each a turn in the first 6 ms, so C finishes at 6 ms, B at 12 ms and A at 14 ms: the most responsive, not the fastest on average.
Process states
A process is new, ready (waiting for the CPU), running, blocked 阻塞 (waiting for I/O or a lock), or terminated. When its time slice ends it goes running → ready; when it requests I/O it goes running → blocked; when the I/O finishes it goes blocked → ready.
The three states and why a process moves.Running: the process has the processor. Ready: it could run but is waiting for the processor. Blocked: it cannot run until something else happens. Reasons for each transition, which the exam asks for one at a time: running to ready when its time slice ends, or when a higher-priority process becomes ready and pre-empts it (an interrupt); running to blocked when it requests input or output or waits for a resource or another process; blocked to ready when the I/O it was waiting for completes (signalled by an interrupt); ready to running when the scheduler dispatches it. A blocked process can never go straight to running: it must become ready first.
Process control block and context switch
For each process the OS keeps a process control block 进程控制块 (PCB) — the saved program counter, registers, state and memory info.
a context switch 上下文切换 suspends one process and starts another: it saves the state into one PCB and restores it from another. This small cost is paid on every switch.
the kernel 内核 (the core of the OS) acts as an interrupt handler 中断处理程序. When a device or the timer raises an interrupt, interrupt handling 中断处理 saves the running process and runs the right routine — this is what drives low-level scheduling.
"Outline how the kernel acts as an interrupt handler" (two marks). When an interrupt is raised, the kernel saves the state of the running process (its registers and program counter, in its process control block), identifies the source and priority of the interrupt, runs the appropriate interrupt service routine, and then restores the interrupted process (or a higher-priority one) so that execution continues. This is how the timer ends a time slice and how a completed I/O operation unblocks a process.
Inter-process communication
Processes are isolated, so the OS provides inter-process communication 进程间通信: pipes 管道 (one program's output feeds another's input), shared memory 共享内存 (a region several processes can use), and message passing.
עברית
תהליך הוא תוכנית בפועל — הקוד שלה, המצב הנוכחי, הזיכרון והקבפים הפתוחים שלה.
תזמון
המזמן בוחר איזה תהליך מוכן יופעל הבא, וכמה זמן:
Round Robin — לכל תהליך מגיע פרוסת זמן קבועה, ולאחר מכן הוא עובר לסוף בתור.
ראשון-הבא-ראשון-מושרת; קצר-הבא-קצר-מושרת; קצר-הבא-זמן-נותר (הפעל את המשימה עם הכי מעט עבודה שנותרה); עדיפויות; תורות משוב רב-שלביות.
המסחר הוא בין תגובה לבין נפח עבודה לבין צדק.
"תאר מה משמעות הרב-ריצות (Multi-tasking) וכיצד היא מועילה לניהול תהליכים."מספר תהליכים מוחזקים בזיכרון בו-זמנית והמעבד עובר ביניהם כל כך מהר עד שהם נראים כאילו רצים במקביל, כאשר לכל אחד מהם מוקצה תור של שימוש במעבד. היתרון: המעבד מעולם לא נשאר פעיל כשהליך אחד מחכה לכניסה או ליציאה, ולכן נפח העבודה גבוה והמשתמש יכול לעבוד על כמה תוכניות בו-זמנית. "הסבר את הצורך בתזמון." ישנם יותר תהליכים מאשר מעבדים, ולכן יש לקבל החלטה לגבי איזה תהליך יופעל הבא ולכמה זמן; תזמון מבטיח שכל תהליך יושג התקדמות, שהמעבד יהיה בשימוש מלא, שהזמני תגובה יהיו סבירים, ושעדיפויות יוכלו להיות נשמרות.
אותה עבודה בסדר שונה: קצר-הבא-קצר-מושרת מסדרת את המשימות הקצרות מראש, כך שרוב המשימות מחכות פחות, אך על סיכון שמשימה ארוכה תחכה לנצח.
תוכניות התזמון, כפי שהן נתונות להתאבחן במבחנים.
תוכנית
פונקציה
יתרון
חיסרון
ראשון-הבא-ראשון-מושרת (FCFS)
תהליכים רצים בסדר הגרסה שבו הם הגיעו לתור המוכנים, כל אחד להשלמתו
פשוטה; כל תהליך מטופל בתור, אף אחד לא מוחרם
תהליך ארוך מחזיק את כול הקצרים שאחוריו; תגובה גרועה
קורא קצר ביותר (SJF)
תהליך הממתין עם זמן הרצה המשוער הקצר ביותר ירץ הבא, עד סיומו
מצמצם את זמן ההמתנה הממוצע; רבים מהתהליכים הקצרים נגמרים במהירות
יש לדעת מראש את זמני הרצה; תהליך ארוך עשוי לעולם לא לרץ (רעב)
זמן שנותר קצר ביותר (SRT)
גרסת הפסקה של SJF: אם תהליך חדש מגיע ויש לו פחות זמן שנותר מאשר בתהליך הנמצא בהרצה, הוא לוקח את המקום
תהליכים קצרים מוגשים אף מהר יותר; תפוקה טובה
מעבר הקשרים רב יותר; תהליך ארוך עשוי להופסק חוזר ונשוא ולספול רעב
סירוב סביבתי (RR)
לכל תהליך ממתין מגיע תור עם פרוסת זמן קבועה; כאשר הפרוסה מסתיימת, התהליך עובר לסוף התור
הוגן; כל תהליך מקבל תגובה בתוך טווח זמן מוגבל, מתאים לשימוש אינטראקטיבי
עלות מעבר הקשרים; פרוסת זמן קצרה מדי מבזבזת זמן, ארוכה מדי מעכבת אחרים
עדיפות
תהליך הממתין בעל העדיפות הגבוהה ביותר ירץ ראשון
עבודה חשובה או דחופה בוצעת תחילה
תהליכים בעלי עדיפות נמוכה עשויים לספול רעב אלא אם כן העדיפויות משתנות עם הזמן
דוגמה מודגמת. שלושה תהליכים מגיעים יחד עם זמני CPU של 8, 4 ו-2 מ"ש. השוו את זמן ההמתנה הממוצע תחת FCFS (בסדר הגעתם A, B, C) ותחת קורא קצר ביותר.
FCFS: A מחכה 0, B מחכה 8, C מחכה 12; ממוצע $(0 + 8 + 12)/3 = 6.7\ \text{ms}$. SJF מרץ C, B, A: C מחכה 0, B מחכה 2, A מחכה 6; ממוצע $2.7\ \text{ms}$. סך העבודה זהה בכל מקרה, 14 מ"ש; הסדר קובע מי מחכה. סירוב סביבתי עם פרוסת זמן של 2 מ"ש יניב לתהליכים A, B ו-C תור כל אחד בתוך 6 המ"ש הראשונים, כך ש-C יסיים ב-6 מ"ש, B ב-12 מ"ש ו-A ב-14 מ"ש: התגובה הכי טובה, אך לא המהירה בממוצע.
תכנון קורא ראשון-משרת ראשון של ארבעה תהליכיםסירוב סביבתי: לכל תהליך מגיע תור עם פרוסת זמן קבועה, ולאחר מכן הרץ הבא (בניגוד לקורא ראשון-משרת ראשון)
מצבי תהליך
לתהליך יש חדש, ממתין (מחכה ל-CPU), בהרצה, חסום (מחכה לפעולת I/O או לנעילה), או מופעל. כאשר פרוסת הזמן שלו מסתיימת, הוא עובר מלהרצות למצב המתנה; כאשר הוא מבקש I/O, הוא עובר מלהרצות למצב חסום; כאשר ה-I/O נגמר, הוא עובר ממצב חסום למצב המתנה.
תהליך עובר בין מצבי החדש, הממתין, ההרצה, החסום והמופעל
שלושת המצבים והסיבות לעברת תהליך.הרצה: התהליך מחזיק במעבד. ממתין: הוא יכול היה לרץ אך מחכה למעבד. חסום: הוא לא יכול לרץ עד שתתרחש פעולה אחרת. סיבות לכל מעבר, שהבחינה דורשת ציון אחד בכל פעם: הרצה לממתין כאשר פרוסת הזמן שלו מסתיימת, או כאשר תהליך בעל עדיפות גבוהה הופך לממתין והופסק אותו (הפרעה); הרצה לחסום כאשר הוא מבקש כניסה או יציאה או מחכה למשאב או לתהליך אחר; חסום לממתין כאשר ה-I/O שבו חיכה נגמר (מוסמן על ידי הפרעה); ממתין להרצה כאשר המתכנן מעביר אותו. תהליך חסום לעולם לא יכול לעבור ישירות להרצה; הוא חייב להפך לממתין תחילה.
בלוק בקרת תהליך ומעבר הקשרים
עבור כל תהליך, מערכת ההפעלה שומרת בלוק בקרת תהליך (PCB) — כונן התוכנית שמור, רשומות, מצב ומידע על הזיכרון.
מעבר הקשרים שומר את מצב תהליך אחד וטוען את מצב תהליך אחר
מעבר הקשרים משהה תהליך אחד ומפעיל תהליך אחר: הוא שומר את המצב ל-PCB אחד ומשחזר אותו מ-PCB אחר. עלות קטנה זו משולמת בכל מעבר.
ה-ליבה (הליבה של מערכת ההפעלה) פועלת כ-מטפל הפסקות. כאשר התקן או השעון מייצרים הפסקה, טיפול בהפסקות שומר על התהליך הרץ ומפעיל את התוכנית הנכונה — זהו המנגנון שמניע את טיוור נמוך-רמה.
"ספק סקירה כיצד הליבה פועלת כמטפל הפסקות (שתי נקודות)." כאשר הפסקה מופעלת, הליבה שומרת על המצב של התהליך הרץ (הרישומים והמדדן התוכנית, בבלוק בקרת התהליך שלו), זיהוי המקור והעדיפות של ההפסקה, מפעיל את תוכנית שירות ההפסקה המתאימה, ואז משחזר את התהליך שהופסק (או תהליך בעל עדיפות גבוהה יותר) כך שהביצוע ימשיך. זוהי הדרך שבה השעון מסתיים במפרק זמן וכיצד פעולת I/O שהושלמה משחררת תהליך מממתנה.
תקשורת בין-תהליכית
תהליכים מבודדים, ולכן מערכת ההפעלה מספקת תקשורת בין-תהליכית: צינורות (הפלט של תוכנית אחת מזין את הקלט של אחרת), זיכרון משותף (אזור שניתן לשימוש על ידי מספר תהליכים), ושידור הודעות.
Explore · חקור
The life of a process · חיי התהליך
Tap round the loop a process travels. It only runs when the scheduler picks it; needing I/O sends it to blocked, and finishing its time slice sends it back to ready — round and round until it's done. · תקף סביב המעגל בתהליך שנעה. הוא רק רץ כשהמתכנן בוחר אותו; צורך ב-I/O שולח אותו למצב חסום, והסתיימות זמן הביצוע שלו שולחת אותו חזרה למצב מוכן — סביב ומסביב עד שהסתיים.
Each process gets its own virtual address space 虚拟地址空间 — a clean, contiguous range of addresses the OS maps to physical memory. This gives each process a simple space, protects processes from each other, and lets the total memory exceed physical RAM.
In paging, the virtual space is split into fixed-size pages 页 and physical memory into same-sized frames 页框. A page table maps each page to a frame. If an accessed page is not in RAM — a page fault 缺页 — the OS reads it from the swap file 交换文件 into a frame, evicting another page if RAM is full. Frequent faults cause thrashing 抖动 (disk thrashing), where the OS spends most of its time swapping pages instead of doing useful work.
In segmentation 分段, memory is split into variable-sized logical segments (code, stack, heap), each with its own permissions. Many systems use paging within segments.
"Explain what is meant by virtual memory" (three marks).Secondary storage (disk) is used to extend the RAM, so that the available memory appears larger than the physical memory; the address space of a process is divided into pages, and only the pages currently needed are held in RAM while the rest wait on disk; pages are swapped between RAM and disk as required, and the OS translates each virtual address into a physical one. Why an OS needs it: the programs running may need more memory than the RAM installed; it lets more (or larger) programs run at once; a program can be larger than the physical memory; memory is used efficiently because only the active parts of programs occupy RAM.
Paging against segmentation: the difference the exam wants.Paging divides memory into blocks of fixed size (pages and frames) chosen by the hardware, with no regard to the program's structure, and the mapping is invisible to the programmer; segmentation divides a program into variable-sized logical units (a procedure, an array, the stack) whose sizes and boundaries follow the program, so a segment can be protected or shared as a unit. "Describe the process of segmentation": the program is split into segments of different sizes, each given a segment number; a segment table records where each segment starts in memory and how long it is; a logical address is a segment number plus an offset, and the OS adds the offset to the segment's base address to find the physical location.
"Explain what is meant by disk thrashing" and when it occurs.Disk thrashing 磁盘抖动 is the state in which pages are swapped in and out of RAM so frequently that the processor spends more time moving pages than executing instructions, and the system slows almost to a halt. It occurs when the RAM is too small for the pages the running processes need (their working sets): a page just moved out is needed again almost at once, so it is fetched back, which pushes out another page that is soon needed, and so on. Too many processes, or a program that accesses memory unpredictably, brings it on; more RAM or fewer processes cure it.
עברית
לכל תהליך מוקצה מרחב כתובות וירטואלי אישי — טווח כתובות נקי ורציף שמערכת ההפעלה מקשר לזיכרון פיזי. זה נותן לכל תהליך מרחב פשוט, מגן על תהליכים אחד מהשני, ומאפשר לזיכרון הכולל לעלות על RAM פיזי.
ב-חלוקה, המרחב הווירטואלי מחולק ל-דפים בגודל קבוע וזיכרון פיזי ל-מסגרות באותו גודל. טבלת דפים מייצבת כל דף למסגרה. אם הדף שנעשה לו שימוש אינו ב-RAM — שגיאת דף — מערכת ההפעלה קוראת אותו מה-קובץ החלפה למסגרה, ומדחיקה דף אחר אם ה-RAM מלא. הפסקות תכופות גורמות ל-דחיפה (דחיפת דיסק), שבו מערכת ההפעלה מבזבזת את רוב זמנה בהחלפת דפים במקום לעשות עבודה מועילה.
חלוקה מייצבת כל דף של זיכרון לוגי למסגרת של זיכרון פיזי
ב-מקטעים, הזיכרון מחולק למקטעים לוגיים בגודל משתנה (קוד, סטק, הייפ), שכל אחד מהם יש לו הרשאות משלו. מערכות רבות משתמשות בחלוקה בתוך מקטעים.
מקטעת מייצבת מקטעים בגודל משתנה באמצעות טבלת מפתח מקטעים
"הסבר מה מתכוונים בזיכרון וירטואלי (שלוש נקודות)." אחסון משני (דיסק) משמש להרחיב את ה-RAM, כך שהזיכרון הזמין נראה גדול מהזיכרון הפיזי; מרחב הכתובות של תהליך מחולק ל-דפים, והדפים הנדרשים כרגע בלבד נשמרים ב-RAM בעוד שארם מחכים על הדיסק; דפים מוחלפים בין R-RAM ודיסק לפי הצורך, ומערכת ההפעלה ממירה כל כתובת וירטואלית לכתובת פיזית. מדוע מערכת הפעלה זקוקה לכך: התוכניות הרצות עשויות לצרוך יותר זיכרון מאשר ה-RAM המותקן; זה מאפשר ליותר (או לתוכניות גדולות יותר) לרץ בו-זמנית; תוכנית יכולה להיות גדולה מהזיכרון הפיזי; זיכרון משמש בצורה יעילה מכיוון שרק החלקים הפעילים של התוכניות תופסים RAM.
חלוקה מול מקטעת: ההבדל שבמבחן.חלוקה מחלקת זיכרון לחסימות בגודל קבוע (דפים ומסגרות) שנבחרו על ידי החומרה, ללא קשר למבנה התוכנית, והמיפוי הוא בלתי נראה למפתח; מקטעה מחלקת תוכנית ל-יחידות לוגיות בגודל משתנה (פרוצדורה, מערך, הסטק) שגודלן וגבולותיהם עוקבים אחר התוכנית, כך שמקטע ניתן להגנה או לשיתוף כיחידה. "תאר את תהליך המקטעה": התוכנית מחולקת למקטעים בגדלים שונים, שכל אחד מקבל מספר מקטע; טבלת מקטעים מקלסת היכן מתחיל כל מקטע בזיכרון ובאיזה אורך הוא; כתובת לוגית היא מספר מקטע פלוס סטייה, ומערכת ההפעלה מוסיפה את הסטייה למכתב הבסיס של המקטע כדי למצוא את המיקום הפיזי.
"הסבר מה מתכוונים בדחיפת דיסק ומתי היא מתרחשת." דחיפת דיסק היא המצב שבו דפים מוחלפים כניסה ויציאה מ-RAM כל כך תכופות שהמעבד מבזבז יותר זמן בהזזת דפים מאשר בביצוע הוראות, והמערכת מאטה כמעט לקיפא. היא מתרחשת כאשר ה-RAM קטן מדי לדפים שהתהליכים הרצים צריכים (הסט העובד שלהם): דף שעודנו הועבר החוצה נדרש שוב כמעט מיד, ולכן מושב בחזרה, מה שמדחיק דף אחר שנדרש בקרוב, וכך הלאה. מספר רב מדי של תהליכים, או תוכנית הנגשת לזיכרון באופן לא צפוי, מובילות לכך; יותר RAM או פחות תהליכים מטפלים בבעיה.
Explore · חקור
What happens on a page fault · מה קורה בעת תקלת דף (Page Fault)?
Step through a page fault. When the program touches a page that isn't in RAM, the OS quietly fetches it from disk and updates the page table — so the program sees more memory than physically exists. · מעבר צעד אחר צעד בתקלת דף: כאשר התוכנית פונה לדף שאינו קיים ב-RAM, מערכת ההפעלה טוענת אותו בשקט מהדיסק ומעדכנת את טבלת המדורים — כך שהתוכנית רואה יותר זיכרון מאשר קיים בפועל.
How an interpreter runs a program · כיצד פרשן מפעיל תוכנית
Syllabus · סיילבוס
English
Candidates should be able to:
Notes and guidance
Show understanding of how an interpreter can execute programs without producing a translated version
Show understanding of the various stages in the compilation of a program
Including lexical analysis, syntax analysis, code generation and optimisation
Show understanding of how the grammar of a language can be expressed using syntax diagrams or Backus-Naur Form (BNF) notation
Show understanding of how Reverse Polish Notation (RPN) can be used to carry out the evaluation of expressions
עברית
המועמדים צריכים להיות מסוגלים:
הערות והנחיות
הוכח הבנה כיצד מפרש יכול לבצע תוכניות ללא יצירת גרסה מותרגמת
הוכח הבנה של השלבים השונים בתהליך התרגום של תוכנית
כולל ניתוח לקסיקלי, ניתוח סינטקטי, יצירת קוד ואופטימיזציה
להראות הבנה כיצד הגרמטיקה של שפה יכולה להתבטא באמצעות תרשימי סyntaxis או Backus-Naur Form (BNF)
להראות הבנה כיצד Reverse Polish Notation (RPN) יכול לשמש לבצע חישוב ביטויים
Source: Cambridge International syllabus · מקור: הסיילבוס הבינלאומי של קמבריד'ג'
English
An interpreter 解释器 translates and runs the source at the same time. For each statement it reads the line, does lexical and syntax analysis, checks types, then executes the action, and moves on. Errors are reported immediately and it usually stops; no executable is produced. The translation is redone every run (slower), but it gives fast development feedback and is portable.
"Explain how an interpreter executes a program without producing a translated version" (three marks). The interpreter takes one statement (line) at a time, translates (analyses) it, and executes it immediately, before moving to the next; no translated version of the whole program is created or stored, so every statement is translated every time it is executed, including each pass through a loop; if a statement contains an error, execution stops there and the error is reported. This is what makes an interpreter good for developing and testing (errors are found as they are reached, and a change can be tried at once) but slower for running finished programs.
עברית
פרשן תורגם ורץ את המקור באותו זמן. עבור כל הודעה הוא קורא את השורה, ביצע ניתוח לקסיקלי וסינטקטי, בודק סוגים, ואז מבצע את הפעולה, ועובר על. שגיאות מדווחות מיד והוא בדרך כלל נ עצור; אין מוצר可執行. התרגום מתבצע מחדש בכל ריצה (איטי יותר), אך זה נותן משוב פיתוח מהיר והוא נייד.
"הסבר כיצד פרשן מבצע תוכנית ללא יצירת גרסה מותרגמת (שלוש נקודות)." הפרשן לוקח הודעה אחת (שורה) בכל פעם, מתרגם (נותח) אותה, ומבצע אותה מיד, לפני מעבר הבא; אין גרסה מותרגמת של כל התוכנית שנוצרה או מאוחזת, כך שכל הודעה מתורגמת בכל פעם שהיא מבוצעת, כולל כל מעבר דרך לולאה; אם הודעה מכילה שגיאה, הביצוע נ עצר שם והשגיאה מדווחת. זה מה שהופך את הפרשן לטוב לפיתוח ולבדיקה (שגיאות נמצאות כשהן מופגשות, ושינוי ניתן לנסות מיד) אך איטי לרצת תוכניות מוגמרות.
A compiler 编译器 turns source into machine code 机器码 in phases:
lexical analysis 词法分析 — the lexer groups characters into tokens 词法单元 (keywords, identifiers, operators, literals), discarding whitespace and comments.
syntax analysis (parsing) 语法分析 — check the tokens fit the grammar and build an abstract syntax tree 抽象语法树. A missing bracket gives a syntax error 语法错误.
semantic analysis 语义分析 — check the program makes sense (variables declared, types match).
code generation 代码生成 — walk the tree and emit target code, choosing registers and layouts.
code optimisation 代码优化 — remove redundant work, fold constants, reorder for the pipeline.
The output is an executable.
The purpose of each stage, in the words that score.Lexical analysis: removes white space and comments; converts the characters of the source code into tokens (keywords, identifiers, operators, constants), checking that each is valid in the language; enters identifiers into the symbol table 符号表. Syntax analysis: checks that the sequence of tokens obeys the grammar (syntax rules) of the language; builds a parse tree (abstract syntax tree); reports syntax errors; type checking and the checking of variable declarations are sometimes counted here as semantic analysis. Code generation: converts the checked tree into object code or machine code (possibly via an intermediate code), allocating memory and registers. Optimisation: makes the code run faster or use less memory, by removing redundant instructions, combining or simplifying calculations, and reorganising loops, without changing what the program does. The matching question pairs each stage with one of these descriptions.
ניתוח סינטקטי (פרסום) — בודק שהטוקנים עומדים בגרממר ובונה עץ סינטקסי מ مجرد. סוגריה חסר גורם ל-שגיאת סינטקס.
ניתוח סמנטי — בודק שהתוכנית הגיונית (משתנים הוגדרו, סוגים תואמים).
יצירת קוד — עובר על העץ ומפיק קוד יעד, בוחר רגיסטר ומייצובים.
אופטימיזציה של קוד — מסיר עבודה כפולה, מקפל קבועים, ממערך מחדש עבור השלבה.
התוצאה היא קובץ מתבצע.
שלבי הה compilation, מקוד מקור לקובץ מתבצע אופטימיזציה
המטרה בכל שלב, במילים שמביאות נקודות.ניתוח מילולי: מסיר רווחים ופירושים; ממיר את תוויות קוד המקור ל-טוקנים (מילות מפתח, זיהויים, אופרטורים, קבועים), בודק שכל אחד מהם חוקי בשפה; מכניס זיהויים ל-טבלת הסמלים. ניתוח סינטקטי: בודק שהסדר הטוקנים עומד ב-גרממר (כללי סינטקס) של השפה; בונה עץ פרסום (עץ סינטקסי מ مجرد); מדווח על שגיאות סינטקס; בדיקת סוגים ובדיקת הגדרת משתנים לעיתים סופרים כאן כניתוח סמנטי. יצירת קוד: ממיר את העץ הנבדק ל-קוד אובייקט או קוד מכונה (אפשר דרך קוד ביניים), מפנה זיכרון ורגיסטרים. אופטימיזציה: הופעת הקוד מהירה יותר או שימוש ב-פחות זיכרון, על ידי הסרת הוראות מועדות, מיזוג או פישוט חישובים, וארגון מחדש של לולאות, מבלי לשנות את מה שהתוכנית עושה. שאלת התאמה מחברת כל שלב עם אחת מהתיאורים האלה.
Explore · חקור
The phases of compilation · שלבי ההרכבה
Step through what a compiler does to your source. Each phase hands its output to the next — characters become tokens, tokens become a tree, the tree becomes optimised machine code. · מעבר שלב אחר שלב על מה שהרוכב עושה בקוד המקור שלך. כל שלב מעביר את הפלט שלו לשלב הבא — תווים הופכים לטוקנים, טוקנים הופכים לעץ, העץ הופך לקוד מכונה אופטימיזציה.
16.2
Grammar: BNF and syntax diagrams · גרממר: BNF ותרשימי סינטקס
English
A grammar 文法 says which token sequences are valid programs.
Backus-Naur Form 巴科斯-诺尔范式 (BNF) is textual. A production rule 产生式 has the form:
Each alternative is a sequence of terminal 终结符 symbols (literal text) and non-terminal 非终结符 symbols (other rule names):
The recursive third rule expresses "a letter followed by any number of letters or digits". An IF statement:
A syntax diagram 语法图 (railroad diagram) shows the same thing graphically: boxes for non-terminals, rounded boxes for terminals, arrows for valid paths, loops for repetition. The two notations are equivalent. The parser uses the grammar to decide whether a program is valid.
Reading the exam's diagrams. Each diagram defines one non-terminal; follow the arrows from the entry to the exit, and every path you can trace is a valid string. A choice of boxes side by side is a set of alternatives; a loop back is "repeat as many times as you like"; a box for another non-terminal means "insert anything that rule allows". "State why the string is invalid" wants the rule it breaks, in words: 9K is invalid as a variable because the first character must be a letter, not a digit; JJ90 is an invalid passcode if the rule allows only one letter before the digits, or if J is not in the set of letters listed. Always check the string against the set of characters the diagram actually allows, not against what a real language would accept.
Writing BNF from a diagram. Each diagram becomes one rule <name> ::= ...; alternatives are separated by |; a sequence is written one symbol after another; and repetition is written with recursion, because BNF has no loop symbol: "one or more letters" is <word> ::= <letter> | <letter><word>, and "zero or more digits after a letter" is <variable> ::= <letter> | <letter><digits> with <digits> ::= <digit> | <digit><digits>.
Worked example. Complete the BNF for a vehicle registration that must begin with two letters (from A B C) followed by one, two or three digits (from 0 1 2).
AB12 is valid; A12 is not (only one letter); AB1234 is not (four digits); AD1 is not (D is not a listed letter). Asked to add a constraint such as "the third character may also be a symbol", add the extra alternative to the rule for that position only, and define <symbol> with its own rule.
Worked example. Write BNF for an expression that is a variable, followed by an operator, followed by either a variable or a number, where a variable is a single lower-case letter from a b c and an operator is + or -.
The recursive <number> rule allows any number of digits; the two alternatives of <expression> cover both cases named in the definition. Keep every non-terminal in angle brackets and every terminal without them.
עברית
גרממר אומר איזה סדרות טוקנים הן תוכניות חוקיות.
פורמט באקוס-נאור (BNF) הוא טקסטואלי. כלל ייצור יש לו צורה:
<symbol> ::= alternative1 | alternative2 | ...
כל אלטרנטיבה היא סדרה של סימנים טורמיינליים (טקסט מפורש) וסימנים לא-טורמיינליים (שמות כללים אחרים):
הכלל הרקורסיבי השלישי מבטא "אות אחריה כל מספר של אותיות או ספרות". הבעה IF:
<if-statement> ::= IF <condition> THEN <statement> ENDIF
| IF <condition> THEN <statement> ELSE <statement> ENDIF
תרשים סינטקטי (תרשים מסילה) מראה אותו דבר גרפית: תיבות ללא-טורמיינלים, תיבות מעוגלות לטורמיינלים, חצים למסלולים חוקיים, לולאות לחזרה. שתי הנוטרציות שקולות. הפרסמר משתמש בגרממר כדי להחליט אם תוכנית היא חוקית.
תרשים סינטקטי (מסילה) להבעת הצגהתרשים סינטקטי וכלל BNF אומרים אותו דבר: בחירה הופכת לאלטרנטיבות המופרדות על ידי פסים, ולולאה הופכת לכלל שמתייחס לעצמו
קריאת תרשימי הבחינה. כל תרשים מגדיר לא-טורמיינל אחד; עקוב אחר החצים מהכניסה ליציאה, וכל מסלול שתוכל לעקוב אחריו הוא שרשרת חוקית. בחירה של תיבות בצדדים זה של סט של אלטרנטיבות; לולאה חוזרת היא "חזור כמה פעמים שתרצה"; תיבה עבור לא-טורמיינל אחר פירושה "הכנס כל מה שהכלל הזה מאפשר". "הסבר מדוע השרשרת לא חוקית" דורש את הכלל שהיא שוברת, במילים: 9K לא חוקי כמזהה כי התווית הראשונה חייבת להיות אות, ולא ספרה; JJ90 הוא קוד מעבר לא חוקי אם הכלל מאפשר רק אות אחת לפני הספרות, או אם J אינו בקבוצת האותיות המפורטת. תמיד בדוק את השרשרת מול סט התוויות שהתרשים בפועל מאפשר, ולא מול מה ששפה אמיתית הייתה מקבלת.
כתיבת BNF מתרשים. כל תרשים הופך לכלל אחד <name> ::= ...; אלטרנטיבות מופרדות על ידי |; רצף נכתב סמל אחר סמל; וחזרה על עצמה נכתבת עם רקורסיה, כי ל-BNF אין סמל לולאה: "אחד או יותר אותיות" הוא <word> ::= <letter> | <letter><word>, ו"אפס או יותר ספרות לאחר אות" הוא <variable> ::= <letter> | <letter><digits> עם <digits> ::= <digit> | <digit><digits>.
דוגמה פתורה. השלימו את ה-BNF עבור תעודת רישום רכב שחייבת להתחיל בשתי אותיות (מA B C) ולאחריהן אחת, שתיים או שלושה ספרות (מ0 1 2).
<letter> ::= A | B | C
<digit> ::= 0 | 1 | 2
<digits> ::= <digit> | <digit><digit> | <digit><digit><digit>
<registration> ::= <letter><letter><digits>
AB12 תקין; A12 לא תקין (אות אחת בלבד); AB1234 לא תקין (ארבע ספרות); AD1 לא תקין (D אינה אות ברשימה). מבקשים להוסיף הגבלה כמו "התווית השלישית יכולה להיות גם סמל", הוסיפו את האלטרנטיבה הנוספת לכלל של המיקום הזה בלבד, והגדירו <symbol> עם הכלל שלו.
דוגמה פתורה. כתבו BNF עבור ביטוי שהוא משתנה, שלאחריו אופרטור, שלאחריו או משתנה או מספר, כאשר משתנה הוא אות קטנה בודדת מa b c ואופרטור הוא + או -.
<variable> ::= a | b | c
<operator> ::= + | -
<number> ::= <digit> | <digit><number>
<expression> ::= <variable><operator><variable> | <variable><operator><number>
הכלל הרקורסיבי <number> מאפשר מספר כלשהו של ספרות; שתי האלטרנטיבות של <expression> מכסות את שני המקרים הנזכרים בהגדרה. שמרו על כל נונטרמינל בסוגריים尖 brackets וכל טרמינל ללא סוגריים.
In infix 中缀 notation the operator sits between its operands (3 + 4 * 2), needing brackets and precedence rules. In Reverse Polish Notation 逆波兰表示法 (RPN, postfix 后缀) the operator follows its operands (3 4 2 * +), needing no brackets.
Converting infix to RPN
Use an operator stack 栈. Scan left to right: output an operand; for an operator, first pop any stacked operators of higher or equalprecedence 优先级 to the output, then push it; push (; on ) pop to output until the matching (. At the end, pop all operators. Example: (3 + 4) * 2 → 3 4 + 2 *.
Evaluating RPN
Use a stack of operands. Scan left to right: push each operand; on an operator, pop the top two, apply it, and push the result. Evaluating 3 4 2 * +:
Token
Stack
3
3
4
3, 4
2
3, 4, 2
*
3, 8
+
11
Result: 11. RPN needs no brackets at evaluation time and suits a stack machine — which is how the JVM and many bytecode 字节码 interpreters work.
"Explain why RPN is used to evaluate expressions" (two marks). In RPN the operators appear in the order in which they are applied, so an expression can be evaluated in a single left-to-right pass with no brackets and no precedence rules; it is therefore simpler and faster for the compiler or interpreter to process. "Identify, with reasons, a suitable data structure": a stack, because evaluation needs the most recently pushed operands first (last in, first out): each operand is pushed, and each operator pops the top two, applies itself, and pushes the result. Show the stack contents after every token when asked.
Converting infix to RPN by hand. (1) Fully bracket the expression using the precedence rules; (2) move each operator to just after the closing bracket of its own pair; (3) remove the brackets. So $(a - b) * (a + c) / 7$ becomes $((a - b) * (a + c)) / 7$, then a b - a c + * 7 /. Note that * and / are applied left to right, so the division is the last operator, not the multiplication. More conversions: $((7 + 3) - (2 * 8)) / 6$ is 7 3 + 2 8 * - 6 /; $(7 - 2 + 8) / (9 - 5)$ is 7 2 - 8 + 9 5 - /; $a * b + b - d + 15$ is a b * b + d - 15 +; $(2 - 6) * (13 + 7) / 5$ is 2 6 - 13 7 + * 5 /.
Converting RPN back to infix. Work through the RPN with a stack of expressions: push each operand; for each operator pop two, write them either side of it in brackets, and push the result. So a b / 4 * a b + - is $((a / b) * 4) - (a + b)$; 5 2 + 9 3 - / 3 * is $((5 + 2) / (9 - 3)) * 3$; b a c - + d b + * c / is $((b + (a - c)) * (d + b)) / c$; a b - c + c a - * d / is $(((a - b) + c) * (c - a)) / d$. Keep the brackets: dropping them can change the meaning.
Worked example. Evaluate a b - c d + * e / when $a = 17$, $b = 5$, $c = 7$, $d = 3$ and $e = 10$, showing the stack.
token
action
stack (top on the right)
a
push 17
17
b
push 5
17, 5
-
pop 5 and 17, push $17 - 5$
12
c
push 7
12, 7
d
push 3
12, 7, 3
+
pop 3 and 7, push $7 + 3$
12, 10
*
pop 10 and 12, push $12 \times 10$
120
e
push 10
120, 10
/
pop 10 and 120, push $120 / 10$
12
Result 12. The order of the pops matters for - and /: the value popped second is the left operand, so a b - is $a - b$, not $b - a$. Two more, in the same way: d a b + * c a - / with $a = 6, b = 12, c = 15, d = 5$ gives $5 \times (6 + 12) / (15 - 6) = 90 / 9 = 10$; c a - b d + * b c + / with $a = 4, b = 12, c = 24, d = 6$ gives $(24 - 4) \times (12 + 6) / (12 + 24) = 360 / 36 = 10$.
Worked example. Convert $(A + B) \times (C - D)$ to RPN, then evaluate $(3 + 4) \times (5 - 2)$. Scan left to right using an operator stack. Push (; output A; push +; output B; on ) pop back to the matching (, giving A B + so far. Push ×, and the second bracket behaves the same way, giving C D -. At the end pop the ×. Result: A B + C D - ×. To evaluate the numbers, use a stack of operands: push 3, push 4; + pops both and pushes 7; push 5, push 2; - pops both and pushes 3; × pops 7 and 3 and pushes 21. Two things make these reliable: the operands keep their original order through the conversion (only the operators move), and every operator acts on the two values immediately below it on the stack.
עברית
בסימון אינפיקס האופרטור יושב בין הארגומנטים שלו (3 + 4 * 2), דורש סוגריים וחוקי עדיפות. בסימון פולין הפוכה (RPN, פוסטפיקס) האופרטור עוקב אחר הארגומנטים שלו (3 4 2 * +), ואינו דורש סוגריים.
המרת אינפיקס ל-RPN
השתמש במופע (stack) של מופעים. סרוק משמאל לימין: הפלט אופרנד; עבור מופע, קודם כל פלט כל המופעים המצטברים עם עדיפותגבוהה או שווה, ואז הדחס אותו; הדחס (; על ) פלט עד למתאם (. בסוף, פלט את כל המופעים. דוגמה: (3 + 4) * 2 → 3 4 + 2 *.
חישוב RPN
השתמש במופע של אופרנדים. סרוק משמאל לימין: הדחס כל אופרנד; על מופע, פלט את שני האופרנדים העליונים, יישם את הפעולה, והדחס את התוצאה. חישוב 3 4 2 * +:
טוקן
ערימה
3
3
4
3, 4
2
3, 4, 2
*
3, 8
+
11
תוצאה: 11. ל-RPN אין צורך בסוגריים בזמן הערכה והוא מתאים למכונת ערימה — כפי שה-JVM ורבים מפרשני בייטקוד פועלים.
"הסבר מדוע משתמשים ב-RPN כדי לבצע ערכה של ביטויים" (שתי נקודות). ב-RPN האופרטורים מופיעים בסדרה שבו הם מופעלים, כך שניתן לבצע ערכה של ביטוי ב-מעבר יחיד משמאל לימין עם ללא סוגריים וללא כללי עדיפות; ולכן קל ומהיר יותר לקומפילר או לפרשר לעבד אותו. "זיהה, עם הסברים, מבנה נתונים מתאים":ערימה, מכיוון שהערכה דורשת את הארגומנטים שנדחסו באחרונה תחילה (אחרון נכנס, אחרון יוצא): כל ארגומנט נדחס, וכל אופרטור מפלט שני העליונים, מבצע את פעולתו, ומדחס את התוצאה. הצג את תוכן הערימה לאחר כל טוקן כאשר מבוקש.
המרת אינפיקס ל-RPN באופן ידני. (1) חבר סוגריים מלאים לביטוי לפי כללי העדיפות; (2) הזז כל אופרטור לגוף הסוגר הפותח של זוג הסוגרים שלו; (3) הסר את הסוגריים. כך $(a - b) * (a + c) / 7$ הופך ל$((a - b) * (a + c)) / 7$, ואז לa b - a c + * 7 /. שימו לב כי * ו/ מופעלים משמאל לימין, ולכן החלוקה היא האופרטור האחרון, ולא הכפל. המרות נוספות: $((7 + 3) - (2 * 8)) / 6$ הוא 7 3 + 2 8 * - 6 /; $(7 - 2 + 8) / (9 - 5)$ הוא 7 2 - 8 + 9 5 - /; $a * b + b - d + 15$ הוא a b * b + d - 15 +; $(2 - 6) * (13 + 7) / 5$ הוא 2 6 - 13 7 + * 5 /.
המרת RPN חזרה לאינפיקס. עברו על ה-RPN בעזרת ערימה של ביטויים: הדחסו כל ארגומנט; עבור כל אופרטור מפלטו שניים, כתבו אותם משני צדדיו בתוך סוגריים, והדחסו את התוצאה. כך a b / 4 * a b + - הוא $((a / b) * 4) - (a + b)$; 5 2 + 9 3 - / 3 * הוא $((5 + 2) / (9 - 3)) * 3$; b a c - + d b + * c / הוא $((b + (a - c)) * (d + b)) / c$; a b - c + c a - * d / הוא $(((a - b) + c) * (c - a)) / d$. שמרו על הסוגריים: השלמתם עלולה לשנות את המשמעות.
דוגמה מפורטת. בצעו ערכה של a b - c d + * e / כאשר $a = 17$, $b = 5$, $c = 7$, $d = 3$ ו$e = 10$, תוך הצגת הערימה.
טוקן
פעולה
ערימה (העליון מימין)
a
הדחס 17
17
b
הדחס 5
17, 5
-
פופ 5 ו-17, פוסט $17 - 5$
12
c
פוסט 7
12, 7
d
פוסט 3
12, 7, 3
+
פופ 3 ו-7, פוסט $7 + 3$
12, 10
*
פופ 10 ו-12, פוסט $12 \times 10$
120
e
פוסט 10
120, 10
/
פופ 10 ו-120, פוסט $120 / 10$
12
תוצאה 12. סדר ההפלטות חשוב עבור - ו/: הערך הנפלט שני הוא הארגומנט השמאלי, כך ש-a b - הוא $a - b$, ולא $b - a$. עוד שניים, באותו אופן: d a b + * c a - / עם $a = 6, b = 12, c = 15, d = 5$ נותן $5 \times (6 + 12) / (15 - 6) = 90 / 9 = 10$; c a - b d + * b c + / עם $a = 4, b = 12, c = 24, d = 6$ נותן $(24 - 4) \times (12 + 6) / (12 + 24) = 360 / 36 = 10$.
דוגמה מפורטת. המיר $(A + B) \times (C - D)$ ל-RPN, ולאחר מכן חשב את $(3 + 4) \times (5 - 2)$. סרוק משמאל לימין תוך שימוש ב-סטק של מקצועות. פוסט (; צא ⟨A⟩; פוסט +; צא ⟨B⟩; על ) פופ אחורה למצאת ⟨(⟩ המתאימה, מה שמניב עד כה ⟨A B +⟩. פוסט ⟨×⟩, והסוגריים השנייה מתנהגים באותו אופן, ומניבים ⟨C D -⟩. בסוף פופ את ⟨×⟩. תוצאה: A B + C D - ×. כדי לחשב את המספרים, השתמש ב-סטק של מאורכים: פוסט 3, פוסט 4; ⟨+⟩ פופ שניהם ופוסט 7; פוסט 5, פוסט 2; ⟨-⟩ פופ שניהם ופוסט 3; ⟨×⟩ פופ 7 ו-3 ופוסט 21. שני דברים הופכים את אלו לאמינים: המאורכים שומרים את הסדר המקורי שלהם במהלך ההמרה (רק המקצועות זזים), וכל מקצוע פועל על שני הערכים המיידיים מתחתיו בסטק.
Explore · חקור
Operator precedence — what RPN removes · עדיפות מפעילים — מה ש-RPN מסיר
In ordinary infix maths × and ÷ bind tighter than + and −, so you must apply rules in the right order. Reverse Polish Notation writes the operands first (3 4 2 × + 1 −), fixing the order so no precedence rules are needed. · במתמטיקה אינפיקס רגילה, × ו-÷ בעלי עדיפות גבוהה יותר מ-+ ו-−, ולכן יש ליישם את הכללים בסדר הנכון. נקודת פולין ההפוכה כותבת את האופרנדים קודם (3 4 2 × + 1 −), מה שמקבע את הסדר כך שאין צורך בכללי עדיפות.
Definitions the examiner accepts · הגדרות מקובלות בקורס
English
A definition question is marked against fixed wording. Learn these exactly, and give one answer only.
Term
Definition
multi-tasking
several processes held in memory at once, the processor switching between them so that they appear to run simultaneously
process
a program that has been loaded into memory and is being executed (or is ready to be)
running / ready / blocked
has the processor / waiting for the processor / cannot continue until an event such as I/O completes
scheduling
deciding which ready process gets the processor next, and for how long
pre-emptive scheduling
the running process can be interrupted and moved to ready so that another process runs
virtual memory
using secondary storage to extend RAM, holding only the pages currently needed in physical memory
paging
dividing memory and programs into fixed-size pages that are moved between disk and RAM as needed
segmentation
dividing a program into variable-sized logical segments, each mapped to memory by a segment table
disk thrashing
pages being swapped between RAM and disk so often that little useful processing is done
interpreter
translates and executes a program one statement at a time, without producing a translated version
compiler
translates a whole high-level program into machine (object) code before it is run
lexical analysis
converts the source code into tokens, removing white space and comments, and builds the symbol table
syntax analysis
checks that the tokens obey the grammar of the language and builds a parse tree
Backus–Naur Form
a notation for the grammar of a language: rules of the form <name> ::= alternatives built from terminals and non-terminals
Reverse Polish Notation
a way of writing expressions with each operator after its operands, so they can be evaluated with a stack and without brackets
עברית
שאלת הגדרה מוקדמת לפי טקסט קבוע. לימודן במדויק, ותן תשובה אחת בלבד.
מונח
הגדרה
ריבוי משימות
מספר תהליכים המוחזקים בזיכרון בו-זמנית, מעבד החולף ביניהם כך שהם נראים כאילו פועלים במקביל
תהליך
תוכנית שנטענה לזיכרון ומופעלת (או מוכנה להפעלה)
פעיל / ממתין / חסום
יש לו את המעבד / מחכה למעבד / אינו יכול להמשיך עד שאירוע כמו I/O הסתיים
תזמון
קביעת אילו תהליך ממתין יקבל את המעבד הבא, וכמה זמן
תזמון גונרטיבי
התהליך הפעיל יכול להיפסק ולהועבר למצב ממתין כך שתהליך אחר יופעל
זיכרון וירטואלי
שימוש באחסון משני כדי להרחיב את ה-RAM, תוך אחסון רק הדפים הנחוצים כרגע בזיכרון פיזי
חלוקה לדפים
חלוקת הזיכרון והתוכניות לדפים בעובי קבוע הנעים בין דיסק ל-RAM לפי הצורך
חלוקה לקטעים
חלוקת תוכנית לקטעים לוגיים בעובי משתנה, כל אחד מהם ממופה לזיכרון באמצעות טבלת קטעים
תזוזת דיסק
דפים המוחלפים בין ה-RAM לדיסק כל כך לעיתים קרובות שמעט עיבוד מועיל מתבצע
מפרש
מתרגם ומפעיל תוכנית משפט אחרי משפט, מבלי לייצר גרסה מתורגמת
קומפילר
תרגם תוכנת גובה גבוהה שלמה לקוד מכונה (קובץ ביצועים) לפני ההפעלה
ניתוח קלפי
ממיר את קוד המקור לטוקנים, מנקה רווחים ותגובות, ובונה טבלת סמלים
ניתוח סינטקטי
בודק שהטוקנים עומדים בדרישות הסינטקס של השפה ובונה עץ פירוק
צורת באקוס-נאור
סימון עבור הגרמטיקה של שפה: כללים מהצורה <name> ::= alternatives המבונים מטורמינלים ופוליתורמינלים
סימון פולני הפוך
דרך לכתיבת ביטויים כאשר כל אופרטור נמצא לאחר הארגומנטים שלו, כך שניתן לבצע אותם בעזרת ערימה וללא סוגריים
16.2
Exam tips · טיפים לבחינות
English
The OS questions are marked on named mechanisms: scheduling, memory management, I/O buffering and spooling, file management; for the interface, file names not addresses, clicks not commands, drivers, GUI.
Process states with their transitions and the reason for each; scheduling routines as function plus benefit plus drawback; the kernel saves state, identifies the interrupt, services it, restores.
Virtual memory: disk extends RAM, pages swapped, address translation; paging is fixed-size and invisible, segmentation is variable-size and logical; thrashing is swapping instead of working.
Interpreter: one statement at a time, translated then executed, nothing stored. Compiler stages: tokens and symbol table, grammar and parse tree, code, optimisation.
BNF: a rule per diagram, | for choice, recursion for repetition, terminals bare and non-terminals in angle brackets. Say which rule a string breaks.
RPN: operators after operands, evaluate with a stack, show every step; convert by fully bracketing; when converting back, keep the brackets.
Common mistakes
Describing multi-tasking as "running several programs at the same time" without saying the processor switches between them.
Sending a blocked process straight to running, or giving "time slice ended" as the reason for running to blocked.
Confusing shortest job first (non-pre-emptive) with shortest remaining time (pre-emptive), or round robin with priority.
Defining virtual memory as "using the hard disk as RAM" with no mention of pages being swapped.
Saying an interpreter "converts the program to machine code and then runs it"; that is a compiler.
Putting syntax checking in lexical analysis, or optimisation before code generation in the matching question.
Writing BNF repetition as <letter>* or with an ellipsis; use recursion. Leaving angle brackets off non-terminals.
Reversing the operands of - or / when evaluating RPN, or writing the RPN of $a * b + c$ as a b c + *.
עברית
שאלות מערכת ההפעלה נדרשות מכנויות ספציפיות: תכנון, ניהול זיכרון, ריכוב I/O וספוולינג, ניהול קבצים; עבור הממשק: שמות קבצים לא כתובות, לחיצות לא פקודות, דרייברים, ממשק גרפי.
מצבי תהליך עם מעבריהם והסיבה לכל אחד; שגרות תכנון כפונקציה בתוספת יתרון וחסרון; הגרעין שומר מצב, מזהה הפרעה, טיפל בה, ושחזר.
זיכרון וירטואלי: דיסק מרחיב את RAM, עמודים מתחלפים, מעבר כתובות; פייג'ינג הוא בגודל קבוע ואינו נראה למשתמש, סגמנטציה היא בגודל משתנה ולוגית; תזוזה היא החלפת עמודים במקום ביצוע עבודה.
מפרש: ביצוע statement אחת בכל פעם, מתורגמת ומבוצעת, ולא נשמר דבר. שלבים במרכיב: טוקנים וטבלת סמלים, גרמטיקה ועץ פירוק, קוד, מיטוב.
BNF: כלל אחד לכל דיאגרמה, | לבחירה, רקורסיה לחזרה על, טורמינלים חשופים ופוליתורמינלים בסוגריים זוויתיים. לומר איזה כלל שובר מחרוזת נתונה.
RPN: אופרטורים לאחר ארגומנטים, ביצוע בעזרת ערימה, הצגת כל שלב; המרה על ידי הסגרת סוגריים מלאה; בעת המרה חזרה, שמירת הסוגריים.
טעויות נפוצות
תיאור רב-תפקודי כ"ריצת מספר תוכניות בו-זמנית" מבלי לציין שהמעבד מתחלף ביניהן.
שליחת תהליך חסום ישירות לריצה, או מתן "סוף שיעת זמן" כסיבה למעבר מריצה לחסימה.
בלבול בין Shortest Job First (לא קוטע) ל-Shortest Remaining Time (קוטע), או בין Round Robin לסדרי עדיפות.
הגדרת זיכרון וירטואלי כ"שימוש בדיסק הקשיח כ-RAM" ללא אזכור של עמודים המתחלפים.
טענה כי מפרש "ממיר את התוכנית לקוד מכונה ולאחר מכן מפעיל אותה"; זהו תכנת הרכיב.
הכנסת בדיקת סינטקס לניתוח קלפי, או מיטוב לפני יצירת קוד בשאלת התאמה.
כתיבת חזרה על ב-BNF כ<letter>* או עם נקודות; יש להשתמש ברקורסיה. השמדת סוגריים זוויתיים מפוליתורמינלים.
הפכת ארגומנטים של - או / בעת ביצוע RPN, או כתיבת ה-RPN של $a * b + c$ כa b c + *.
Interactive lessons on this topic · שיעורים אינטראקטיביים בנושא זה
Work through it step by step, with instant-check exercises. · לעבור על הדברים צעד אחר צעד, עם תרגילים לבדיקה מיידית.
Pick one and the site follows you — notes, papers, videos and practice all open on it. · בחרו נושא אחד והאתר יעקוב אחריו — הערות, מסמכים, וידאו ותרגולים פתוחים בו.
Type to search notes, lessons, code, vocabulary and past-paper questions across every subject. · הקלד כדי לחפש הערות, שיעורים, קוד, אוצר מילים ושאלות מבחנים בכל הנושאים.