Questions for today

What does "run" mean?How does code run on the CPU?

CPU - Machine Code

The CPU implements "machine code" instructionsEach machine code instruction is incredibly simple-e.g. add 2 numbers-e.g. compare 2 numbersJavamanuscript code we"ve used: print(1, 2)Javascript is not machine codeJavamanuscript does not run on the CPU directlyJavamanuscript functions in translation -print(1, 2)converts to many machine instructions to actually run on the CPUOnly machine code runs on the CPU"Software" is the general category of code which runs on the hardware. If the hardware is a player piano, then the software is the music. The common instance is a "program" prefer Firefox -- software application you run on your computer to solve a certain problem. A computer system can run multiple programs at the same time and also is responsible for maintaining their memory sepaprice.A CPU understands a low level "machine code" language (also recognized as "aboriginal code"). The language of the machine code is hardwired right into the style of the CPU hardware; it is not somepoint that deserve to be adjusted at will certainly. Each family of compatible CPUs (e.g. the incredibly well-known Intel x86 family) has its very own, idiosyncratic machine code which is not compatible through the machine code of various other CPU family members.

You are watching: The part of a computer that runs programs is called

What is a Program/App?

*
What is a Program or App? - e.g. FirefoxFirefox is made of countless machine code instructions - Run top to bottom (simply like Javascript!) - The Firefox home window shows up (the first 1000 instructions) - Its menus appear (the following 1000) - The cursor blinks waiting for you to typeThe instructions such that, as soon as run, "Firefox" actions happenFirefox.exe is a file in the file system, 80 MB in size (".exe" is a Windows convention for the name of a regimen file)The Firefox.exe file is largely the bytes of machine code instructionsEach instruction is, say, 4 bytes in sizeFirefox.exe at 80 MB is around 20 million machine instructionsThe machine code defines a collection of individual instructions. Each machine code instruction is incredibly primitive, such as including two numbers or trial and error if a number is equal to zero. When stored, each instruction takes up simply a few bytes. When we said previously that a CPU can execute 2 billion operations per second, we meant that the CPU have the right to execute 2 billion lines of machine code per second.A regime, such as Firefox, is comprised of a sequence of numerous these exceptionally easy machine code instructions. It"s a small hard to think that somepoint as well-off and also complicated as Firefox can be accumulated out of instructions that simply include or compare two numbers, however that is how it functions. A sand sculpture deserve to be affluent and also complex when viewed from a distance, also though the individual grains of sand are exceptionally simple.

How Does a Program Run?

CPU runs a "fetch/execute cycle" -fetch one instruction in sequence -execute (run) that instruction, e.g. execute the addition -fetch the next instruction, and also so onRun a program = Start CPU running on its first instruction it runs down through every one of the machine code, running the program the routine will have actually instructions like "return to action 3" to keep it running Super straightforward machine code instructions run at the rate of 2 billion per-secondThe CPU runs instructions making use of a "fetch-execute" cycle: the CPU gets the initially instruction in the sequence, executes it (adding two numbers or whatever), then fetches the next instruction and executes it, and also so on. Some of the instructions influence the order that the CPU takes through the instruction sequence. For instance, an instruction could straight the CPU to jump back to an earlier suggest in the instruction sequence (loops are enforced this way), or to skip over the following instruction if a details condition is true (if-statements are enforced this way).CPU runs a series of machine language instructions

How Does a Program Start?

The file Firefox.exe has its instructions (in the file system)To begin Firefox.exe running: -Each program gets its own area of RAM -The RAM area holds the program"s code and data it manipulates -The instruction bytes are copied from storage to RAM -The CPU is directed to begin running at the first instruction -Now the routine is running!Run Firefox.exe: (1) copy instructions to RAM, (2) CPU runs themIn the file device, a file favor Firefox.exe simply includes the bytes of the machine code instructions that consist of the regime (".exe" is a home windows convention to note a paper as a program). Each machine code instruction takes up about 4 bytes, and entirety regimen is simply an substantial sequence of instructions.When the user double clicks a routine file to run it, basically the block of bytes of the instructions for the routine are replicated right into RAM, and then the CPU is directed to begin running at the initially instruction in that location of RAM.

