How Input and Output devices work together

Vignesh Sekar
A free video tutorial from Vignesh Sekar
Software Engineer,Computer Science Instructor
4.5 instructor rating • 14 courses • 12,715 students

Learn more from the full course

Operating Systems from scratch - Part 1

Learn the concepts of Operating Systems from scratch as Operating System forms the core of Computer Science

08:18:41 of on-demand video • Updated October 2020

  • You will become very familiar with the core concepts of Operating Systems
  • You will be able to challenge the interviewer on questions related to Operating Systems
  • You will view Computer Science in a different dimension
  • You will be able to answer all questions of exams like GATE,PGEE,ISRO (after completing all parts of OS course
  • You will be able to get a top grade in your Operating systems course in your Bachelor's degree
  • Understand how Operating Systems work
  • Understand how a process is created
  • Understand how CPU scheduling is done in Operating Systems
  • Understand the various scheduling algorithms we have in Operating Systems
  • Understand how CPU , Memory and Disk work together
  • Understand Memory managment in Operating Systems
  • Understand how a process is moved from hard disk to RAM
  • understand memory allocation strategies used by operating systems
English So so far we have seen ... what an operating system is ... operating system is nothing but a program which is going to act as a resource manager. OK.? Now this operating systems program will always be present inside the RAM which means ... whenever we switch-ON the computer these operating systems program will be loaded inside the RAM... ok..? This is the code... right ..? this code will be loaded inside the RAM and this program will be in the RAM forever...ok ? It will always be present inside the RAM ... Now this code. This code is what we are placing it here right...? This code will always be present inside the RAM and we say this set of addresses ... See our RAM will be full of addresses. Right...? And these set of addresses where the operating system's program is placed is also called as OS code space... right...? it is also called OS space whereas the remaining space is used for placing our programs .... our programs means application programs. The programs which we write ... Or the programs which belong to a particular software like Photoshop, MS-WORD and all these ... OK.? All these programs will be actually placed within this space and we say this space as user space ...ok ? we say this space as user space where we place lot of programs. For example , P1,P2,P3......any program ... OK. ? which we execute .... will be placed in things within this space .... fine. Now So far we have seen how CPU, RAM and hard disk work together.... How...? For example .. initially our source program will be given to a compiler and it will be converted to machine code. Once it is converted into a machine code it will always be placed inside the hard disk. OK..? now at some point in time ... This program will be loaded into the RAM (within the user space) and once it is loaded into the RAM this program at some point in time will be taken by the CPU line-by-line (instruction-by-instruction) and executed.... OK..? this is how a program actually is being executed... fine. Now once this execution of this program is done by the CPU... right ?? the program is actually executed by taking line-by-line by the CPU. And at some point in time the execution of this program will get done.. Right ? Once it is done ... this program will be completely removed from the RAM ... OK..? all information about the program which is maintained inside the RAM will be actually completely . removed... Which means the space will be free. Why.? Because some other program can accomodate that space... right ...? That's the reason we do that. Fine. Now let's see... how I/O devices .... I/O devices means keyboard, monitor, mouse and all these devices right ..? How these devices work along with the CPU (communicate along with the CPU) that's what we are going to see... right...? See any I/O device will have a buffer associated with it. For example our monitor will have a buffer.... buffer means nothing but memory or register ... okay ? .... This space.... And also keyboard,printer ( or you can take any device ) ...every device will have a buffer associated with it ... Now why this buffer is actually helpful..? Now just to understand that. Let's see. How a calculator application works in our computer. OK .? .. we have a calculator software. Ok ..? a software now. This software will be in .exe format right ? executable code. We have already seen it ... machine code is nothing but executable code .. Both are same ... Now using this software .. I am going to add 2 numbers say 2 + 3 and then I want to see the result equal to 5 in my monitor. OK ..? see 2 and 3. I'm going to give it through keyboard ...Ok ..? Mouse or Keyboard .... Anything is fine ... but let's assume for time-being both 2 and 3 are given to the computer through the keyboard and once the result is computed ... this result "5" has to be displayed in the monitor. OK..? this is what we're going to do... First.... We will be opening this. First of all what we'll be doing is ... we will be opening this calculator app .. right..? now for that... incase if the calculator app is already present inside the RAM... It is fine... if the app is not. If the software is not present inside (Software is nothing nothing but a program) right..? calculator program...incase if the the problem is not present inside the RAM it will be fetched from the hard disk and then it will be placed inside the RAM ..OK.? ... Let us assume .... the calculator app is now present inside the RAM ... Fine ... Now whenever I enter "2" in the keyboard....2's binary format is nothing but "0 1 0"... right ? this will come into the buffer. Why this is coming in binary format...? Because computers can understand only binary format .... right,,.? That's the reason this "0 1 0" will get into the buffer. Similarly from this buffer.... This (010) will be moved into the RAM ...ok ..? "0 1 0" is nothing but 2 ..right ? (in binary). Similarly whenever I type 3 in keyboard... "0 1 1" will overwrite this in the buffer and this "0 1 1" will also be moved inside the RAM ... OK...? fine... now once this is moved inti the RAM ...the CPU will take both "010" and "011" inside its registers ... See ....CPU will also be having a Buffer or register... ok ? Generally how CPU will perform its operation is ...it will take the operands ...Here operands means "2" and "3" are operands ...right ? These options will be taken into the register. "010" ... "011" ......Not only this operation ... any operation will be done in this way ... All the operands will be fetched into the register and the operation will be done by the CPU.... Here the operation is nothing but addition .... it will be done by the CPU .... and the result will be over-written In one of the registers... any register (among 2) ... it really depends on the implementation... ok ? ok? In one of these two registers the result will be placed... "2+3" is nothing but "5" and 5's binary format is "1 0 1". This will be overwritten in this .... Now who actually does this addition ? It is done by the CPU ... How.? Because CPU will be having 2 parts ....ok ? "control unit" and "arithmatic and logic unit". Let's see about CONTROL UNIT a bit later it's not important for this course ...actually ... Now coming to Arithmatic and logic unit....they will do all the mathematical operations which we do in our computer. It can be addition, subtraction, logarithm, multiplication, division..... any mathematical operation you take.... It can be done by your arithmatic and logic unit using hardware circuits ... ok ? using this (ALU) the result "1 0 1" has been computed and this will again be placed inside the RAM ... ok ? This "1 0 1" will be placed inside the RAM ... fine ... Now this has to be displayed in the monitor right.? We want to see this in monitor (the result) ...Now what will be done is ... this "1 0 1"...which is the result .... will be placed in the monitor'buffer As a result of which we are able to see the result in our computer's screen... ok ? this is how this is being done... ok ? let's take one more example. OK.? See I'm explaining all these to understand one thing (one concept) .. ok ? I will explain it later. Now let's take one more example. I'm taking some word document which has been already created and it has been saved....ok ? If it is saved... it has to be present inside the hard disk...right ? Let us assume there is a word document which is present inside the hard disk ... The name of the document is... (say A) OK ? this is the name of the document. Now I want to edit this document which means I want to add some more letters into the document and then I might have to save the document... ok ? so what I should be doing is... first this document will be moved from Hard disk to RAM ... Why ? Because CPU cannot access the hard disk directly ... now to edit that this has to be more into the RAM ....Fine ... This document is moved into the RAM .. ok ? which means something is moved from hard disk to RAM and this document. First of all MS-WORD is a program and that program will also be loaded into the RAM ... OK..? I'm not showing it here ... but you understand it MS-WORD is actually a software. So that will have a program and that program will also be placed inside the RAM ... Fine ... And that program will be executed by the CPU ... That is fine.... Now This is nothing but data. This data has been loaded into the RAM and then the editing will be done Which means.... incase if I want to add some text to the Word document... that will be done through the keyboard just like how we saw The words which we type will be placed in the buffer... in some binary format... see any letter can be represented in binary format ... Right ..? Those words will be placed in the buffer and then it will be moved into the RAM...ok ? into that exact document. Once this is done... this word document. Now we need to save this document permanently right ..? The only way to do this to move the document from RAM to Hard disk back... right.? So we have made the changes to the document. So what we have done is ... First of all we loaded our program which is nothing but MS-WORD program... This program has been loaded into the RAM and also we loaded the data from hard disk to RAM ... then we made some changes to the document and then we again placed the document into the hard disk... ok ? so we can read something from the hard disk as well as we can write something into the hard disk... ok ? so hard disk can act as an input device as well as it can act as an output device... ok ? hard disk can act as an input device as well as it can act as an output device whereas incase if you take keyboard ....keyboard can always act as an input device why .? because we can only give input to the computer through the keyboard Similarly monitor is an output device Why.? because through the monitor... We as a user... will be able to receive the output but we will not be able to give the put through the monitor..right ? So monitor is an output device. Similarly hard disk can act as an input device as well as it can act as an output device .. ok ? so.... one more important point is ... all this I have explained for explaining only one thing..... To say that a program can undergo something called as I/O Ok..? I/O is nothing but ... for example this calculator program or MS-WORD program In both our examples ... are placed inside the RAM and they are waiting for some time to read the data from one of the I/O devices ....(Input device or output device). I/O I/O device is fine .. ok ..? hard disk keyboard monitor.... All these we can say them as I/O devices.. OK ? Which means our program is actually waiting for I/O for some time. ok ? Ok that is what we mean by I/O event ... So once a program has been moved from hard disk to RAM ... What are all the things this program can undergo ..? (question) OK ? Either this program will be in the RAM this program will be in the RAM and it will be executed by the CPU by taking line by line ....such things we say that as execution ... OK...? execution .....Or this program which is in RAM should have undergone I/O ...ok ? Such things we say as "I/O EVENT" Another possibility is that ...this program is neither performing. execution.... this program is neither executed nor this program is performing I/O event ...In that case ... is program is actually waiting for the CPU to execute or it is waiting for some I/O event ...right ? In that case ... We say that this program is actually waiting for some event to happen. OK.? So in simple terms I can say that ....see ... one point I want to tell is there is something called as TURN-AROUND-TIME ok ? ok ? Turn-around time = First i will write the formula and then I will explain it ... OK.? Tun-around time = waiting time Plus Burst time (or execution time) plus I/O time OK.? So every program at some point in time will be loaded into the RAM ... OK.? Let us assume that there is a program named as P1 ... OK.? This program .....Let us assume this program has been loaded from hard disk into RAM. at 1 AM (time) .. ok ? .......and let us assume that this program has completed execution at 3 AM (time). OK.? this program has completed execution at 3 AM (time). and I already told you that ... once the program has completed its execution the program will be completely removed from the RAM ... The program will be completely removed from the RAM ... Now this duration of time from 1 AM to 3 AM is also called as Turn-around time ... OK. ? Now during this Turn-around time ... What are all the things this program should have undergone ?? which means during this time from 1 a.m. to 3 a.m.. This program should have either waited (which means it should have waited for some event to happen). or this program should have been executed by the CPU... See execution time and burst time ... both are same ...ok ? we can also say this as execution time or as burst time ... both are same ... Or this program should have undergone I/O ... ok ? so this Turn-around time is a combination of waiting them plus burst time Plus I/O time ... see actually we can't say which one among waiting or burst or i/O will happen (in which order) .. ok ? In which order In which order this this will happen..... A program once it is loaded from hard disk to RAM it can undergo either waiting for some duration of time or it should have been executed for some duration of time or this program should have been undergoing I/O for some duration of time .... in what order this happens is really dependent on the program ... The ordering will be different from one program to another.... ok ? OK that's what I want to tell you.... see incase if you didn't Understand this formula. You don't really worry... because we are going to see a lot of problems with this concept... ok ? OK we are going to see something called as SCHEDULING ALGORITHMS ...In that ... we will be seeing all these concepts. OK..? fine.