How an Operating System Loads and Executes a Program

Programming Concepts

In this article, we go over how an operating system loads and executes a program.

Before a program can run, the program must be loaded into memory by a utility known as a program loader.

After loading, the operating system must point the CPU to the program's entry point, which is the address at which the program is to begin execution.

Below is a list of the steps of the process.

  • The operating system seraches for the program's filename in the current disk directory. If it cannot find the name there, it searches a predetermined list of directories (called paths) for th efilename. If the OS fiails to find the program filename, it issues an error message.
  • If the program file is found, the OS retrieves the basic information about the program's file from the disk directory, including the file size and its physical location on the disk drive.
  • The OS determines the next available location in memory and loads the program file into memory. It allocates a block of memory to the program and enters information about the program's size and location into a table (sometimes called a descriptor table). Additionally, the OS may adjust the valus of pointers within the program so they contain addresses of program data.
  • The OS begins execution of the program's first machine instruction (its entry point).As soon as the program begins running, it is called a process. The OS assigns the process an identification number (process ID), which is used to keep track of it while running.
  • The process runs by itself. It is the OS's job to track the execution of the process and to respond to requests for system resources.
  • When the process ends, it is removed from memory

Related Resources

How to Set Bits of a Number in C

How to Clear Bits of a Number in C

HTML Comment Box is loading comments...