Docsity

Operating Systems: Processes, Threads, and Scheduling Algorithms, Exercises of Operating Systems

Toggle sidebar
bg1
Part 1
1. What are the possible state transitions of a process?
A process has three states:
1- Running (actually using the CPU at that instant)
2- Ready (runnable; temporarily stopped to let another process run)
3- Blocked (unable to run until some external event happens)
Four transitions are possible among three states
1- Process blocks for input
2- Scheduler picks another process
3- Scheduler picks this process
4- Input becomes available
2. What are the differences between a thread and a process?
Threads exist within a process, every process must have one. Threads share
resources and memory space while processes run in separate memory spaces.
3. User-level threads vs. Kernel-level threads? Describe the pros and cons of each type.
• User level Threads
- Advantages:
+ User level threads are simpler and faster to generate. They are also easier to
manage.
+ Thread switching in user-level threads doesn’t need kernel mode privileges.
+ These are more portable
+ These threads may be run on any OS
- Disadvantages:
+ The complete process is blocked if a user-level thread runs a blocking
operation
+ User-level threads don’t support system-wide scheduling priorities
+ It is not appropriate for a multiprocessor system
• Kernel Level Threads
- Advantages:
+ If a thread in the kernel is blocked, it does not block all other threads in the
same process
+ Several threads of the same process might be scheduled on different CPUs in
kernel-level threading
+ Kernel routines can be multithreaded as well
- Disadvantages:
+ Compared to user-level threads, kernel-level threads take longer to create and
maintain
+ A mode switch to kernel mode is important to transfer control from one thread
in a process to another
4.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Operating Systems: Processes, Threads, and Scheduling Algorithms and more Exercises Operating Systems in PDF only on Docsity!

Part 1

  1. What are the possible state transitions of a process? A process has three states: 1 - Running (actually using the CPU at that instant) 2 - Ready (runnable; temporarily stopped to let another process run) 3 - Blocked (unable to run until some external event happens) Four transitions are possible among three states 1 - Process blocks for input 2 - Scheduler picks another process 3 - Scheduler picks this process 4 - Input becomes available
  2. What are the differences between a thread and a process? Threads exist within a process, every process must have one. Threads share resources and memory space while processes run in separate memory spaces.
  3. User-level threads vs. Kernel-level threads? Describe the pros and cons of each type.
    • User level Threads
      • Advantages:
        • User level threads are simpler and faster to generate. They are also easier to manage.
        • Thread switching in user-level threads doesn’t need kernel mode privileges.
        • These are more portable
        • These threads may be run on any OS
      • Disadvantages:
        • The complete process is blocked if a user-level thread runs a blocking operation
        • User-level threads don’t support system-wide scheduling priorities
        • It is not appropriate for a multiprocessor system
    • Kernel Level Threads
      • Advantages:
        • If a thread in the kernel is blocked, it does not block all other threads in the same process
        • Several threads of the same process might be scheduled on different CPUs in kernel-level threading
        • Kernel routines can be multithreaded as well
      • Disadvantages:
        • Compared to user-level threads, kernel-level threads take longer to create and maintain
        • A mode switch to kernel mode is important to transfer control from one thread in a process to another
  • Preemption
    • Preemptive scheduling is prioritized. Highest priority process should always be the process that is currently utilized. Preemptive algorithms are driven by the notion of prioritized computation. The process with the highest priority should always be the one currently using the processor. If a process is currently using the processor and a new process with a higher priority enters, the ready list, the process on the processor should be removed and returned to the ready list until it is once again the highest priority process in the system.
  • Non-preemption
  • When a process enters the state of running, the state of that process is not deleted from the scheduler until it finishes its service time. Non-preemptive algorithms are designed so that once a process enters the running state (is allowed a process), it is not removed from the processor until it has completed its service time (or it explicitly yields the processor). context_switch() is called only when the process terminates or blocks. In non-preemptive scheduling, a running task is executed until completion. It cannot be interrupted.
  • FIFO
  • As a page replacement algorithm, the same idea is applicable. The operating system maintains a list of all pages currently in memory, with the most recent arrival at the tail and the least recent arrival at the head. On a page fault, the page at the head is removed and the new page added to the tail of the list.
  • SJF The algorithm of Shortest Job First is as follows:
  • First of all, all the processes are sorted according to the arrival time.
  • After that, the process having minimum arrival and burst time is selected.
  • Then that process gets executed and all the process that arrives waits in a queue while the first process is in the execution state, and after completion again the process with minimum arrival and burst time is selected for the next execution.
  • Round-robin
  • Each process is assigned a time interval, called its quantum, during which it is allowed to run. If the process is still running at the end of the quantum, the CPU is preempted and given to another process. If the process has blocked or finished before the quantum has elapsed, the CPU switching is done when the process blocks, of course. Round robin is easy to implement. All the scheduler needs to do is maintain a list of runnable processes. When the process uses up its quantum, it is put on the end of the list

Part 2

quantum. Since there is no clock interrupt for multiprogramming threads, thread that is running can keep running as long as it wants until it runs out of power. This thread will get whatever the scheduler considers their appropriate share, no matter what is going on inside process.

  • Example: A’s threads have relatively little work to do per CPU burst, 5 msec of work within a 50-msec quantum. This might lead to the sequence A1, A2, A3, A1, A2, A3, A1, A2, A3, A1, before the kernel switches to other process.
  • In kernel-level threads: The kernel picks a particular thread to run. The thread is given a quantum and is forcibly suspended if it exceeds the quantum. + Example: With a 50-msec quantum but threads that block after 5 msec, the thread order for some period of 30 msec might be A1, B1, A2, B2, A3, B3, something not possible with these parameters and user-level threads.