questions for today

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

CPU - maker Code

The CPU implements "machine code" instructionsEach machine code instruction is very simple-e.g. Add 2 numbers-e.g. Compare 2 numbersJavascript password we"ve used: print(1, 2)Javascript is not an equipment codeJavascript does not run on the CPU directlyJavascript works in translation -print(1, 2)translates come a many of maker instructions come actually run on the CPUOnly device code runs on the CPU"Software" is the general category of password which operation on the hardware. If the hardware is a player piano, then the software is the music. The common case is a "program" choose Firefox -- software application you run on your computer system to settle a details problem. A computer can operation multiple program at the exact same time and is responsible for maintaining their memory separate.A CPU understands a low level "machine code" language (also recognized as "native code"). The language the the device code is hardwired right into the style of the CPU hardware; the is not something that have the right to be changed at will. Each household of compatible CPUs (e.g. The really popular Intel x86 family) has its own, idiosyncratic maker code i beg your pardon is not compatible through the device code of various other CPU families.

You are watching: When a program is not running, it is stored

What is a Program/App?

*
What is a regimen or App? - e.g. FirefoxFirefox is make of millions of device code indict - Run top to bottom (just prefer Javascript!) - The Firefox window appears (the an initial 1000 instructions) - that menus show up (the following 1000) - The cursor blinks waiting for you to typeThe instructions such that, once run, "Firefox" action happenFirefox.exe is a file in the paper system, 80 MB in dimension (".exe" is a home windows convention for the surname of a routine file)The Firefox.exe file is mostly the bytes of device code instructionsEach accuse is, say, 4 bytes in sizeFirefox.exe in ~ 80 MB is around 20 million device instructionsThe device code specifies a collection of individual instructions. Each machine code indict is incredibly primitive, together as adding two numbers or testing if a number is equal to zero. As soon as stored, each instruction takes up simply a couple of bytes. As soon as we said earlier that a CPU can execute 2 billion operations per second, we intended that the CPU have the right to execute 2 billion lines of maker code per second.A program, such together Firefox, is made up of a succession of numerous these an extremely simple device code instructions. It"s a small hard to think that other as wealthy and complicated as Firefox deserve to be collected out the instructions that just include or compare 2 numbers, but that is how it works. A sand sculpture deserve to be well-off and complicated when regarded from a distance, also though the individual grains of sand are very simple.

How go a program Run?

CPU runs a "fetch/execute cycle" -fetch one accuse in succession -execute (run) that instruction, e.g. Perform the addition -fetch the following instruction, and so onRun a program = start CPU running on its 1st instruction the runs down through every one of the device code, running the program the routine will have actually instructions favor "return to step 3" to save it running Super simple maker code instructions operation at the price of 2 exchange rate per-secondThe CPU operation instructions using a "fetch-execute" cycle: the CPU it s okay the first instruction in the sequence, executes it (adding 2 numbers or whatever), then fetches the next instruction and executes it, and so on. Several of the instructions affect the order that the CPU takes v the instruction sequence. For example, an instruction can direct the CPU come jump ago to one earlier suggest in the instruction sequence (loops are applied this way), or come skip over the next instruction if a certain condition is true (if-statements are implemented this way).CPU operation a series of maker language instructions

How go a regime Start?

The file Firefox.exe contains its instructions (in the record system)To begin Firefox.exe running: -Each routine gets its very own area of lamb -The lamb area stop the program"s code and data the manipulates -The instruction bytes are copied from storage to lamb -The CPU is directed to start running in ~ the an initial instruction -Now the regimen is running!Run Firefox.exe: (1) copy instructions to RAM, (2) CPU operation themIn the document system, a record like Firefox.exe just consists of the bytes that the machine code indict that make up the program (".exe" is a windows convention to mark a paper as a program). Each maker code instruction take away up around 4 bytes, and also whole regime is just an substantial sequence the instructions.When the user double clicks a program record to run it, basically the block of bytes that the instructions because that the routine are copied into RAM, and then the CPU is command to start running in ~ the very first instruction in that area of RAM.

