Labels

Showing posts with label OS. Show all posts
Showing posts with label OS. Show all posts

C program for C-SCAN disk scheduling algorithm

                  Circular SCAN (C-SCAN) scheduling is a variant of SCAN designed to provide a more uniform wait time. Like SCAN, C-SCAN moves the head from one end of the disk to the other, servicing requests along the way. When the head reaches the other end, however, it immediately returns to the beginning of the disk without servicing any requests on the return trip (Figure 10.7). The C-SCAN scheduling algorithm essentially treats the cylinders as a circular list that wraps around from the final cylinder to the first one.Read more>>

C program for SCAN disk scheduling algorithm

                        In the SCAN algorithm, the disk arm starts at one end of the disk and moves toward the other end,servicing requests as it reaches each cylinder,until it gets to the other end of the disk. At the other end, the direction of head movement is reversed, and servicing continues. The head continuously scans back and forth across the disk. The SCAN algorithm is sometimes called the elevator algorithm, since the disk arm behaves just like an elevator in a building, first servicing all the requests going up and then reversing to service requests the other way. Read more>>

C program for FCFS disk scheduling algorithm

                          The simplest form of disk scheduling is, of course, the first-come, first-served (FCFS) algorithm. This algorithm is intrinsically fair, but it generally does not provide the fastest service. Consider, for example, a disk queue with requests for I/O to blocks on cylinders 98, 183, 37, 122, 14, 124, 65, 67. If the disk head is initially at cylinder 53, it will first move from 53 to 98, then to 183, 37, 122, 14, 124, 65, and finally to 67, for a total head movement of 640 cylinders.
Read more>> 

C program for worst fit memory management algorithm

                          Allocate the largest hole. Again, we must search the entire list, unless it is sorted by size. This strategy produces the largest left over hole, which may be more useful than the smaller leftover hole from a best-fit approach.Read more>>

C program for best fit memory management algorithm

                             Allocate the smallest hole that is big enough. We must search the entire list, unless the list is ordered by size. This strategy produces the smallest left over hole.Read more>>

C program for first fit memory management algorithm

                        Allocate the first hole that is big enough.Searching can start either at the beginning of the set of holes or at the location where the previous first-fit search ended.We can stop searching as soon as we find a free hole that is large enough.Read more>>

C program for LFU page replacement algorithm

                       The least frequently used(LFU) page-replacement algorithm requires that the page with the smallest count be replaced. The reason for this selection is that an actively used page should have a large reference count. A problem arises, however, when a page is used heavily during the initial phase of a process but then is never used again. Since it was used heavily, it has a large count and remains in memory even though it is no longer needed. One solution is to shift the counts right by1bit at regular intervals,forming an exponentially decaying average usage count.Read more>>

C program for LRU page replacement algorithm

                        If the optimal algorithm is not feasible, perhaps an approximation of the optimal algorithm is possible. The key distinction between the FIFO and OPT algorithms (other than looking backward versus forward in time) is that the FIFO algorithm uses the time when a page was brought into memory, whereas the OPT algorithm uses the time when a page is to be used. If we use the recent past as an approximation of the near future, then we can replace the page that has not been used for the longest period of time. This approach is the least recently used (LRU) algorithm.Read more>>

C program for FIFO page replacement algorithm

                       The simplest page-replacement algorithm is a first-in,first-out(FIFO)algorithm. A FIFO replacement algorithm associates with each page the time when that page was brought into memory. When a page must be replaced, the oldest page is chosen. Notice that it is not strictly necessary to record the time when a page is brought in. We can create a FIFO queue to hold all pages in memory. We replace the page at the head of the queue. When a page is brought into memory, we insert it at the tail of the queue.Read more>>

C program for preemptive priority CPU scheduling algorithm

                     The SJF algorithm is a special case of the general priority-scheduling algorithm. A priority is associated with each process, and the CPU is allocated to the process with the highest priority. Equal-priority processes are scheduled in FCFS order. An SJF algorithm is simply a priority algorithm where the priority (p) is the inverse of the (predicted) next CPU burst. The larger the CPU burst, the lower the priority, and vice versa. In this case, preemptive execution means the execution of a process will be deferred at any time when a process with higher priority comes.Read more>>

C program for preemptive SJF CPU scheduling algorithm

                     A different approach to CPU scheduling is the shortest-job-first(SJF) scheduling algorithm. This algorithm associates with each process the length of the process’s next CPU burst. When the CPU is available, it is assigned to the process that has the smallest next CPU burst. If the next CPU bursts of two processes are the same, FCFS scheduling is used to break the tie. Note that a more appropriate term for this scheduling method would be the shortest-next CPU-burst algorithm, because scheduling depends on the length of the next CPU burst of a process,rather than its total length. In this case, preemptive execution means the execution of a process will be deferred at any time when a process with lower execution time comes.Read more>>


C program for non-preemptive SJF CPU scheduling algorithm

                        A different approach to CPU scheduling is the shortest-job-first(SJF) scheduling algorithm. This algorithm associates with each process the length of the process’s next CPU burst. When the CPU is available, it is assigned to the process that has the smallest next CPU burst. If the next CPU bursts of two processes are the same, FCFS scheduling is used to break the tie. Note that a more appropriate term for this scheduling method would be the shortest-next CPU-burst algorithm, because scheduling depends on the length of the next CPU burst of a process,rather than its total length. Non-preemptive execution means the execution of a process will not be deferred at any time.
Read more>>

C program for round robin CPU scheduling algorithm

                      The round-robin (RR) scheduling algorithm is designed especially for time sharing systems. It is similar to FCFS scheduling, but preemption is added to enable the system to switch between processes. A small unit of time, called a time quantum or time slice, is defined. A time quantum is generally from 10 to 100 milliseconds in length. The ready queue is treated as a circular queue. The CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval of up to 1 time quantum.Read more>>

C program for non-preemptive priority CPU scheduling algorithm

                  The SJF algorithm is a special case of the general priority-scheduling algorithm. A priority is associated with each process, and the CPU is allocated to the process with the highest priority.Equal-priority processes are scheduled in FCFS order. An SJF algorithm is simply a priority algorithm where the priority (p) is the inverse of the (predicted) next CPU burst. The larger the CPU burst, the lower the priority, and vice versa. Non-preemptive execution means the execution of a process will not be deferred at any time.  Read more>>

C program for FCFS CPU scheduling algorithm

                     By far the simplest CPU-scheduling algorithm is the first-come, first-served (FCFS) scheduling algorithm. With this scheme, the process that requests the CPU first is allocated the CPU first. The implementation of the FCFS policy is easily managed with a FIFO queue.When a process enters the ready queue,its PCB is linked onto the tail of the queue. When the CPU is free, it is allocated to the process at the head of the queue.The running process is then removed from the queue. The code for FCFS scheduling is simple to write and understand.
Read more>>