OS PyramidTechnion 234123 · Operating Systemsbasics → exam
the pyramid
Stage 7 / 10 · Core Mechanics

Deadlocksupporting

Deadlock occurs when two or more processes are indefinitely blocked, each waiting for resources held by another. Understanding its four necessary conditions (Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait) is fundamental. This topic is crucial for designing robust operating systems that can prevent, avoid, detect, or recover from such states, making it a recurring exam subject.

Where to learn it

lectureLecture 7
41 slides
Start with slides 1, 2, 3, 4, 5

How to study it

  • Master the four necessary conditions for deadlock and be able to identify them in scenarios.
  • Practice the Banker's Algorithm extensively for both safety state determination and resource request evaluation.
  • Differentiate clearly between deadlock prevention, avoidance, detection, and recovery strategies, including their trade-offs.

What the exam asks

Typical exam questions will require applying the Banker's Algorithm to determine system safety or evaluate resource requests, or identifying the presence and conditions of deadlock in a given resource allocation graph.

The components, basic → advanced

These are the atomic skills this stage is built from. Learn them in this order — later ones assume the earlier ones.

L4 · advanced
Banker's algorithm safety check
needs first: mutex correctness

Exam subsections in this stage (27 parts across 9 questions)

OS-Winter-2020-2021-examBQ4core7 parts here

deadlocks קיפאון

  1. 1.1· mcq· 2 pts

    האם יתכן deadlock? כן / לא תשבה: נימוק:

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check
  2. 1.2· short_answer· 8 pts

    עבור 4 תנאים ל-deadlock רשמו לכל אחד: מהו השם של התנאי, והאם הוא מתקיים כן או לא (בהתאם לתשובה למעלה), ובנוסף איך הוא מתקיים או לא מתקיים. תנאי 1: שם: האם מתקיים: כן / לא נימוק: תנאי 2: שם: האם מתקיים: כן / לא נימוק: תנאי 3: שם: האם מתקיים: כן / לא נימוק: תנאי 4: שם: האם מתקיים: כן / לא נימוק:

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check
  3. 2.1· mcq· 2 pts

    האם יתכן deadlock? כן / לא תשבה: נימוק:

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check
  4. 2.2· short_answer· 8 pts

    עבור 4 תנאים ל-deadlock רשמו לכל אחד: מהו שם של התנאי, והאם הוא מתקיים כן או לא (בהתאם לתשובה למעלה), ובנוסף איך הוא מתקיים או לא מתקיים. תנאי 1: שם: האם מתקיים: כן / לא נימוק: תנאי 2: שם: האם מתקיים: כן / לא נימוק: תנאי 3: שם: האם מתקיים: כן / לא נימוק: תנאי 4: שם: האם מתקיים: כן / לא נימוק:

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check
  5. 3.1· diagram· 4 pts

    צייר את גרף הקצאת משאבים (resource allocation graph) כמו שנלמד בהרצאות עבור אלגוריתם הבנקאי, עבור תחילת ריצה של מקרה זה. נמק למה.

    Pipe IPC semanticsMutex correctness and deadlock avoidanceBanker's algorithm safety check
  6. 3.2· short_answer· 4 pts

    אם נשתמש באלגוריתם הבנקאי לצורך ניהול משאבים-מנעולים מה תהיה התוצאה מכך ומדוע?

    Mutex correctness and deadlock avoidance
  7. 3.3· calculation· 4 pts

    נניח התוכנה רצה כמו שתואר בסעיף הקודם. להריץ את כל הפונקציונליות הנדרשת בעזרת חוט אחד לוקח T₁ זמן. תניחו הרצה של תוכנה לעיל על N תהליכים (או חוטים) תחת שימוש באלגוריתם הבנקאי לחלוקת משאבים כמו שהסברת בסעיף הקודם. בהינתן הביצועים הגרועים ביותר מה יהיה ה-speedup לפי חוק אמדל (Amdahl law)?

    Pipe IPC semantics
2018B_Spring_AQ2core5 parts here

