ArticleslgStudy

computer science

Chain loading

Chain loading is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Chain loading rather than just read about it. In short: Chain loading is a method used by computer programs to replace the currently executing program with a new program, using a common data area to pass information from the current program to the new program. It occurs in several areas of computing.

Key takeaways

  • Chain loading belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Chain loading to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Chain loading from memory before moving on to harder problems.

Reference excerpt

Chain loading is a method used by computer programs to replace the currently executing program with a new program, using a common data area to pass information from the current program to the new program. It occurs in several areas of computing. Chain loading is similar to the use of overlays. Unlike overlays, however, chain loading replaces the currently executing program in its entirety. Overlays usually replace only a portion of the running program. Like the use of overlays, the use of chain loading increases the I/O load of an application.

Chain loading in boot manager programs In operating system boot manager programs, chain loading is used to pass control from the boot manager to a boot sector. The target boot sector is loaded in from disk, replacing the in-memory boot sector from which the boot manager itself was bootstrapped, and executed.

Chain loading in Unix In Unix (and in Unix-like operating systems), the exec() system call is used to perform chain loading. The program image of the current process is replaced with an entirely new image, and the current thread begins execution of that image. The common data area comprises the process' environment variables, which are preserved across the system call.

Chain loading in Linux In addition to the exec() process level chain loading Linux supports the kexec() system call to replace the entire operating system kernel with a different version. The new kernel boots as if it were started from power up and no running processes are preserved.

Chain loading in BASIC programs In BASIC programs, chain loading is the purview of the CHAIN statement (or, in Commodore BASIC, the LOAD statement), which causes the current program to be terminated and the chained-to program to be loaded and invoked (with, on those dialects of BASIC that support it, an optional parameter specifying the line number from which execution is to commence, rather than the default of the first line of the new program). The common data area varies according to the particular dialect of BASIC that is in use. On BBC BASIC, for example, only a specific subset of all variables are preserved across a CHAIN. On other BASICs, the COM statement can be used in conjunction with CHAIN to specify which variables are to be preserved as common data across a chain operation. Chain loading permits BASIC programs to execute more program code than could fit into available program and variable memory. Applications written in BASIC could thus be far larger than the size of working memory, via a set of cooperating programs that CHAIN back and forth amongst themselves as program flow moves within the overall application.

Chain loading in FORTRAN programs Many versions of Fortran include a CALL CHAIN or CALL LINK statement that performs chain loading, preserving the contents of COMMON storage. This is not the same as the unrelated LINK subroutine in GNU Fortran.

Chain loading in OS/360 OS/360 and successors use the XCTL (for "transfer control") macro for chain loading. Because of the operating system's memory management this may or may not result in replacement of the code of the calling program in memory.

See also CHAIN (CONFIG.SYS directive) (chain executing multiple CONFIG.SYS files in DR-DOS)

References

"chain loading". GNU GRUB manual. Orlando Lee Stevenson (December 1985). "Commodore Program Chaining". Compute! (67): 114. Raymond, Eric Steven. "Multiprogramming: Taxonomy of Unix IPC Methods: Wrappers and Bernstein Chaining". The Art of Unix Programming.

Worked examples

Example 1 — a first encounter with Chain loading

Start with the simplest possible case. Write down what Chain loading claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Chain loading before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Chain loading ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Chain loading

In research
Chain loading appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Chain loading in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Chain loading is common in secondary-school and first-year university syllabi. It links to neighbouring topics Operating system technology, Process (computing), so understanding it makes those chapters shorter.
In everyday life
Look for Chain loading outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Chain loading” →

How to study Chain loading in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Chain loading means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Chain loading out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Chain loading in simple terms?

Chain loading is a method used by computer programs to replace the currently executing program with a new program, using a common data area to pass information from the current program to the new program. It occurs in several areas of computing.

Why does Chain loading matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Chain loading?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Chain loading.

Tags

  • Operating system technology
  • Process (computing)

Keep exploring