Showing posts with label Class Notes: Operating System Concepts. Show all posts
Showing posts with label Class Notes: Operating System Concepts. Show all posts

C++ Program (Source Code) for Priority Scheduling CPU Scheduling Algorithm

Priority Scheduling:

In operating systems, tasks that are queued to be processed go through different scheduling algorithms in different operating systems. Priority Scheduling is one of them.
Priority scheduling is like shortest job first except that the next job to process is selected not by the amount of time it will take, but by the priority of the job. So in this priority scheduling each job has a priority value associated with it. The task with shortest priority value gets preferred.


C++ Program (Source Code) for Round Robin (RR) CPU Scheduling Algorithm


Round Robin (RR):

In operating systems, tasks that are queued to be processed go through different scheduling algorithms in different operating systems. Round Robing or RR is one of them.
In round robin, like first come first served, the job or task that comes first, gets processed first, but not fully. Rather in round robin, a portion or segment of the task is completed at once, then the processor moves to the next task and then processes that same amount of task for this second task in hand and it continues. When a portion or segment of all tasks has been processed, the processor starts from the beginning of the task list again and continues to process a portion or segment of each remaining tasks. However in this way, as new task can be continuously added at the end of the task list, the processor might not come back to the head of the list sooner which might cause tasks to be waiting for much longer time ultimately resulting in halted situation.


C++ Program (Source Code) for Preemptive Shortest Job First (SJF) CPU Scheduling Algorithm

Shortest Job First:

In operating systems, tasks that are queued to be processed go through different scheduling algorithms in different operating systems. Shortest Job First or SJF is one of them. In shortest job first, literary, the smallest task among all the remaining tasks will get processed first.

However, I explained Shortest Job First (SJF) in my another post earlier and as many of my readers wanted to have the source code, here I am publishing the source code of the program. I am not currently explaining the source code, please try to play with it to understand it. I am removing comments intentionally.


C++ Program (Source Code) for First Come First Served (FCFS) CPU Scheduling Algorithm

First Come First Served (FCFS): 

In operating systems, tasks that are queued to be processed go through different scheduling algorithms in different operating systems. First Come First Served or FCFS is one of them.
In first come first served, literary, the task that comes first to be processed gets processed first, then the next one and this continues. This is a less preferable way of scheduling as any task can block the processor for infinite amount of time. Also as all tasks are given the same priority, more important tasks might be waiting too long to be processed.


3 Differences between time sharing and real time systems

Q. What are time sharing and real time systems? What are the differences between time sharing and real time systems?

Time-Sharing Systems:

Time sharing operating systems are extension of multi-programmed batched operating system and the extension is that here the user can interact with the program running. The CPU scheduling algorithm and allocate small amount time to each job at once and then move on to the next job. Thus the user can get output from the program and can input another command and wait for the output. Keyboard is used to input command and monitors are for output. A time sharing operating system allows many user to use the same computer at the same time such as every user is using his own computer. This is achieved by frequently switching from one program to another and satisfying users with an output from the program before switching to the next one.

2 differences between time sharing and multi-programmed batched systems?

Q. What are time sharing and multi-programmed batched systems? What are the differences between time sharing and multi-programmed batched systems?

Time-Sharing Systems:

Time sharing operating systems are extension of multi-programmed batched operating system and the extension is that here the user can interact with the program running. The CPU scheduling algorithm and allocate small amount time to each job at once and then move on to the next job. Thus the user can get output from the program and can input another command and wait for the output. Keyboard is used to input command and monitors are for output. A time sharing operating system allows many user to use the same computer at the same time such as every user is using his own computer. This is achieved by frequently switching from one program to another and satisfying users with an output from the program before switching to the next one.

2 Differences between parallel and multi-programmed batched systems

Q. What are parallel and multi-programmed batched systems? What are the differences between parallel and multi-programmed batched systems?

Multi-programmed Batched Systems:

In multi-programmed batched operating systems, the operating system reads jobs from disk drives where a list of jobs are already being stored through card readers. The operating system then pull and store as much job as it can in the memory. Then from the memory, operating system start working on a job. Now, whenever a job reaches a situation where is has to be waiting for one or more tasks to be completed like use of any IO devices, the operating system pulls another job from the memory and starts working on it. Whenever this job also starts waiting, for example it need to use the same IO which is already in use by its previous job, the operating systems pulls another job. This is how, a multi-programmed batched systems harness the power of disk drives and memory.

4 Differences between simple batch and multi-programmed batched operating systems

Q. What are simple batch and multi-programmed batched operating systems? What are differences between simple batch and multi-programmed batched operating systems?

Simple Batch Systems:

Early computers used to take one job at a time, no input in the middle of the process and also no output either. The jobs were prepared commands for the computer to execute on its side and these jobs were generally written on cards, control cards, which the computer used to read through card readers. After processing the job, the computer used to output the data through line-printer machines or tape drives. 

So, the simple batch operating systems were designed to speed up the process by grouping jobs which are similar in nature into one job and execute them and then send back output of each jobs to its programmer. So simple batch systems lack the interaction between the programmer and the machine while it’s running or working on a job.

