OS PyramidTechnion 234123 · Operating Systemsbasics → exam
the pyramid
Stage 2 / 10 · Foundations

Processes & Signalshigh-yield

This topic covers the fundamental concepts of processes, including their creation (`fork`, `exec`), termination, and states, as well as inter-process communication basics. It also delves into signals, explaining their delivery mechanism, handling (`sigaction`), and blocking (`sigprocmask`). Understanding these concepts is crucial for comprehending how programs execute and interact within an operating system, making them a recurring and important part of OS exams.

Where to learn it

lectureLecture 2
35 slides
Start with slides 1, 2, 3, 4, 5
tutorialTutorial 2 · processes
46 slides

How to study it

  • Master the semantics of `fork()` and `exec()`: understand memory space duplication, file descriptor inheritance, and how program execution changes. Pay special attention to `fork_exec_semantics`.
  • Thoroughly understand signal delivery, signal masks, and the difference between reliable and unreliable signals. Practice writing and analyzing code that uses `sigaction` and `sigprocmask`.
  • Trace the execution flow of C code snippets involving multiple processes and signals. Pay attention to `syscall_mechanism` and how system calls like `fork` and `exec` interact with the kernel.

What the exam asks

Exam questions typically involve analyzing C code snippets that use `fork`, `exec`, `wait`, `kill`, and signal handling functions, asking to predict output, identify errors, or explain behavior under-the-hood behavior.

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.

L1 · foundational
Process state transitions
L2 · building
PCB / process control block fields
needs first: process states
L2 · building
System call trap and kernel entry
needs first: process states
L3 · applied
fork/exec address-space semantics
needs first: process states
L3 · applied
libc syscall wrapper caching pitfalls
needs first: syscall mechanism, fork exec semantics
L3 · applied
Signal delivery and handler timing
needs first: fork exec semantics, syscall mechanism

Exam subsections in this stage (20 parts across 10 questions)

2018A_Winter_AQ1core4 parts here

