Chapter 8 of 14
Where does a program live?
A copy of Echo is on disk. There is also an Echo in the running system’s module directory. Its instructions can serve one shell and then another. Each invocation still needs its own arguments, writable storage and stack.
Read a module’s identity
ident /dd/cmds/echo
mdir
ident examines the named disk file. In the supplied edition, look for the name Echo, size $0022 (34 bytes), execution offset $0012 and a good module CRC. Offset $0012 means the first instruction is 18 bytes from the start of the module. The header tells the loader where to begin. The CRC checks the module’s bytes against the check value recorded in the file.
mdir lists modules currently known to the kernel. The prepared boot loads a group of frequently used utilities, so Echo is already there. A file may contain several modules, each with its own header, name and entry in memory. A module can also be a file manager, driver or device descriptor. A name present in mdir alone tells you little about whether that name makes sense at a command prompt.
Count references you create yourself
Use a fresh practice boot with no other job using Cmp. Here Cmp is the small file-comparison program. Use the lowercase letters mp in the filter to match the ending of Cmp as it is printed.
load cmp
mdir -e ! grep mp
link cmp
mdir -e ! grep mp
unlink cmp
mdir -e ! grep mp
unlink cmp
mdir -e ! grep mp
Read the last number before the name. The four checks on our guest gave 1, 2, 1, and finally no Cmp row.
load brought the program from the execution directory into memory and retained a reference. link found that named module in memory and retained a second reference. Each unlink released one. The disk file remains available after the module leaves memory. If other processes have acquired the module, their references also count. Release only the references you created. For boot modules, keep the system’s existing references intact.