5 Key Functions of Operating System

Q. What are the functions of operating system?

Functions of Operating Systems: 

Operating system’s size, organization and scope of operating vastly depends on the size, organization and use of various computer system. Obviously not all operating systems can be used on all systems. Functions of an operating system are always targeted to meet the needs. Some operating systems are designed to give more flexibility to users, some gives more priority to performance and security and some are designed to be operated by other operating systems, not humans. 

However, following are some general functions of operating systems

What are the conditions for deadlock situation to occur?

Deadlock

In a system, deadlock situations are moments when processes never finish executing and system resources are tied up, which ultimately prevents other processes from ever starting. Dead lock situations are obviously undesirable, however they occur in systems while the following conditions take place simultaneously. These conditions are not completely independent, that is, all four conditions must hold for a deadlock to occur.

What is a process in operating system? What are the process states?

Process: 

A process can be thought as a program in execution, but a program by itself is not a process. Process is nothing but a set of instruction to be executed. Multiple instances of a single process can be running at any given time and also a process may create sub-processes with time. Processes may need certain resources like, CPU time, memory, files and access to other devices.

4 Key Reasons for building Distributed Systems.

Q. What are the reasons for building distributed systems?

Distributed Systems: 

Distributed Systems (also loosely coupled systems) are also multiprocessor systems but they will not be sharing clock, memory etc. and will be communicating with each other with high speed buses, telephone lines etc. Processors in distributed systems may vary in size and function and include microprocessors, workstations to large general-purpose computers. Some of the reasons for building distributed systems are resource sharing, computation speed up, reliability, communication etc.

7 Different types of operating systems


Q: What are the different types of operating systems? Briefly describe.

Operating systems and computer architecture have had a great influence on each other. As hardware industry started to develop powerful and feature enriched hardware for computers, the operating systems needed to update themselves to harness the power of those hardware. Again, as operating systems started to show what else they can do, hardware manufacturers needed to develop further better hardware. Following are different types of operating systems.

What is operating system? Describe operating systems in brief.

Operating System:

An operating system is an intermediary program between computer user and the computer hardware. This computer user can also be just another software running on the operating system or another computer or device. So basically, operating systems are computer programs that let other computer programs or humans communicate with the hardware of the computers. 

Explain and Solve : Round Robin (RR) CPU Scheduling Algorithm in C++ with Explanation


If you haven't read/tried the earlier/other problems then click the links follow:

Round Robin CPU Scheduling Algorithm in C++ with Explanation: 

This method is quite same as the FCFS but the difference is the in this case the processor will not process the whole job (process) at a time. Instead, it will complete an amount of job (quantum) at a turn and then will go to the next process and so on. When all job has got a turn, it will again start from the first job and work for a quantum of time/cycle on each job and proceed. Now consider a CPU and also consider a list in which the processes are listed as follows,

Arrival
Process
Burst Time
0
1
3
1
2
2
2
3
1

Quantum = 2 Second

Explain and Solve : Priority Scheduling CPU Scheduling Algorithm in C++ with Explanation

If you haven't read/tried the earlier problems then click the links follow:


Priority Scheduling CPU Scheduling Algorithm in C++ with Explanation: 

This method is quite same as the SJF but the difference is that instead of choosing the next process to work on by the shortest burst time, CPU chooses the next process by the shortest priority value. Here, all the processes are given a priority value. The process with the shortest (The most shortest is 1) priority will be worked on first and so on. Now consider a CPU and also consider a list in which the processes are listed as follows,

Arrival
Process
Burst Time
Priority
0
1
3
2
1
2
2
1
2
3
1
3

Preemptive Shortest Job First (SJF) CPU Scheduling Algorithm in C++ with Explanation


If you haven't read/tried the earlier problems then click the links follow:



Preemptive Shortest Job First (SJF) CPU Scheduling Algorithm in C++ with Explanation

Preemptive Shortest Job First (SJF) CPU Scheduling Algorithm in C++ with Explanation:

Preemptive Shortest Job First (SJF) is a CPU scheduling algorithm in which the CPU, at any given time, looks for the job with the shortest burst time among the jobs in hand and starts processing it. In SJF the processor will not just pick the job that arrived first, rather will compare them based on their required CPU time and will pick the one which requires lowest amount of time.

Explain and Solve : First Come First Served (FCFS) CPU Scheduling Algorithm in C++ with Explanation

If you haven't read/tried the earlier problems then click the links follow:


First Come First Served (FCFS) CPU Scheduling Algorithm in C++ with Explanation: 

CPU gets a lot of processes to handle. The problem is shortening the waiting time for a process to reach CPU and get processed. Now consider a CPU and also consider a list in which the processes are listed as follows,
Arrival
Process
Burst Time
0
1
3
1
2
2
2
3
1

Here, Arrival is the time when the process has arrived the list, Process Number is used instead of the process name, and Burst Time is the amount of time required by the process from CPU. Well, as the unit of time you can take anything like nano-second, second, minute etc whatever. We consider it as second.