OS PyramidTechnion 234123 · Operating Systemsbasics → exam
Stage 10: Storage & Filesystems
examB-spring2020Question 1corecritical20 pts

אבי פיתח מערכת קבצים חדשה עבור לינוקס בשם AFS והתקין אותה על דיסק בגודל 1MB. AFS נפרסת בדיסק באופן הבא: Block #0: superblock Block #1: inode bitmap Block #2: data bitmap Blocks #3 - #10: inode table Blocks #11 - #1023: data blocks נתונים נוספים לגבי AFS: * גודל בלוק הוא 1K בתים. * גודל inode הוא 128 בתים. אבי קנה דיסק גדול יותר, בנפח 16MB (סה"כ 16384 בלוקים), והתקין עליו את AFS עם יותר בלוקים עבור הנתונים: Block #0: superblock Block #1: inode bitmap Block #2: data bitmap Blocks #3 - 10: inode table Blocks #11 - 16383: data blocks אבי חזר להשתמש בדיסק הקטן (בגודל 1MB) וניסה לחשוב כיצד ניתן לחסוך שטח אחסון. נעמי שמה לב כי עבור קבצים קטנים, המכילים 60 בתים לכל היותר, ניתן לשמור את תוכן הקובץ בתוך ה-inode מבלי להקצות עבורם בלוקים נוספים. להלן מבנה ה-inode במערכת הקבצים AFS: struct afs_inode { unsigned int mode; /* File mode */ unsigned int size; /* Size in bytes */ unsigned int links_count; /* Links count, max 32000 */ unsigned int block_count; /* Number of allocated data blocks */ unsigned int block[15]; /* Pointers to blocks */ /* other irrelevant fields */ }; רמז: זיכרו כי sizeof(unsigned int) = 4B. השיטה של נעמי נועדה כדי לחסוך שטח דיסק, אבל היא חוסכת גם בזמן הריצה של פעולות מסוימות.

Full original question text (raw OCR)