חלק 1 - קריאות מערכת

  1. 1· mcq· 5 pts

    (5 נק') היכן הגרעין שומר את ה-PID של התהליך? a. בספריה .libc b. במחסנית המשתמש. c. במחסנית הגרעין. d. בערימה. e. במתאר התהליך (ה-PCB). f. בתור הריצה (runqueue)

    fork/exec address-space semanticslibc syscall wrapper caching pitfalls
  2. 3· mcq· 5 pts

    (5 נק') מהי התקלה שנוצרה בעקבות השינוי? a. אם שני תהליכים קוראים ל-()getpid בו-זמנית עלול להיווצר race condition. b. fork().b עלולה לחזור עם אותו ערך בתהליך האב ובתהליך הבן. c. fork().C עלולה להיכשל במקרים בהם המימוש המקורי היה מצליח. d. getpid().d עלולה להחזיר pid של תהליך אחר. e. getpid().e עלולה להחזיר "1-". f. execv() .f עלולה להיכשל במקרים בהם המימוש המקורי היה מצליח.

    System call trap and kernel entryfork/exec address-space semanticslibc syscall wrapper caching pitfalls
  3. 4· mcq· 5 pts

    (5 נק') השלימו את התיקון הנדרש בשורה 10: a. if (res == 0) cached_pid = -1; b. if (res == 0) cached_pid = getpid(); c. if (res == 0) return cached_pid; d. if (res > 0) cached_pid = -1; e. if (res > 0) cached_pid = getpid(); f. if (res > 0) return cached_pid;

    System call trap and kernel entryfork/exec address-space semanticslibc syscall wrapper caching pitfalls
  4. 5· mcq· 5 pts

    (5 נק') מהי התקלה בקוד לעיל ומתי היא תתרחש? a. הסיגנל לא יטופל אם האב שלח את הסיגנל לפני שהבן התחיל לרוץ. b. הסיגנל לא יטופל אם האב שלח את הסיגנל אחרי שהבן סיים את שורה 8. c. הסיגנל לא יטופל ללא תלות בסדר הזימון של התהליכים. d. שורה 2 תדפיס ערך שגוי אם האב שלח את הסיגנל לפני שהבן התחיל לרוץ. e. שורה 2 תדפיס ערך שגוי אם האב שלח את הסיגנל אחרי שהבן סיים את שורה 8. f. שורה 2 תדפיס ערך שגוי ללא תלות בסדר הזימון של התהליכים.

    Signal delivery and handler timing
OS-Spring2021-examAQ1core4 parts here

שאלה 1

  1. א.· mcq· 5 pts

    בעבור תהליך כלשהו, איזה מבין ההיגדים הבאים מתאר שינוי מצבים (state change) שהוא בלתי אפשרי 1. [היגד:] שינוי ממצב waiting אל מצב running 2. [היגד:] שינוי ממצב waiting אל מצב ready 3. [היגד:] שינוי ממצב ready אל מצב running 4. [היגד:] שינוי ממצב running אל מצב ready 5. [היגד:] שינוי ממצב running אל מצב zombie 6. יש יותר מהיגד אחד שמתאר שינוי מצבים בלתי אפשרי

    SRT / preemptive Gantt construction
  2. ג.· mcq· 5 pts

    איזה מבין ההיגדים הבאים נכון 1. [היגד:] כשמגדירים signal handler בעבור הסיגנל SIGCONT, ה-handler נקרא מיד אחרי שממשיכים את התהליך 2. [היגד:] כשמגדירים signal handler בעבור הסיגנל SIGKILL, ה-handler נקרא מיד אחרי שהורגים את התהליך 3. [היגד:] כשמגדירים signal handler בעבור הסיגנל SIGSTOP, ה-handler נקרא מיד אחרי שעוצרים את התהליך 4. [היגד:] משתמש יכול לחסום את כל סוגי הסיגנלים רק אם הוא super-user או root 5. יש יותר מהיגד אחד נכון 6. כל ההיגדים אינם נכונים

    libc syscall wrapper caching pitfallsSignal delivery and handler timing
  3. ד.· mcq· 5 pts

    איזה מבין ההיגדים הבאים נכון 1. כל ההיגדים שגויים 2. כל ההיגדים נכונים 3. [היגד:] תהליך עלול לקבל את הסיגנל SIGXCPU רק אם השתמשנו קודם לכן בקריאת המערכת setrlimit בכדי להגביל את צריכת המעבד של תהליך זה 4. [היגד:] אפשר לשלוח את הסיגנל SIGCONT לתהליך רק אם קודם לכן שלחנו אליו את הסיגנל SIGSTOP 5. [היגד:] תהליך עלול לקבל את הסיגנל SIGPIPE רק אם קודם לכן הוא השתמש בקריאת המערכת pipe אבל אז השתמש ב pipe שנוצר לא נכון (כתב ל pipe שנסגר לקריאה) 6. [היגד:] תהליך עשוי לקבל את הסיגנל SIGTRAP רק אם הוא רץ תחת דיבאגר

    libc syscall wrapper caching pitfallsSignal delivery and handler timingPipe IPC semantics
  4. ה.· mcq· 5 pts

    איזה מבין ההיגדים הבאים איננו נכון? (תזכורת: IPI הינו קיצור ל Inter-Processor Interrupt. הנחה: מדובר בארכיטקטורת x86.) 1. [היגד:] כשמתחוללת פסיקת חומרה כלשהי, הגרעין מטפל בה ואז שולח את הסיגנל המתאים לתהליך המתאים 2. [היגד:] ה scheduler עשוי לשלוח IPI מליבה אחת של המעבד לאחרת 3. [היגד:] תת-המערכת בגרעין שמממשת את הזיכרון הוירטואלי עשויה לשלוח IPI בין ליבה אחת של המעבד לאחרת 4. [היגד:] רק הגרעין מטפל בפסיקות חומרה, ורק תהליכים מטפלים בסיגנלים 5. יש יותר מהיגד אחד שאיננו נכון 6. כל ההיגדים נכונים

    libc syscall wrapper caching pitfallsLocal vs global interrupt disableSignal delivery and handler timingPreemption trigger identificationSRT / preemptive Gantt construction