Jump to content

Execution (computing)

From Wikipedia, the free encyclopedia

Executionincomputerand software engineering is the process by which acomputerorvirtual machineinterprets and acts on the instructions of acomputer program.Each instruction of a program is a description of a particular action which must be carried out, in order for a specific problem to be solved. Execution involves repeatedly following a "fetch–decode–execute"cycle for each instruction done by thecontrol unit.As the executing machine follows the instructions, specific effects are produced in accordance with thesemanticsof those instructions.

Programs for a computer may be executed in abatch processwithout human interaction or ausermay typecommandsin aninteractive sessionof aninterpreter.In this case, the "commands" are simply program instructions, whose execution is chained together.

The termrunis used almost synonymously. A related meaning of both "to run" and "to execute" refers to the specific action of a user starting (orlaunchingorinvoking) a program, as in "Please run the application."

Process[edit]

Prior to execution, a program must first be written. This is generally done insource code,which is then compiled atcompile time(and statically linked atlink time) to produce an executable. This executable is then invoked, most often by an operating system, which loads the program into memory (load time), possibly performsdynamic linking,and then begins execution by moving control to theentry pointof the program; all these steps depend on theApplication Binary Interfaceof the operating system. At this point execution begins and the program entersrun time.The program then runs until it ends, either in a normalterminationor acrash.

Executable[edit]

Executable code,anexecutable file,or anexecutable program,sometimes simply referred to as anexecutableor binary,is a list of instructions and data to cause a computer "to perform indicated tasks according to encodedinstructions",[1]as opposed to adata filethat must be interpreted (parsed) by a program to be meaningful.

The exact interpretation depends upon the use. "Instructions" is traditionally taken to meanmachine codeinstructions for a physicalCPU.[2]In some contexts, a file containing scripting instructions (such asbytecode) may also be considered executable.

Context of execution[edit]

The context in which execution takes place is crucial. Very few programs execute on abare machine.Programs usually contain implicit and explicit assumptions about resources available at the time of execution. Most programs execute withinmultitaskingoperating systemandrun-time librariesspecific to the source language that provide crucial services not supplied directly by the computer itself. This supportive environment, for instance, usually decouples a program from direct manipulation of the computer peripherals, providing more general, abstract services instead.

Context switching[edit]

In order for programs andinterrupt handlersto work without interference and share the same hardware memory and access to the I/O system, in amultitasking operating systemsrunning on a digital system with a single CPU/MCU it is required to have some sort of software and hardware facilities to keep track of an executing processes data (memory page addresses, registers etc.) and to save and recover them back to the state they were in before they were suspended. This is achieved by a context switching.[3]: 3.3 [4]The running programs are often assigned aProcess Context IDentifiers(PCID).

In Linux-based operating systems, a set of data stored inregistersis usually saved into a process descriptor in memory to implement switching of context.[3]PCIDs are also used.

Runtime[edit]

Runtime,run time,orexecution timeis the final phase of acomputer program'slife cycle,in which the code is being executed on the computer'scentral processing unit(CPU) asmachine code.In other words, "runtime" is the running phase of a program.

Aruntime error is detectedafter or during the execution (running state) of a program, whereas acompile-timeerror is detected by thecompilerbefore the program is ever executed.Type checking,register allocation,code generation,and code optimization are typically done at compile time, but may be done at runtime depending on the particular language and compiler. Many other runtime errors exist and are handled differently by differentprogramming languages,such asdivision by zeroerrors, domain errors,array subscript out of boundserrors,arithmetic underflowerrors, several types of underflow andoverflowerrors, and many other runtime errors generally considered as software bugs which may or may not be caught and handled by any particular computer language.

Implementation details[edit]

When a program is to be executed, aloaderfirst performs the necessarymemorysetup and links the program with anydynamically linkedlibrariesit needs, and then the execution begins starting from the program'sentry point.In some cases, a language or implementation will have these tasks done by the language runtime instead, though this is unusual in mainstream languages on common consumer operating systems.

Some program debugging can only be performed (or is more efficient or accurate when performed) at runtime.Logic errorsandarraybounds checking are examples. For this reason, some programmingbugsare not discovered until the program is tested in aproduction environmentwith real data, despite sophisticated compile-time checking and pre-release testing. In this case, the end-user may encounter a "runtime error" message.

