Show understanding of program libraries

5.1 Operating Systems – Program Libraries

5.1.1 Why an Operating System Is Required

An operating system (OS) sits between the hardware and the applications. It hides the complexity of the hardware and provides a set of essential services that every program needs.

  • Process management – creation, scheduling and termination of processes.
  • Memory management – allocation, protection, paging/segmentation and virtual‑memory support.
  • File‑system management – organising, storing and retrieving data on disks.
  • Device (hardware) management – abstracting keyboards, displays, disks, printers, etc.
  • Security & protection – authentication, access‑control lists, audit logs and firewalls.

5.1.2 Core OS Management Functions (Syllabus Requirement 5.1)

Process Management

  • Process states – New, Ready, Running, Waiting (Blocked), Terminated.
  • Scheduling algorithms – the OS decides which Ready process gets the CPU.
AlgorithmKey IdeaTypical Use
FCFS (First‑Come‑First‑Served)Run processes in the order they arrive.Simple batch systems.
SJF (Shortest Job First)Run the process with the smallest CPU burst next.Minimises average waiting time (non‑pre‑emptive).
RR (Round‑Robin)Give each Ready process a fixed time‑slice (quantum) in turn.Time‑sharing / interactive systems.
Priority‑basedHigher‑priority processes are chosen before lower‑priority ones.Real‑time or mixed‑criticality environments.

Memory Management

  • Virtual memory – each process sees a large, contiguous address space that may be larger than physical RAM.
  • Pages are moved between RAM and secondary storage (swap space) on demand (page faults).
  • Page‑replacement policies decide which page to evict when a new page must be loaded:
    • FIFO – first‑in, first‑out.
    • LRU – least recently used.
    • Optimal (theoretical) – evicts the page that will not be used for the longest time.

File‑System Management

  • Hierarchical directory structure (folders, sub‑folders).
  • File attributes – name, size, timestamps, permissions.
  • Common operations – create, open, read, write, close, delete.

Device Management

  • Device drivers translate generic OS requests into hardware‑specific actions.
  • Uniform I/O interface (e.g., read/write system calls) works for disks, keyboards, mice, network cards, etc.

Security & Protection

  • Authentication – verifying user identity (passwords, biometrics).
  • Access‑control lists (ACLs) – specify which users or groups may read/write/execute a file.
  • Audit logs – record security‑relevant events for later review.
  • Firewalls and sandboxing – limit network traffic and isolate applications.

5.1.3 Utility Software Supplied with the OS

Beyond the kernel, most operating systems provide a suite of utility programmes that help users and administrators manage the system.

  • Disk formatter / partitioner – prepares storage media for use.
  • File manager / explorer – graphical or command‑line interface to the file system.
  • Virus / malware scanner – checks files for known threats.
  • System monitor (Task Manager, top) – displays running processes and resource usage.

5.1.4 What Is a Program Library?

A program library is a collection of pre‑compiled routines (functions, procedures, classes) that can be called by many different programs. Libraries give developers:

  • Reusable code – avoid rewriting common functionality.
  • Encapsulation – hide implementation details behind a simple interface.
  • Faster development – concentrate on the unique parts of an application.

5.1.5 Types of Program Libraries

  • Static libraries – linked into the executable at compile time; the code becomes part of the final program file.
  • Dynamic (shared) libraries – linked at run‑time; a single copy can be shared by many processes.
  • Import libraries – small stub files that describe the symbols in a dynamic library for the linker.

Dynamic libraries are loaded by the OS loader when the program starts, whereas static libraries are incorporated before the loader ever sees the executable.

5.1.6 Static vs Dynamic Linking – Comparison

Aspect Static Linking Dynamic Linking
When linking occurs During compilation (build time) At program start‑up or on‑demand (run‑time)
Executable size Larger – library code is copied into each executable Smaller – only references to the shared object are stored
Memory usage Each process has its own copy of the library code All processes can share a single copy in RAM
Update / patching Requires recompilation of every program that uses the library Replacing the shared library automatically updates every program that loads it
Portability Executable is self‑contained – easier to move between systems Depends on the correct version of the shared library being present on the target system
Typical file extensions .a (Unix), .lib (Windows) .so (Unix/Linux), .dll (Windows)

5.1.7 How Dynamic Linking Works

When a program that uses a dynamic library is started, the OS loader performs these steps:

  1. Read the executable’s import table to discover which shared objects are required.
  2. Search the system’s library path (e.g., /lib, /usr/lib, PATH) for the required .so or .dll files.
  3. Map the shared object into the process’s address space (typically with mmap on Unix‑like systems).
  4. Resolve symbols – the loader patches the program so that calls to library functions jump to the correct memory addresses.
  5. If the library itself depends on other libraries, repeat the process recursively.

5.1.8 Versioning and Compatibility

Dynamic libraries usually follow semantic versioning to signal API compatibility:

  • Major version – incompatible API changes.
  • Minor version – backward‑compatible additions.
  • Patch version – bug‑fix releases only.

Operating systems can keep several versions of a library side‑by‑side, allowing older programs to continue using the version they were built against.

5.1.9 Common Examples of Program Libraries

  • C Standard Library (libc)printf, malloc, string handling, etc.
  • Java Standard API – packages such as java.util, java.io packaged in rt.jar.
  • .NET Framework Class Library (FCL) – classes in assemblies like System.dll.
  • POSIX Threads Library (pthread) – functions for creating and managing threads.
  • OpenGL / DirectX – graphics rendering libraries that rely on OS video‑driver services.

5.1.10 Advantages of Using Libraries

  • Code reuse reduces development time and the chance of errors.
  • Complex functionality is encapsulated behind simple interfaces.
  • Centralised maintenance – fixing a bug in the library benefits all dependent programs.
  • Memory efficiency when shared libraries are used.

5.1.11 Disadvantages and Risks

  • Version conflicts can lead to “DLL hell” or “dependency hell”.
  • A compromised shared library can affect many applications (security risk).
  • Dynamic linking adds a start‑up overhead while the loader resolves symbols.
  • Static linking inflates executable size, which may be unsuitable for embedded systems.

5.1.12 Sample Calculation – Memory Savings with Shared Libraries

Assume each process needs 2 MB of library code. If 10 processes run simultaneously:

Static linking total memory:

$$\text{Static total memory}=10\times2\text{ MB}=20\text{ MB}$$

Dynamic linking total memory (one shared copy + process‑specific data):

$$\text{Dynamic total memory}=2\text{ MB (shared)}+10\times\text{(process‑specific data)}$$

Thus, the shared approach can save up to 18 MB of RAM in this scenario.

Suggested diagram: Flowchart of the dynamic linking process from program start‑up to symbol resolution.

5.1.13 Key Points to Remember

  • A program library is a reusable collection of compiled code.
  • Static linking incorporates the library into the executable; dynamic linking loads it at run‑time.
  • Dynamic libraries reduce memory usage and simplify updates, but they introduce version‑dependency issues.
  • Understanding the OS loader’s role is essential for diagnosing linking problems.
  • Core OS management tasks (process scheduling, virtual memory, file systems, device drivers and security) provide the services on which libraries rely.

Create an account or Login to take a Quiz

90 views
0 improvement suggestions

Log in to suggest improvements to this note.