# IB Topic 2 Computer Science - Operating systems and programs The topic 2 in CS of IB can be divided in 4 parts * Logic gates * Binary/denary/hexadecimal * Hardware systems * Software and OS We're doing the part of explaining what is an OS (Operating System) and programs that we can find on it. This topic has an overlap with HL topic 6. ## Operating System As we saw in [the hardware part of this topic](/3xQjnnJgTLylJr8LzNzkYw) we have a **pretty complex** hardware in most of our computer systems. So, to deal with it, we use Operating Systems. :::info An **Operating System (OS)** is a set of _software_ meant to _interface_ the hardware and other software that can be built on top of it (programs, aplications) and handles the basic operations of the system. ::: Usually we think in Computer Science of OS as in a **layer** ![imagen](https://hackmd.io/_uploads/SJ_MH2sxR.png) **Example of layers** Imagine that you're on your phone and you press a button to open your favorite app. In this case you (the user) are using a hardware (the capacitive screen) to press into a part of it. The OS (iOS or Android in the case of most phones) is going to intercept and process that signal as pressing in a part of the virtual "desktop" and it will decide to open the app that was in that part of the virtual desktop. **Other example of layers** Nowadays in laptops we have even more layers. Right now I'm writing this in a webApp (hackmd) ![imagen](https://hackmd.io/_uploads/BkjfInolR.png) _hackmd_ that is embedded in a website shown by a browser (Firefox, aguante Firefox) ![imagen](https://hackmd.io/_uploads/Hy1HLnog0.png) _hackmd in Firefox_ In this case the browser is a program (app, application) that works in the OS that I have (in this case Windows 11) ![imagen](https://hackmd.io/_uploads/HJ7OUhse0.png) _hackmd in Firefox in Windows 11_ And all of it is working in a laptop that is a physical piece of hardware ![imagen](https://hackmd.io/_uploads/HkL6wholC.png) So all the layers to write this words are | | | -------- | | User (me) | | Hardware (laptop Lenovo) | | OS (Windows 11) | | Program (Browser, Firefox) | | WebAPP (Hackmd) | **Another example by Y.C** In her case she's using [Notion](https://www.notion.so/) to take notes and here we have the layers of the system ![imagen](https://hackmd.io/_uploads/B1PBthoeC.png) ### Functions of an Operating System Summary: * Read/write files * Peripheral communicationn /Control hardware through drivers * Security features * Networking * Manage resources ### Read/write files The OS is in charge of reading and writing files on the computer. When you save your data within an program, this program tells the OS where it want it to be writen (or read) and the OS is the one that is going to actually tell the hardware to read/write that file. Also OS come with different ways to distribute the files through the secondary memory (formats) ### Peripheral communication :::info Remember that **peripheral** is a device that doesn't work on their own but needs to be connected to a main computer. Like a mouse or a external keyboard. ::: OS communicate to these peripherals using certain type of software called drivers. ![fotonoticia_20160208130146_1200](https://hackmd.io/_uploads/r1kV8MHlA.jpg) _not this taxi driver, though_ (image from the movie Taxi Driver) This software allows the OS to know if the mousse has moved or send to a printer the page that you need to print. ### Security Other function that we associate to an OS is security. This security goes from encrypt files to have autentication systems (logins, etc) and also differnciate permissions. As an example in the corporate computer of the teacher I cannot install any program that I want if IT doesn't approve it (or a person with their password). This is is integrated in my OS (Windows) and probably could also be done in the other major OS (macOS and linux) :::info **Vocabulary of admins** To distinguish users between them in OS we usually have 2 levels of users. Administrators and other (usually more restricted) users. An administrator has full control of the system, whereas the regular user only has some part of it. Specifically to install new software in the computer or do certain tasks. In *linux* contexts these admins are called su (short of super user) and usually can make more statements. In the **command line** you sometimes write sudo [command] to do a specific command with super user permissions. This lead to this joke ![sandwich](https://hackmd.io/_uploads/r1KOcSRxR.png) https://xkcd.com/149/ ::: ### Networking We're going to expand this topic in topic 3 but OS usually have a lot of things to say regarding networks. OS are usually in charge to have the tools to connect to the different networks and manage those connections. For example when you have this type of selection of which wifi do you want to connect to is something that your laptop or mobile is doing thanks to the OS. ### Managing resources This is expanded way more in Topic 6. There are 3 main computing resources. Computation, memory and bandwidth. The OS is usually in charge to distribute these resources between the different applications being like a manager or a cop. You can see it in the task manager. This is from windows ![imagen](https://hackmd.io/_uploads/SJ8QpH0l0.png) _Spanish gonna Spaniate_ You can see in the columns that they say CPU (processing), Memory (primary memory, RAM), disk (bandwith with the disk) and network (bandwith with the network). In macOS you can see through the activity monitor and you will see something very resembling. ![imagen](https://hackmd.io/_uploads/ry1m0rAeR.png) ### Where is the OS :::success They sometimes ask for this specifically in the IB tests. ::: The OS usually is stored into secondary memory. (Usually a HDD or a SSD). When the computer is booted (initialized) it's transfered (most of it) into the primary memory (RAM). This what is (mainly) happening when we have the booting images ![imagen](https://hackmd.io/_uploads/SkKJnq7W0.png) _old windows xp_ ![imagen](https://hackmd.io/_uploads/HJA-nq7bR.png) _iOS_ ![imagen](https://hackmd.io/_uploads/r1WEn5mZC.png) _some Linux distros are more transparent in this kind of booting images_ In some cases when the OS is so little that can be directly manufactured into the microcontroller is written on the ROM. Not common in regular nowadays computers ![imagen](https://hackmd.io/_uploads/rydJaqQW0.png) _Commodore 64 was a computer with a keyboard integrated. They have their OS stored in a ROM. These were the 1980s_ ### Examples of OS * Windows (several versions, developed by Microsoft) * macOS (several versions, developed by Apple) * linux (generic, thousands of types called "distros", based on GNU, maintained by fundations) * iOS (specific for mobile products developed by Apple) * android (specific for mobile products, usually with another layer on top specific of the branch) Others * FreeBSD * Unix (VERY old) * AMD/400 (IBM, very old) ## Types of programs/applications As a Computer Science student you need to understand what is the difference between a program and the category of that program. Depending on the function you can have one or other programs and you might find different solutions. :::success In IB exams they don't ask for specific programs like "word", they go with the generic "word processor". This is important because I've seen students with a lot of confusion with these concepts. ::: Types of programs: * Word processors. Creates written documents. Examples: Microsoft Word, Google Docs, apple iPages, LibreOffice Writer * Spreadsheet. Usually called "excels" but the idea is organize and clasify data in rows and columns.Examples: Microsoft excel, Google Spreadsheet (they didn't thought a lot with the name here google), LibreOffice calc. * Data Base Managment System (DBMS): A program to manage DB (Data Base). For example Access and some clients of DB. :::info Some of the IA can have a DB and probably part of it (or at least the maintenance) can be done (or should be done) using a DBMS that we can use for adding/editing records in the DB that the program uses with another interface (such a front-end web app, for example) ::: * Email client: A program that ask an email server for email (send and recieve). For example outlook or thunderbird. Also Gmail aplication for mobile phones. * Browser: A program that interprets HTML pages and process also http requests. For example, Chrome, Edge, Firefox, Opera ![61N0K1ARWTL._AC_UF894,1000_QL80_](https://hackmd.io/_uploads/r1i4-IClR.jpg) _not to confuse Browser with Bowser from Mario_ * CAD: Computer Aided Design. Programs that are used to draw/design. There are a lot of subtypes * Photo and raster retouch: Adobe Photoshop, GIMP * 3D design: Tinkercad, Blender, WOMP, AutoCAD, SketchUp * 2D vector design: inkscape, adobe illustrator, autoDesk AutoCAD You should totally check this page out with alternatives to the programs from Adobe https://github.com/KenneyNL/Adobe-Alternatives * Graphic Processing software. Also manipulating images using software. The line with CAD is difficult. * Photo and raster retouch: Adobe Photoshop, GIMP Other types of software that are not included in the categories of applications from the book. * Games (no info about this) * Video game launcher. Nowadays with Steam, battle.net or epic games, usually we have a program that manages the games (or other software) that we can install or uninstall with a DRM system integrated. DRM is Digital Rights Management and is how a program avoids piracy. They are some privacy concerns about these programs (should Steam inc know exactly what are you playing, how and where from all the people of the world? Can we play but opt out from this?) ![imagen](https://hackmd.io/_uploads/r1u1giXZC.png) (_from this video https://www.youtube.com/watch?v=fCUTX1jurJ4_) * Communication programs. Nowadays we can use whatsapp/telegram/discord/weChat in the browser but sometimes they have their own applications. These programs allows people to connect to each other. Sometimes with text. Also with audio/video supported (discord, meet, jitsi, zoom). ![imagen](https://hackmd.io/_uploads/S18ogiQZA.png) _pandemic memories unlocked!_ Back in my days we used MSN messenger or skype ![imagen](https://upload.wikimedia.org/wikipedia/en/a/aa/Royale_theme.JPG) _old days_ * Video editing programs. Programs that edit video. Capcut, adobe Premiere, davinci resolve, and other alternatives that you can check out [here](https://github.com/KenneyNL/Adobe-Alternatives?tab=readme-ov-file#premiere) * IDE. Integrated Development Enviroments. In short: programs to program. Arduino IDE, visual studio code, atom (even if now is sunsetted by microsoft), eclipse (for java). * SDK Software development Kit. Like Ren'py. ### Embedded browsers in programs Some programs (like discord, whatsapp, telegram) when downloaded in a computer, are actually webbrowsers with the webapplication pre-installed. The most common framework to do it is called [electron](https://www.electronjs.org/) ![imagen](https://hackmd.io/_uploads/HysEdnsl0.png) Nowadays is very common to see this kind of "applications" that in the bottom of it has a browser ([Chromium](https://www.chromium.org/chromium-projects/)) The advantadges of these for the perspective of the development is that Chromium already handles the interface with all the OS (mainly Linux, macOS and Windows) so there is no need of writing 3 different programs and maintain them for 3 different OS. The disadvantadges are that using another layer is not that efficient and usually is more memory heavy. Also there are some concerns about chromium, chrome and backdoors that it may have concerning privacy. In my opinion if a webapp has an application, unless is strictly necessary, keep using the web application. Less stuff in the computer, faster booting (starting the system) and less concern about privacy (unless using chrome). ### Common features of applications This is lexicon * UI, User Interface. This is the part of the program that deals with the /human/. This can be done in graphical or command lines (or voice commands). It's also called "Front End" in web and other types of applications. In games the UI is the part of the menus, dialogs and so on. ![imagen](https://hackmd.io/_uploads/HkDfn1rbC.png) * GUI, Graphical User Interface is the element that the user interacts with the program with visuals. Windows, screens, buttons, anything that is graphical around the interaction User-machine. * Command Line Interface (CLI). This way of interfacing is via a command line where you type a command and then the console executes something. CLI can be embedded in GUI. For example in your browser you have an actual CLI in the status bar on top In firefox if you write: about:config you can access to the configuration of your browser and if you write a URL(Unique Resource Location) it's going to attempt a https request to that place. If you write something else probably your browser is going to load your default search engine look out. Those are commands that you can have in your everyday program. If you write "wikipedia" it goes to the search page of wikipedia in google (my default search engine, I _do_ need to change this one) ![imagen](https://hackmd.io/_uploads/SyJ9pkHWR.png) But if I write wikipedia.org it's going to understand that is an URL and it's going to go straight to wikipedia without telling google directly that I want to go to wikipedia ![imagen](https://hackmd.io/_uploads/SJea6JrZR.png) In some programs like autoCAD they have a GUI but also a command line that you can interact ![imagen](https://hackmd.io/_uploads/BkzlAkB-A.png) When we did stuff in arduino IDE through serial that was a small CLI that we did. Other example is [FFMPEG](https://ffmpeg.org/). A program that encodes video (converts video and audio from one format to another). The main way to do it (and faster) is using a CLI where you type the file that you need to convert, the conditions and the output file and it does it for you. Ther is actually a GUI but is way clunkier than working with the CLI Pros of command lines * Easier to implement * Less memory to run * Can be run without a monitor * Quicker for experienced users (we type faster than we use the mouse) * Easier to interface with other programs. Cons of command lines * Not very accessible * User need to remember or find the commands. Step learning curve. Pros of GUI * Easier to use * Graphical icons are easier to remember than commands * You can group elements through menus and toolbars * More accessible (if well done) Cons of GUI * More complex to implement * Requires more memory * Need a graphical monitor and a pointing device (can be a capacitive screen) ## Binary representation [this parts omits for now how binary and hexadcimal works] 1 **bit** is an amount of information that can be only 1 or 0 (only 2 possible values) 1 **Byte** is a group of 8 bits. A byte can have $2^8=256$ possible values. Multiples When working with memory we work with multples and usually in CS they go instead of $10^3$ with $2^{10}$ (because binary). So 1 KB is equal to 1024 Bytes; 1 MB is equal to 1024 KB, 1GB is equal to 1024 MB, 1 TB is equal to 1024 GB and so on. ### Representing different types of information with bits and bytes [This is only revision] #### Numbers With numbers we should only need as many bits as the $log_2 +1$ of the number. For example for representing the number 2, we need 2 bits, for representing number 5 we need 3 bits (the binary representation of 5 is 110). If we have the number 2000 we need 11 bits (with 10 bits we can arrive up to $2^{10}-1=1023$ and with 11 bits we can arrive up to $2^{11}-1=2047$ ) The problem arrives when the computer doesn't have to know when a number that needs to consider starts or ends. If we have MB we may don't know how to chunk those numbers. To solve that we use registers. So we define types (in high level programming languages that are highly typed) to specify how big is a number in memory. In this case how many bits can it hold. In different programming languages we can have different types for different sizes that depends on the languages. Here you have C++ and Java https://www.w3schools.com/java/java_data_types.asp ![image](https://hackmd.io/_uploads/HJeAC22ZR.png) https://learn.sparkfun.com/tutorials/data-types-in-arduino/defining-data-types ![image](https://hackmd.io/_uploads/BJR0C33WC.png) For representing signs usually we set a bit at the beginning for knowing the sign. For representing big numbers (such as factorials (! numbers)) we may use part of those bits for representing the first digits and then save some space for the number of the power of 10 that we're power to. :::info In computer science maybe we see scientific notation $2.234ยท10^4$ written as $2.234E4$. Here you can see an example in excel ![image](https://hackmd.io/_uploads/B16VMan-0.png) ::: #### Characters For using bits and bytes to represent charactes we need a table that can be a key for understandind which caracter is which number and there have been several ways to do this. One of the most common created in the 70s was the ASCII, created in the US that represents characters using 7 bits, so we can have 128 possible caracters. ![imagen](https://hackmd.io/_uploads/H1E0QxS-A.png) (source https://www.asciitable.com/) Problem with this is that there are other languages, Stephen. That uses other characters. Nowadays the most common encoding system is called UNICODE. You can visit here the lots of [Unicode that you can use](https://symbl.cc/en/unicode-table) #### Strings Strings are array of characters. If you know hot to work with characters, strings are arrays of that. #### Colours When we have raster images (images that have pixels) we use commonly 3 bytes to represent its colour. 1 for the Blue luminance, 1 for Green and 1 for Red. So in one pixel with this system we can represent $2^{24}$ colours. This related video is interesting for this: https://www.youtube.com/watch?v=Kv1Hiv3ox8I {%youtube Kv1Hiv3ox8I%}