IIEST, Shibpur

Indian Institute of Engineering Science and Technology, Shibpur

(Formerly Bengal Engineering and Science University, Shibpur)

Empowering the nation since 1856

आई आई ई एस टि, शिवपुर

भारतीय अभियांत्रिकी विज्ञान एवं प्रौद्योगिकी संस्थान, शिवपुर

(पूर्व में बंगाल इंजीनियरिंग एंड साइंस यूनिवर्सिटी)

१८५६ से देश को सशक्त बनाना

Operating System Laboratory

Assignments

      1. Write a program that creates another process and together (two processes together) print the first n (n given by the user) Fibonacci numbers. The first (parent) process prints first C (given by the user) fibonacci numbers and the second (child) process prints the rest. Extend this program so that it creates P (given by the user) processes and these P processes together print the first n (given by the user) Fibonacci numbers.
      2. A process P goes on collecting "tasks" from the user (either through key-board or file) and add them to a queue Q. For example, a task could be just computation of factorial of a positive integer and P could just read sequence of such numbers. There are  n other processes (p1, p2, ..., pn). which will actually execute the "tasks" collected by P. There is one array T of n structures (one structure for each pi, representing the task pi handles) and P assigns tasks to these n processes through this T. T[i], therefore, is to hold all the information of a task (what the task is, its status, result, etc.) that pi handles. You have to decide the exact structure for T[i], that is, the elements of T. Since T is accessed by P as well as all pis, it is conceived as a shared data structure. Whenever there is no pending task for pi, P dequeues a task from Q and assigns that to pi. If there is no pending task in Q, P "tells" pi to terminate. Each pi, i = 1 to n, checks whether there is any pending task in T[i] or not. If yes, pi executes that and puts back the result in T[i]. pi terminates when it finds that P has "instructed" it (indeed through T[i]) to terminate. When P finds that T[i] contains the result of the task, that is, pi had executed the task and has put the result in T[i], P prints the result and marks that pi is free (no pending task, can accept new task). Whenevr Q is not full, P collects one task from the user and adds that to Q. P terminates when all pis have terminated. The above is illustrated in the following schematic diagram. Please consult the online manual pages for fork(2), shmget(2), shmat(2), shmctl(2) and related ones.

        OS Asgnmnt II July 22 2013

      3. Modify the program developed under the previous assignment in the following way. Let there be two queues PendingQ and DoneQ maintaining the pending tasks and completed tasks respectively. Let PI be the process that collects tasks from the user and puts them in PendingQ (it should not try that when PendingQ is full). The process PO dequeues a completed task from DoneQ (obviously if it is not empty) and prints the result of the task. There are  n other processes (p1, p2, ..., pn) which actually execute the "tasks". Each Pi (i = 1 to n) dequeues a task from PendingQ (when not empty), computes the result and enqueues the task (with computed result) in DoneQ (when not full). PI will decide (depending on user intevention) when to terminate all Pi (i = 1 to n), POand itself.
        alt

        Please note that PendingQ is shared by PI and all Pi (i = 1 to n). Similarly DoneQ too is shared by PO and all Pi (i = 1 to n). Natuarally (how?) there are scopes for race conditions and inconsistent result. Try to demonstrate this. Identify the "critical sections" in your program. Use semaphore to prevent race condition by ensuring mutual exclusion over the execution of the critical sections.After termination your program must release all the ipc tools used by it. Please consult the online manual pages for fork(2), semget(2), semctl(2) and related ones.

      4. Create your own filesystem on a file (provided by the operating system) following unix-like filesystem organization (indexed). The following schematic diagram illustrates what you are supposed to do.
        alt
        Your implementation should support a typical session as given below. Assume that your filesystem is flat and does not support subdirectorie
        1. $myfs /* execute your program */
        2. myfs> /* prompt given by your program */
        3. myfs>mkfs osfile1 512 10MB /* creates your filesystem on file osfile1, blocksize is taken to be 512B */
        4. myfs>mkfs osfile2 1024 20MB /* creates your filesystem on file osfile2, blocksize is taken to be 1024B */
        5. myfs>use osfile1 as C: /* the filesystem on osfile1 will henceforth be accessed as C: */
        6. myfs>use osfile2 as D: /* the filesystem on osfile2 will henceforth be accessed as D: */
        7. myfs>cp osfile3 C:tesfile1 /* copy the file osfile3 from os to the filesystem C: as testfile1 */
        8. myfs>ls C: /* see the contents of the filesystem C: */
          testfile1 ... size
        9. myfs>cp C:tesfile1 C:testfile1a /* copy the file testfile1 from C: to the filesystem C: as testfile1a */
        10. myfs>ls C: /* see the contents of the filesystem C: */
          testfile1 ... size
          testfile1a ... size
        11. myfs>cp C:tesfile1 D:testfile2 /* copy the file testfile1 from C: to the filesystem D: as testfile2 */
        12. myfs>cp D:testfile2 osfile4 /* copy the file testfile2 from C: to the to the OS as osfile4 */
        13. myfs>rm C:testfile1 /* Delete the testfile1 from C: */
        14. myfs>ls C: /* see the contents of the filesystem C: */
          testfile1a ... size
        15. myfs>mv D:testfile2 D:testfile2a  /* Rename  testfile2 of D: to testfile2a in D: */
        16. myfs>exit /* exit from your program */
        17. $
        18. $diff osfile3 osfile4 /* see the difference between osfile3 and osfile4 */