Processes can be synchronized using semaphores or flags Protocol constructions

Processes can be synchronized using semaphores or

This preview shows page 50 - 52 out of 102 pages.

Processes can be synchronized using semaphores or flags. Protocol constructions such as critical sections and monitors guarantee that shared data are not modified by more than one process at a time. If a process has to wait for a condition which can never arise until it has finished waiting, then a deadlock is said to arise. The cause of deadlock waiting is often a resource which cannot be shared. Most operating systems do not try to prevent deadlocks, but leave the problem to user programs.
Image of page 50
Exercises 1. Explain the difference between a light weight process and a normal process. 2. What is meant by the critical section of a program? 3. What is meant by deadlock? 4. Explain why round-robin scheduling would not be appropriate for managing a print-queue. 5. Devise a combination of first-come-first-serve (FCFS) and shortest-job-first (SJF) scheduling which would be the `fairest' solution to scheduling a print queue. Project You can learn a lot by solving the following problem. The idea is to make a time-sharing system of your own. 1. Make a fake kernel simulator which, instead of executing processes in memory, reads instructions from a number of files. You should aim to share the time spent reading each `process' equally between all tasks. The output of your kernel should show clearly what is being executed and when. You should give each process a process identifier (pid). The `command language' you are reading in contains instructions like `abcd 3', `wait 4' etc. i.e. four letters followed by a number. 2. Add process priorities to each task. You can decide how these are assigned yourself. Keep a record of how long each process takes to complete and print status information when each process finishes. You can either call the real system clock to do this, or increment a counter each time an instruction is read. This is like counting `fake CPU cycles'. 3. The input files contain ` wait <number> ' instructions. Modify your program so that when one of the tasks reads an instruction `wait 5', for instance, it waits for process number 5 to finish before it continues. The output of the kernel should show this clearly. Hint: use a status variable which indicates whether the process is `ready' or `waiting'. 4. Copy and modify the input files so that a deadlock can occur. Explain carefully how it occurs. For example, make two processes wait for each other. Add to your kernel a simple test to detect such deadlock situations. Decide for yourself how you wish to handle this situation. Explain what you have chosen to do in your solution. 5. Some of the input files contain `fork' instructions. Modify your code so that when such an instruction is detected, the current process spawns a new copy of itself which begins executing from the instruction after the fork command. The new process should have a different pid and should have the same priority as the old one.
Image of page 51
Image of page 52

You've reached the end of your free preview.

Want to read all 102 pages?

  • One '20

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors