How the MS-DOS 6.22 COMMAND /P Switch Works
In MS-DOS 6.22, the /P (Permanent) switch instructs
COMMAND.COM to establish itself as the primary,
non-terminating command processor for the operating system. When this
switch is invoked, the shell disables the internal EXIT
command, triggers the automatic execution of AUTOEXEC.BAT,
and alters its process termination vectors so memory is never
deallocated back to a parent process. By locking the shell into memory
and refusing termination requests, the /P switch prevents
the system from crashing into an unrecoverable state where no command
processor exists.
Suppressing the EXIT Command
Under standard operation, a secondary shell loaded without
/P allows users to return to the parent program or previous
shell instance by typing EXIT. When
COMMAND.COM is invoked with the /P switch, the
command parser explicitly disables or ignores the EXIT
command. If a user enters EXIT at the prompt, the shell
simply redisplays the prompt or takes no action. Because the primary
shell has no parent process to return to, disabling the exit routine
ensures the user cannot accidentally drop out of the interface and cause
a system lockup.
Initialization and AUTOEXEC.BAT Execution
The /P switch signals to COMMAND.COM that
it is acting as the top-level system shell. Upon initialization, the
presence of the /P flag directs the shell to search the
root directory of the boot drive for AUTOEXEC.BAT and
process its batch commands. Secondary instances of
COMMAND.COM loaded without /P skip this step
entirely to avoid re-running boot-time configuration scripts during a
standard user session.
Termination Vectors and Interrupt 22h
In the MS-DOS architecture, when a child process terminates via DOS Interrupt 21h Function 4Ch, control returns to the address specified by Interrupt 22h (the termination address) stored in the child's Program Segment Prefix (PSP).
When COMMAND.COM starts with /P:
- It configures Interrupt 22h to point directly back to its own entry point rather than an external caller.
- If a critical fault or unexpected termination request occurs, the
execution flow loops back into the resident portion of
COMMAND.COMinstead of releasing control to MS-DOS. - It hooks Interrupt 23h (Ctrl+C/Ctrl+Break handler) and Interrupt 24h (Critical Error handler) to ensure that keyboard aborts or hardware I/O errors cannot force the shell process to close.
Resident and Transient Memory Management
COMMAND.COM divides itself into two segments: the
resident portion and the transient portion. The resident portion resides
in low memory, sets up the interrupt vectors, manages process reloading,
and holds the logic for handling permanent execution. The transient
portion resides at the high end of conventional memory and handles
prompt generation and internal command execution.
When loaded with /P, the resident portion remains
permanently anchored in the DOS memory control block (MCB) chain. Even
if a large application overwrites the transient portion in high memory,
the resident portion detects the corruption upon program exit and
automatically reloads the transient code from disk, guaranteeing that
the permanent shell environment remains operational indefinitely.