The Wayback Machine - https://web.archive.org/web/20240813012801/https://www.geeksforgeeks.org/static-and-dynamic-linking-in-operating-systems/
Open In App

Static and Dynamic Linking in Operating Systems

Last Updated : 10 May, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Static Linking: When we click the .exe (executable) file of the program and it starts running, all the necessary contents of the binary file have been loaded into the process’s virtual address space. However, most programs also need to run functions from the system libraries, and these library functions also need to be loaded. In the simplest case, the necessary library functions are embedded directly in the program’s executable binary file. Such a program is statically linked to its libraries, and statically linked executable codes can commence running as soon as they are loaded.

Static linking is performed during the compilation of source program.

Linking is performed before execution in static linking . It takes collection of Realocatable object file and command line arguments and generates a fully linked. 

object file that can be loaded and run. 

 Disadvantage: Every program generated must contain copies of exactly the same common system library functions. In terms of both physical memory and disk-space usage, it is much more efficient to load the system libraries into memory only once. Dynamic linking allows this single loading to happen. 

Dynamic Linking: Every dynamically linked program contains a small, statically linked function that is called when the program starts. This static function only maps the link library into memory and runs the code that the function contains. The link library determines what are all the dynamic libraries which the program requires along with the names of the variables and functions needed from those libraries by reading the information contained in sections of the library. After which it maps the libraries into the middle of virtual memory and resolves the references to the symbols contained in those libraries. We don’t know where in the memory these shared libraries are actually mapped: 

 

They are compiled into position-independent code (PIC), that can run at any address in memory. 

Advantage: Memory requirements of the program are reduced. A DLL is loaded into memory only once, whereas more than one application may use a single DLL at the moment, thus saving memory space. Application support and maintenance costs are also lowered.

Differences between static and dynamic linking in operating systems are:

  Static Linking  Dynamic Linking
 
Definition  The process of combining all necessary library routines and external references into a single executable file at compile-time.  The process of linking external libraries and references at runtime, when the program is loaded or executed.
 
Linking Time  Occurs at compile-time.  Occurs at runtime.
 
File Size  Generally larger file size, as all required libraries are included in the executable.  Smaller file size, as libraries are linked dynamically at runtime.
 
Flexibility  Less flexible, as any updates or changes to the libraries require recompilation and relinking of the entire program.  More flexible, as libraries can be updated or replaced without recompiling the program.
 
Performance  Faster program startup and direct execution, as all libraries are already linked.  Slightly slower program startup due to the additional linking process, but overall performance impact is minimal.
 
Examples  Executables with file extensions like .exe, .elf, .a, .lib, etc.  Executables with file extensions like .dll, .so, .dylib, etc.
 


Similar Reads

Difference between Loading and Linking in Operating System
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 o
4 min read
Static and Dynamic Loader in Operating System
An Operating system is the critical component for managing the various memory resources in the computer system. One of the essential tasks of the operating system is to manage the executable programs or applications in the computer system. A program needs to be loaded into the memory for the purpose of execution. For the execution context, the load
7 min read
Operating Systems | Input Output Systems | Question 5
Which of the following is major part of time taken when accessing data on the disk? (A) Settle time (B) Rotational latency (C) Seek time (D) Waiting time Answer: (C) Explanation: Seek time is time taken by the head to travel to the track of the disk where the data to be accessed is stored.Quiz of this Question
1 min read
Difference between Static and Dynamic Hazard
1. Static Hazard : Static hazard occur in combinational circuits and can be eliminated by using redundant gates. Static hazard is further classified as: 1. Static-1 hazard 2. Static-0 hazard 2. Dynamic hazard : When the output changes several times then it should change from 1 to 0 or 0 to 1 only once, it is called dynamic hazard. Dynamic hazard oc
2 min read
Static and Dynamic Libraries | Set 1
When a C program is compiled, the compiler generates object code. After generating the object code, the compiler also invokes linker. One of the main tasks for linker is to make code of library functions (eg printf(), scanf(), sqrt(), ..etc) available to your program. A linker can accomplish this task in two ways, by copying the code of library fun
4 min read
Difference between Static and Dynamic Routing
Routing is a vital communication mechanism that governs how data packets travel from source to destination. Effective routing ensures that data is transferred across networks in an efficient, reliable, and timely manner. There are two main forms of routing: static and dynamic. In this article, we will discuss the differences between static and dyna
3 min read
Dynamic Host Configuration Protocol (DHCP) vs Static IP Assignment
The two different approaches of network configuration to manage IP addresses for devices are DHCP (Dynamic Host Configuration Protocol) and Static IP Assignment which you can use to configure computer networks and to assign IP addresses to devices on a network are the focus. A distinctive feature of DHCP is the automated assignment of IP addresses
5 min read
Difference Between Static andDynamic Loading in Operating System
An operating system is a program loaded into a system or computer. and manage all the other program which is running on that OS Program, it manages the all other application programs. or in other words, we can say that the OS is an interface between the user and computer hardware. Static Loading in OS In static loading, Initially, the complete prog
5 min read
Fixed (or static) Partitioning in Operating System
Fixed partitioning, also known as static partitioning, is a memory allocation technique used in operating systems to divide the physical memory into fixed-size partitions or regions, each assigned to a specific process or user. Each partition is typically allocated at system boot time and remains dedicated to a specific process until it terminates
6 min read
Process Creation and Deletions in Operating Systems
Prerequisite - States of a Process in Operating Systems There are two basic operations that can be performed on a process: Creation and Deletion. They are explained as Process creation: 1. When a new process is created, the operating system assigns a unique Process Identifier (PID) to it and inserts a new entry in the primary process table. 2. Then
2 min read
three90RightbarBannerImg