שאלה 1 - מערכות קבצים (20 נק') אבי פיתח מערכת קבצים חדשה עבור לינוקס בשם AFS והתקין אותה על דיסק בגודל 1MB. AFS נפרסת בדיסק באופן הבא: Block #0: superblock Block #1: inode bitmap Block #2: data bitmap Blocks #3 - #10: inode table Blocks #11 - #1023: data blocks נתונים נוספים לגבי AFS: * גודל בלוק הוא 1K בתים. * גודל inode הוא 128 בתים. 1. (4 נק') מה מספר הקבצים המקסימלי במערכת הקבצים AFS? אבי קנה דיסק גדול יותר, בנפח 16MB (סה"כ 16384 בלוקים), והתקין עליו את AFS עם יותר בלוקים עבור הנתונים: Block #0: superblock Block #1: inode bitmap Block #2: data bitmap Blocks #3 - 10: inode table Blocks #11 - 16383: data blocks 2. (4 נק') למרבה הצער, מערכת הקבצים המעודכנת אינה מתאימה לדיסק בנפח 16MB. מדוע? 3. (4 נק') הציעו לאבי שינוי במבנה מערכת הקבצים כך שתתאים לדיסק בנפח 16MB. אבי חזר להשתמש בדיסק הקטן (בגודל 1MB) וניסה לחשוב כיצד ניתן לחסוך שטח אחסון. נעמי שמה לב כי עבור קבצים קטנים, המכילים 60 בתים לכל היותר, ניתן לשמור את תוכן הקובץ בתוך ה-inode מבלי להקצות עבורם בלוקים נוספים. להלן מבנה ה-inode במערכת הקבצים AFS: struct afs_inode { unsigned int mode; unsigned int size; /* File mode */ /* Size in bytes */ unsigned int links_count; /* Links count, max 32000 */ unsigned int block_count; /* Number of allocated data blocks */ unsigned int block[15]; /* Pointers to blocks */ /* other irrelevant fields */ }; רמז: זיכרו כי sizeof(unsigned int) = 4B. 4. (4 נק') הסבירו בפירוט כיצד ניתן לממש את השיטה של נעמי. היכן בדיוק בתוך ה-inode יישמר התוכן של קובץ קטן? נימוק: השיטה של נעמי נועדה כדי לחסוך שטח דיסק, אבל היא חוסכת גם בזמן הריצה של פעולות מסוימות. 5. (4 נק') הביאו דוגמה לפעולה על קובץ אשר תהיה מהירה יותר בשיטה של נעמי. הסבירו במפורט מדוע השיטה של נעמי מהירה יותר לעומת מערכת הקבצים המקורית AFS.

  1. 1· calculation· 4 ptsStorage & Filesystems

    (4 נק') מה מספר הקבצים המקסימלי במערכת הקבצים AFS?

    libc syscall wrapper caching pitfalls
  2. 2· short_answer· 4 ptsStorage & Filesystems

    (4 נק') למרבה הצער, מערכת הקבצים המעודכנת אינה מתאימה לדיסק בנפח 16MB. מדוע?

    libc syscall wrapper caching pitfalls
  3. 3· short_answer· 4 ptsStorage & Filesystems

    (4 נק') הציעו לאבי שינוי במבנה מערכת הקבצים כך שתתאים לדיסק בנפח 16MB.

    libc syscall wrapper caching pitfalls
  4. 4· short_answer· 4 ptsStorage & Filesystems

    (4 נק') הסבירו בפירוט כיצד ניתן לממש את השיטה של נעמי. היכן בדיוק בתוך ה-inode יישמר התוכן של קובץ קטן? נימוק:

    Hard link vs symlink inode behavior
  5. 5· short_answer· 4 ptsStorage & Filesystems

    (4 נק') הביאו דוגמה לפעולה על קובץ אשר תהיה מהירה יותר בשיטה של נעמי. הסבירו במפורט מדוע השיטה של נעמי מהירה יותר לעומת מערכת הקבצים המקורית AFS.

    libc syscall wrapper caching pitfalls

The exam question — original PDF

Exactly as it appears on the exam paper.

loading PDF…
loading PDF…

Built from these components

Ordered basic → advanced. Master the earlier ones first.

L2System call trap and kernel entryL3libc syscall wrapper caching pitfallsL3Per-process file descriptor tableL3Hard link vs symlink inode behaviorL4SRT / preemptive Gantt construction

Review the material

Read these before you answer — each verified slide teaches a component this question tests, and nothing from an unrelated topic is included. Tutorial slides show the actual slide image.

Lecture 4–5slide 39SRTF (Shortest-Remaining-Time First)

SRTF (Shortest-Remaining-Time First) • Assume different jobs may arrive at different times • SJF is not optimal – As it’s not preemptive, and – A short job might arrive while a very long job is running => recall: convoy effect • SRTF is just like SJF but – Is allowed to use preemption – Hence, it’s “optimal” (assuming a zero context-switch cost etc.) • Whenever a new job arrives, or an old job terminates – SRTF schedules the job with the shortest remaining time – Thereby making an optimal decision 39 OS (234123) - scheduling

Lecture slide — text above is the material (no raster available).
Lecture 11–12slide 9POSIX file descriptors (FDs)

POSIX file descriptors (FDs) • A successful open<“file name”> of a file returns a FD rpt – A nonnegative integer – An index to a per-process array called the “file descriptor table” – Each entry in the array saves, e.g., the current offset – Threads share the array (and hence the offset) – C’s FILE structure encapsulates a FD • FD or filename? – Some file-related POSIX system calls operate on FDs • read, write, fchmod, fchown, fchdir, fstat, ftruncate… – Others operate on file names • chmod, chown, chdir, stat, truncate – Has security implications: FD versions are more secure in some sense • Because association of FD to underlying file is immutable – Once an FD exists, it will always point to the same file • Whereas association between file & its name is mutable – So they can lead to TOCTTOU (time of check to time of use) races OS (234123) - files 9

Lecture slide — text above is the material (no raster available).
Lecture 11–12slide 26Hard links – when is a file deleted?

Hard links – when is a file deleted? • Every file has a “reference count” associated with it – link()  ref_count++ – unlink()  ref_count-- • if( ref_count == 0 ) – The file has no more names – It isn’t pointed to from any node within the file hierarchy – So it can finally be deleted • What if an open file is deleted? (its ref_count==0) – Can we still access the file through the open FD(s)? • Yes – If >=1 processes have the file open when the last link is removed • The link shall be removed before unlink() returns • But the removal of the file contents shall be postponed until all references (file descriptors) to the file are close()-ed • Have you seen files names that begin with “.nfs”? OS (234123) - files 26

Lecture slide — text above is the material (no raster available).
Lecture 11–12slide 34inodes & *stat syscalls

inodes & *stat syscalls • lstat(2) – Exactly the same as stat(2) if applied to a hard link – But if applied to a symlink, would return the information of this symlink (not to the target of the symlink) – In this case, POSIX says that the only fields within the stat structure that you can portably use are: • st_mode which will specify that the file is a symlink • st_size symlink content length (= length of target filepath) – The value of the rest of the fields could be valid, but it is not specified by POSIX – Notably, it is not specified if a symlink has a corresponding inode • Will be discussed shortly OS (234123) - files 34

Lecture slide — text above is the material (no raster available).
Tutorial 2slide 16קריאת המערכת waitpid()pid_t waitpid(pid_t pid, int *wstatus, int options);פעולה: המתנה לסיום בן ספציפי שמספרו pid

קריאת המערכת waitpid()pid_t waitpid(pid_t pid, int *wstatus, int options);פעולה: המתנה לסיום בן ספציפי שמספרו pid.wait(), waitpid() הן קריאות מערכת חוסמות.כלומר חוסמות את התקדמות התהליך עד להתרחשות תנאי מסוים.באנגלית: blocking system calls.הארגומנט options מאפשר לשנות את ההתנהגות של waitpid() לקריאת מערכת לא חוסמת.אם options==WNOHANG קריאת המערכת תחזור מיד, כאשר ערך חזרה 0 משמעותו שאף תהליך בן עוד לא סיים, ואילו ערך חזרה חיובי הוא ה-pid של תהליך בן שסיים ונמצא עדיין במצב zombie.מערכות הפעלה - תרגול 216

Tutorial 2slide 18קריאת המערכת exit()שאלה: למה בכלל לקרוא ל-exit(status) , אם אפשר פשוט לרשום return status בסוף פונקציית ה-main?תשובה:...

קריאת המערכת exit()שאלה: למה בכלל לקרוא ל-exit(status) , אם אפשר פשוט לרשום return status בסוף פונקציית ה-main?תשובה: main היא לא באמת הפונקציה הראשית של התכנית...main() נקראת ע"י __libc_start_main() שאוספת את ערך החזרה של main() וקוראת ל-exit().int __libc_start_main(…) { …… exit(main(…));}מסקנה: הפונקציה exit תמיד נקראת לסיום סטנדרטי של התוכנית.מערכות הפעלה - תרגול 218

Tutorial 2slide 22קריאות המערכת getpid(), getppid()pid_t getpid();קריאת מערכת המחזירה לתהליך הקורא את ה-pid של עצמו

קריאות המערכת getpid(), getppid()pid_t getpid();קריאת מערכת המחזירה לתהליך הקורא את ה-pid של עצמו.pid_t getppid();קריאת מערכת המחזירה את ה-PID של תהליך האב של התהליך הקורא.שאלה: מה המשמעות של getppid() == 1 עבור תהליך משתמש טיפוסי?תשובה: תהליך האב הוא init. קורה למשל אם תהליך הבן יתום.מערכות הפעלה - תרגול 222

Tutorial 2slide 24דוגמת קודמסכמתprintf("pid = %d\n", getpid());pid_t pid = fork();if (pid == 0) { printf("child pid = %d\n", getpid());...

דוגמת קודמסכמתprintf("pid = %d\n", getpid());pid_t pid = fork();if (pid == 0) { printf("child pid = %d\n", getpid()); char* args[] = {"/bin/date", NULL}; execv(args[0], args); printf("This should not be printed\n");} else { wait(NULL); printf("parent pid = %d\n", getpid());}פלט לדוגמה:pid = 8919child pid = 8920Sun Oct 29 00:31:32 IDT 2017parent pid = 8919מערכות הפעלה - תרגול 224

Tutorial 2slide 25אתחול תהליכים בלינוקסמשתמשים מתחברים לעבודה בלינוקס דרך מסופים (terminal)

אתחול תהליכים בלינוקסמשתמשים מתחברים לעבודה בלינוקס דרך מסופים (terminal).מסוף = מסך + מקלדת (מקומי או מרוחק).התהליך init יוצר תהליך בן עבור כל מסוף, אשר טוען ומבצע את המשימות הבאות לפי הסדר:איתחול של המסוף.התחברות של המשתמש עם שם משתמש וסיסמא באמצעות תכנית login.אם אושרה כניסת המשתמש: קריאה לתוכנית shell(כמו tcsh או bash) המאפשרת למשתמש להעביר פקודות למערכת ההפעלה.מערכות הפעלה - תרגול 225

Tutorial 2slide 26דוגמה לשימוש בתהליכים - shellממשק שורת פקודה (command line)

דוגמה לשימוש בתהליכים - shellממשק שורת פקודה (command line).ייעוד עיקרי: לקבל פקודות ולבצע אותן באופן סדרתי.ה-shell מייצר תהליך בן עבור כל פקודה על-מנת לבצע אותה.כל פקודה ניתן להריץ בחזית (foreground) או ברקע (background).הרצה בחזית: האב (shell) ממתין לסיום הבן לפני קריאת הפקודה הבאה.הרצה ברקע: האב (shell) עובר מיד לקריאת הפקודה הבאה.ייעוד נוסף: להציג קבצים ותיקיות על-מנת לסייר במערכת.דוגמה חיה:https://www.tutorialspoint.com/unix_terminal_online.phpמערכות הפעלה - תרגול 226

Tutorial 5slide 9דוגמת FCFSaverageResponseTime = (10 + 20 + 30) / 3 = 20כעת נסיר את הנחה 1 ("כל התהליכים רצים למשך אותו זמן")

דוגמת FCFSaverageResponseTime = (10 + 20 + 30) / 3 = 20כעת נסיר את הנחה 1 ("כל התהליכים רצים למשך אותו זמן"). לכל תהליך זמן ריצה משלו.תוכלו לחשוב על דוגמה שבה FCFS אינו יעיל?מערכות הפעלה - תרגול 59כל התהליכים רצים למשך אותו זמן.כל התהליכים מגיעים באותו זמן (t=0).אם תהליך התחיל לרוץ, אז הוא ירוץ עד לסיומו ללא הפסקות.התהליכים משתמשים רק במעבד ולא מבצעים I/O.זמן הריצה של כל התהליכים ידוע מראש.

Tutorial 5slide 10אפקט השיירה (convoy effect)averageResponseTime = (100 + 110 + 120) / 3 = 110אלגוריתם FCFS עלול לסבול מ"אפקט השיירה": ...

אפקט השיירה (convoy effect)averageResponseTime = (100 + 110 + 120) / 3 = 110אלגוריתם FCFS עלול לסבול מ"אפקט השיירה": מצב שבו תהליך אחד ארוך מעכב הרבה תהליכים קצרים. מערכות הפעלה - תרגול 510

Tutorial 13slide 13בלינוקס יש שני סוגי קישורים (links)soft / symbolic linkln -s src dstקישור סימבולי הוא קובץ חדש עם inode נפרד מזה של ה...

בלינוקס יש שני סוגי קישורים (links)soft / symbolic linkln -s src dstקישור סימבולי הוא קובץ חדש עם inode נפרד מזה של הקובץ המקורי.כתיבה דרך הקישור כותבת לקובץ אליו הוא מצביע.מחיקת הקישור (באמצעות הפקודה rm) לא תמחק את הקובץ המוצבע.אפשר ליצור קישורים סימבוליים גם לקובץ שלא קיים.hard linkln src dstקישור קשיח הוא שם נרדף לקובץ המקורי כי הוא מצביע ישירות ל-inode של הקובץ המקורי.כתיבה דרך הקישור כותבת לקובץ אליו הוא מצביע.מחיקת הקישור תקטין את מונה הקישורים של הקובץ (כפי שנשמר ב-inode).הקובץ יימחק מהדיסק רק כאשר כל ה-hard links אליו יימחקו.מערכות הפעלה - תרגול 1213

Tutorial 13slide 19>> rm /A/helloמערכות הפעלה - תרגול 1219inode #2type=dirdatanameinode #A5B7inode #5type=dirdatanameinode #…………inode #1...

>> rm /A/helloמערכות הפעלה - תרגול 1219inode #2type=dirdatanameinode #A5B7inode #5type=dirdatanameinode #…………inode #13type=soft_linkdatainode #7type=dirdatanameinode #soft13……data block/A/helloקישור "שבור"!dangling link

Ask Gemini
examB-spring2020 · Q1 — question + its material already loaded
Pick a shortcut above or ask anything about this question.
The exam text, the skills it tests, and the exact slides are already in context.