Application errors (exceptions)[edit]

Exception handlingis one language feature designed to handle runtime errors, providing a structured way to catch completely unexpected situations as well as predictable errors or unusual results without the amount of inline error checking required of languages without it. More recent advancements in runtime engines enableautomated exception handlingwhich provides "root-cause" debug information for every exception of interest and is implemented independent of the source code, by attaching a special software product to the runtime engine.

Runtime system[edit]

Aruntime system,also calledruntime environment,primarily implements portions of anexecution model.[clarification needed]This is not to be confused with theruntimelifecycle phase of a program, during which the runtime system is in operation. When treating theruntime systemas distinct from theruntime environment(RTE), the first may be defined as a specific part of theapplication software (IDE) used for programming,a piece of software that provides the programmer a more convenient environment for running programs during their production (testingand similar), while the second (RTE) would be the veryinstanceof an execution model being applied to the developed program which is itself then run in the aforementionedruntime system.

Mostprogramming languageshave some form of runtime system that provides an environment in which programs run. This environment may address a number of issues including themanagementof applicationmemory,how the program accessesvariables,mechanisms for passing parameters betweenprocedures,interfacing with theoperating system,and otherwise. Thecompilermakes assumptions depending on the specific runtime system to generate correct code. Typically the runtime system will have some responsibility for setting up and managing thestackandheap,and may include features such asgarbage collection,threadsor otherdynamicfeatures built into the language.[5]

Instruction cycle[edit]

Theinstruction cycle(also known as thefetch–decode–execute cycle,or simply thefetch-execute cycle) is the cycle that thecentral processing unit(CPU) follows fromboot-upuntil the computer has shut down in order to process instructions. It is composed of three main stages: the fetch stage, the decode stage, and the execute stage.

This is a simple diagram illustrating the individual stages of the fetch-decode-execute cycle.

In simpler CPUs, the instruction cycle is executed sequentially, each instruction being processed before the next one is started. In most modern CPUs, the instruction cycles are instead executedconcurrently,and often inparallel,through aninstruction pipeline:the next instruction starts being processed before the previous instruction has finished, which is possible because the cycle is broken up into separate steps.[6]

Interpreter[edit]

A system that executes a program is called aninterpreterof the program. Loosely speaking, an interpreter directly executes a program. This contrasts with a languagetranslatorthat converts a program from one language to another before it is executed.

Virtual machine[edit]

Avirtual machine(VM) is thevirtualization/emulationof acomputer system.Virtual machines are based oncomputer architecturesand provide functionality of a physical computer. Their implementations may involve specialized hardware, software, or a combination.

Virtual machines differ and are organized by their function, shown here:

Some virtual machine emulators, such asQEMUandvideo game console emulators,are designed to also emulate (or "virtually imitate" ) different system architectures thus allowing execution of software applications and operating systems written for anotherCPUor architecture.OS-level virtualizationallows the resources of a computer to be partitioned via thekernel.The terms are not universally interchangeable.

See also[edit]

References[edit]

  1. ^"executable".Merriam-Webster's Online Dictionary.Merriam-Webster.Retrieved2008-07-19.
  2. ^"Machine Instructions".GeeksforGeeks.2015-11-03.Retrieved2019-09-18.
  3. ^abBovet, Daniel P. (2005).Understanding the Linux Kernel.Marco Cesati (3 ed.). Sevastopol, CA: O'Reilly.ISBN0-596-00565-2.OCLC64549743.
  4. ^"Difference between Swapping and Context Switching".GeeksforGeeks.2021-06-10.Retrieved2022-08-10.
  5. ^Aho, Alfred V.;Lam, Monica Sin-Ling;Sethi, Ravi;Ullman, Jeffrey David(2007).Compilers: Principles, Techniques and Tools(2nd ed.). Boston, MA, US:Pearson Education.p.427.ISBN978-0-321-48681-3.
  6. ^Crystal Chen, Greg Novick and Kirk Shimano (2000)."Pipelining".Retrieved2019-06-26.