See more: Watch Gotham Season 3 Episode 1 Full Episode Free, Gotham Season 3

What starts Firefox Running? The "Operating System"

What room the procedures to operation Firefox?"Operating System" -e.g. Windows, Linux, Android, iOSOperating system = ManagementSet of supervisory programs that control the computerThe operating system runs when the computer an initial starts upManage the start/stop the programsManage RAMManage persistent storageComputers can run multiple program at the exact same timeOperating system keeps track of the details for every program and also shares sources (like RAM) among the programsThe "operating system" that a computer system is like a first, supervisory regimen that starts running as soon as the computer first starts increase ("boots up"). The operating mechanism plays an invisible administrative and also bookkeeping role behind the scenes. When a laptop or phone starts up, the operation system commonly gets points organized and then launches a "file explorer" regime which displays obtainable programs and menus etc. That present the user what is available, enabling the user to navigate and run programs.The operating mechanism keeps things arranged in the elevator so that multiple programs have the right to run in ~ the very same time, i beg your pardon is well-known as "multitasking". The operation system offers each program its own area of memory, so each program only accesses its very own resources .. Attempting to border what one erroneous or malicious program have the right to do. Maintaining the programs different is sometimes known as "sandboxing" .. Mediating the access of each regime so it operates independently, without interfering with other programs or the system as a whole. Similarly, each program has some accessibility to the display through a window, but this calculation area is separated indigenous the output of various other programs.Recall the a .exe paper or everything is basically just a paper of machine code instructions. As soon as you double-click the program, the operating mechanism "launches" the program, doing the housekeeping actions of allocation an area of storage within lamb for the program, loading the first section the the program"s an equipment code right into that memory, and also finally directing the CPU to start running that code.

The Whole snapshot - Scenarios

Now we have actually the whole photo of a regime running on the hardware. Watch at typical scenarios.Demo: carry up "Activity Monitor" (Mac) "Task Manager" (windows) -See every the programs running -Do something i have lot of money in Firefox, see its CPU % spike -Kill a programoperating mechanism manages cpu, ram, programs, storage

1. Normal Running Programs

Operating system starts and also stops programsEach program has actually its very own separate area in RAM: its accuse + dataCPU "round robin:" CPU operation a couple of instructions indigenous each routine so they every the programs show up to be running simultaneouslyPersistent storage is arranged as a record system, programs have the right to read and also write data here

2. Regime Exits Normally

The regimen exits normally ("Quit" menu item)The operating device stops running that programThe operating device reclaims the program"s area of ram (to be re-used)

3. Regimen Stuck/Infinite Loop - Abnormal Exit

Suppose program gets stuck to run an limitless loop, is "stuck"The operating system stops to run that regime - involuntary vs. Normal-exitThe operating device reclaims the program"s area of RAM

4. Running the end Of Memory

A regimen requests more RAM from the operating mechanism e.g. To hold an image, however there"s not enough RAM availableThe operating mechanism refuses the request, the program provides an error message

5. Memory access Error

A program tries to accessibility the memory of one more programMaybe due to the fact that of a pest (common)Maybe on purpose because it is malwareThe operating mechanism blocks the accessibility (ideally)Maybe death the offending program too

6. Reboot

Why go this fix anything????Sometimes some operating-system regulated bytes in ram is not quite right -a an insect in the operating system, or maybe a hardware errorA reboot wipes all the data native RAMStarts up the operating system freshThis might fix the problemThis must never it is in necessaryBut sometimes it works!The require for reboots is a hallmark of the presence of computers in formerly reliable systems!

Why is it dubbed Reboot?

Chicken and egg problem.. Who runs the operation system?Old phrase: "get end a fence by pulling top top your own bootstraps"When very first powered on, computer system runs a distinct "bootstrap" programThat program frequently looks for persistent storage containing an operating system to runBoot up - startReboot - execute a new shutdown/startup cycle