See more: Living Well Is The Best Revenge Quote, George Herbert Quotes

What Starts Firefox Running? The "Operating System"

What are the measures to run Firefox?"Operating System" -e.g. Windows, Linux, Android, iOSOperating System = ManagementSet of supervisory programs that manage the computerThe operating system runs as soon as the computer system initially starts upManage the start/speak of programsManage RAMManage persistent storageComputers can run multiple programs at the very same timeOperating device keeps track of the information for each routine and shares resources (prefer RAM) among the programsThe "operating system" of a computer system is prefer an initial, supervisory routine that starts running once the computer initially starts up ("boots up"). The operating mechanism plays an invisible administrative and bookkeeping duty behind the scenes. When a lapoptimal or phone starts up, the operating device typically gets things organized and also then launches a "file explorer" routine which display screens obtainable programs and menus etc. that display the user what is accessible, permitting the user to navigate and run programs.The operating system keeps points arranged in the background so that multiple programs have the right to run at the very same time, which is well-known as "multitasking". The operating device offers each program its very own area of memory, so each regimen just accesses its own sources .. attempting to limit what an erroneous or malicious routine deserve to carry out. Keeping the programs separate is occasionally well-known as "sandboxing" .. mediating the accessibility of each routine so it opeprices separately, without interfering through other programs or the system all at once. Similarly, each regime has actually some accessibility to the display screen via a home window, however this output area is separated from the output of various other programs.Recall that a .exe file or whatever is essentially just a record of machine code instructions. When you double-click the regime, the operating mechanism "launches" the program, doing the housemaintaining actions of allocating a room of memory within RAM for the regime, loading the initially area of the program"s machine code into that memory, and ultimately directing the CPU to begin running that code.

The Whole Picture - Scenarios

Now we have actually the whole image of a regimen running on the hardware. Look at widespread scenarios.Demo: bring up "Activity Monitor" (Mac) "Task Manager" (windows) -See all the programs running -Do something costly in Firefox, see its CPU % spike -Kill a programoperating mechanism manages cpu, ram, programs, storage

1. Typical Running Programs

Operating mechanism starts and stops programsEach regime has its very own separate area in RAM: its instructions + dataCPU "round robin:" CPU runs a few instructions from each regime so they all the programs appear to be running simultaneouslyPersistent storage is arranged as a document device, programs can review and write data here

2. Program Exits Normally

The routine exits usually ("Quit" menu item)The operating mechanism stops running that programThe operating device reclaims the program"s area of RAM (to be re-used)

3. Program Stuck/Infinite Loop - Abnormal Exit

Suppose routine gets stuck running an infinite loop, is "stuck"The operating device stops running that routine - involuntary vs. normal-exitThe operating system reclaims the program"s location of RAM

4. Running Out Of Memory

A program repursuits more RAM from the operating mechanism e.g. to hold a photo, yet there"s not sufficient RAM availableThe operating device refoffers the repursuit, the regimen provides an error message

5. Memory Access Error

A regimen tries to accessibility the memory of an additional programMaybe bereason of a bug (common)Maybe on function bereason it is malwareThe operating device blocks the accessibility (ideally)Maybe kills the offending regime too

6. Reboot

Why does this settle anything????Sometimes some operating-system regulated bytes in RAM is not rather right -a pest in the operating system, or possibly a hardware errorA reboot wipes all the information from RAMStarts up the operating device freshThis might fix the problemThis should never be necessaryBut periodically it works!The require for reboots is a hallnote of the existence of computer systems in formerly dependable systems!

Why is it called Reboot?

Chicken and also egg trouble.. who runs the operating system?Old phrase: "gain over a fence by pulling on your own bootstraps"When first powered on, computer system runs a special "bootstrap" programThat regimen typically looks for persistent storage containing an operating device to runBoot up - startReboot - do a fresh shutdown/startup cycle