אלגוריתם הבנקאי

  1. 1· mcq· 5 pts

    (5 נק') מה מטרתו של אלגוריתם הבנקאי? a. לסנכרן בין שני תהליכים או יותר. b. לפתור את בעיית ה-deadlock לאחר שכבר קרתה. c. לזהות את ה-deadlock שיכול להתרחש במקרה שבקשת קבלת המשאבים הנוכחית תענה. d. לענות האם ייתכן deadlock בהינתן גרף הקצאת המשאבים של התהליכים לפני ריצתם. e. מטרה זהה לזו של אלגוריתם קופת חולים. נימוק:

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check
  2. 2· mcq· 5 pts

    (5 נק') מהי ההגדרה של "מצב בטוח" (safe state) באלגוריתם הבנקאי? a. מצב בו תהליכים אינם ב-deadlock b. מצב בו תהליכים אינם ב-deadlock וגם כל בקשת משאבים עתידית לא תגרום ל-deadlock וכל הצרכים למשאבים יסופקו. c. מצב בו רק תהליך אחד משתמש בכל המשאבים שהוא צריך וכל השאר ממתינים. d. מצב בו תהליכים אינם ב-deadlock וקיימת סדרת בקשות משאבים עתידית שלא תגרום ל-deadlock וכל הצרכים למשאבים יסופקו. e. המצב ההתחלתי בלבד של אלגוריתם הבנקאי. נימוק:

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check
  3. 3· mcq· 5 pts

    (5 נק') מהי הסיבוכיות של אלגוריתם הבנקאי עבור בקשת משאבים אחת בהנחה שיש n תהליכים? מדוע זאת הסיבוכיות? a. O(n) כי עוברים על כל התהליכים פעם אחת. b. O(n) כי בכל איטרציה עוברים על כל התהליכים שנשארו בקבוצה ומורידים תהליך אחד מהקבוצה (או שעוצרים) עד שהקבוצה מתרוקנת. c. O(n) כי בשתי לולאות for מקוננות, עוברים על כל התהליכים בשביל כל תהליך. d. O(n!) כי עוברים על כל הסידורים האפשריים של n תהליכים. e. אף תשובה אינה נכונה. נימוק:

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check
  4. 4· mcq· 5 pts

    (5 נק') מבין שיטות הטיפול ב-deadlock (קיפאון), לאיזו קטגוריה משתייך אלגוריתם הבנקאי? a. Deadlock prevention מניעת קיפאון. b. Deadlock avoidance הימנעות מקיפאון. c. Deadlock detection & recovery זיהוי מצב קיפאון וחילוץ מהמצב. d. Deadlock protection שמירת מצב קיפאון. e. אף תשובה לא נכונה. נימוק:

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check
  5. 5· short_answer· 5 pts

    (5 נק') ציינו יתרון אחד וחיסרון אחד של אלגוריתם הבנקאי לעומת טכניקת הקצאת משאבים לפי הסדר (circular wait no.). יתרון של אלגוריתם הבנקאי: חיסרון של אלגוריתם הבנקאי:

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check
2017A_Winter_AQ3core4 parts here

סינכרוניזציה

  1. 2· short_answer· 5 pts

    (5 נק') שלומית שמה לב שהיא זו שתמיד קונה את החלב ולכן ניסחה את האלגוריתם באופן סימטרי: 1. if no milk: 2. atomically get the car keys and the wallet 3. buy milk יהודה טוען שהאלגוריתם עשוי לא להסתיים, האם יהודה צודק? נמקו.

    Voluntary vs preemptive context switchPreemption trigger identificationMutex correctness and deadlock avoidance
  2. 3· short_answer· 5 pts

    (5 נק') יהודה טוען שהאלגוריתם קשה למימוש ולכן שלומית ניסחה אלגוריתם חדש: 1. if no milk: 2. get the car keys 3. get the wallet 4. buy milk יהודה טוען שהאלגוריתם עשוי לא להסתיים, האם יהודה צודק? נמקו.

    Voluntary vs preemptive context switchPreemption trigger identificationMutex correctness and deadlock avoidance
  3. 4· short_answer· 5 pts

    (5 נק') שלומית שמה לב שהאלגוריתם גורם לוויכוחים על המפתחות של הרכב ולכן החליטה לנסח אלגוריתם נוסף: 1. if no milk: 2. if (Yehuda): 3. get the car keys 4. get the wallet 5. buy milk 6. if (Shlomit): 7. get the wallet 8. try to get the car keys 9. //try: non-blocking attempt to take the keys 10. if could not get the car keys: 11. release the wallet 12. buy milk יהודה טוען שהאלגוריתם עשוי לא להסתיים, האם יהודה צודק? נמקו.

    Voluntary vs preemptive context switchPreemption trigger identificationMutex correctness and deadlock avoidance
  4. 5· short_answer· 5 pts

    (5 נק') שלומית שמה לב שהאלגוריתם לא מספיק חברתי ולכן החליטה לנסח אלגוריתם נוסף: 1. if (Yehuda): 2. while (no milk): 3. get the wallet 4. try to get the car keys 5. if could not get car keys: 6. release the wallet 7. else 8. buy milk 9. if (Shlomit): 10. while (no milk): 11. get the car keys 12. try to get the wallet 13. if could not get the wallet: 14. release the car keys 15. else 16. buy milk שלומית טוענת שלפחות אחד מהתנאים לקיום deadlock לא מתקיים כאן. יהודה טוען שהאלגוריתם עשוי לא להסתיים, מי צודק? נמקו.

    Mutex correctness and deadlock avoidanceBanker's algorithm safety check