Open In App

Difference between Loading and Linking in Operating System

Improve
Improve
Like Article
Like
Save
Share
Report

An operating system acts as an intermediary between the user of a computer and computer hardware. The purpose of an operating system is to provide an environment in which a user can execute programs conveniently and efficiently.

Linking and Loading are utility programs that play an important role in the execution of a program. Linking intakes the object codes generated by the assembler and combines them to generate the executable module. On the other hand, the loading loads this executable module to the main memory for execution. 

What is Loading?

To bring the program from secondary memory to main memory is called Loading. It is performed by a loader.  It is a special program that takes the input of executable files from the linker, loads it to the main memory, and prepares this code for execution by a computer. There are two types of loading in the operating system:

  • Static Loading:
    • Loading the entire program into the main memory before the start of the program execution is called static loading.
    • If static loading is used then accordingly static linking is applied.
  • Dynamic Loading: 
    • Loading the program into the main memory on demand is called dynamic loading.
    • If dynamic loading is used then accordingly dynamic linking is applied.

What is Linking?

Establishing the linking between all the modules or all the functions of the program in order to continue the program execution is called linking. Linking is a process of collecting and maintaining pieces of code and data into a single file. Linker also links a particular module into the system library. It takes object modules from the assembler as input and forms an executable file as output for the loader. Linking is performed at both compile time when the source code is translated into machine code, and load time, when the program is loaded into memory by the loader. Linking is performed at the last step in compiling a program.

  • Static Linking: 
    • A statically linked program takes constant load time every time it is loaded into the memory for execution.
    • Static linking is performed by programs called linkers as the last step in compiling a program. Linkers are also called link editors.
    • In static linking, if any of the external programs has changed then they have to be recompiled and re-linked again else the changes won’t reflect in the existing executable file.
  • Dynamic Linking:
    • Dynamic linking is performed at run time by the operating system.
    • In dynamic linking, this is not the case and individual shared modules can be updated and recompiled. This is one of the greatest advantages dynamic linking offers.
    • In dynamic linking load time might be reduced if the shared library code is already present in memory.

For more information please refer to the Static and Dynamic Linking in Operating Systems article.

Loading and Linking in Operating System

 

Differences between Linking and Loading

Linking

Loading

The process of collecting and maintaining pieces of code and data into a single file is known as Linking in the operating system. Loading is the process of loading the program from secondary memory to the main memory for execution.
Linking is used to join all the modules. Loading is used to allocate the address to all executable files and this task is done by the loader.
Linking is performed with the help of Linker. In an operating system, Linker is a program that helps to link object modules of a program into a single object file. It is also called a link editor. A loader is a program that places programs into memory and prepares them for execution.
Linkers are an important part of the software development process because they enable separate compilation. Apart from that organizing a large application as one monolithic source file, we can decompose it into smaller, more
manageable modules that can be modified and compiled separately.
The loader is responsible for the allocation, linking, relocation, and loading of the operating system.

Last Updated : 22 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads