Hamilton C shell
Encyclopedia
Hamilton C shell is a clone of the Unix C shell
and utilities for Microsoft Windows
created by Nicole Hamilton at Hamilton Laboratories. It was first released on OS/2
on December 12 1988 and on Windows NT
in July 1992. The OS/2 version was discontinued in 2003 but the Windows version continues to be actively supported.
architecture, its use of threads
, and the decision to follow Windows rather than Unix conventions.
simply didn't work. There was a limit to how complex a command it could handle.
By contrast, Hamilton uses a top-down recursive descent parser
that allows it to compile commands and procedures to an internal form before running them. As a result, statements can be nested arbitrarily.
. A subshell is a separate child
copy of the shell that inherits the current state but can then make changes, e.g., to the current directory, without affecting the parent. When the Unix C shell runs a script, it runs it in a subshell. A subshell can also be specified by putting parentheses around a group of statements. Concurrency occurs in pipelines, where all the stages are intended to run concurrently, or when a command is run in the background.
The Unix C shell's implementation of both these features depends on being able to make copies of its entire process state very inexpensively, which in turn depends on the Unix fork
system call, which has access to the hardware. The semantics
of fork are that it creates a child process
which is a duplicate of the caller, differing only in the return value from fork. The parent and child are otherwise identical with duplicate sets of open file descriptor
s, duplicate current directories and duplicate memory images. The memory image, which can be quite large, is duplicated using the hardware page table
and a technique called "copy-on-write
": Initially, parent and child share the same physical pages in memory but all the pages are marked read-only. When one or the other tries to write to a page, a hardware exception
is raised and the Unix kernel
makes a copy of the page, gives the original to one process and the copy to the other and marks them both writable.
But Windows doesn't support a fork primitive under its native Win32 API
(even though it is supported in the kernel for the POSIX subsystem), in part because Windows was conceived as graphical OS and it was unclear what it would mean to fork a graphical application with message queue
s. It's possible to simulate the functionality of fork on Windows at the application layer
, but without access to the hardware page tables, it's awkward and not nearly as performant.
Lacking fork or a performant way to recreate that functionality, Hamilton uses the Windows threads facilities instead. When a new thread is created, it runs within the same process space and it shares all of the process state. If one thread changes the current directory or the contents of memory, it's changed for all the threads. It's much cheaper to create a thread than a process but there's no isolation between them. To recreate the missing isolation of separate processes, the threads cooperate to share resources using locks
.
C shell
The C shell is a Unix shell that was created by Bill Joy while a graduate student at University of California, Berkeley in the late 1970s. It has been distributed widely, beginning with the 2BSD release of the BSD Unix system that Joy began distributing in 1978...
and utilities for Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
created by Nicole Hamilton at Hamilton Laboratories. It was first released on OS/2
OS/2
OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
on December 12 1988 and on Windows NT
Windows NT
Windows NT is a family of operating systems produced by Microsoft, the first version of which was released in July 1993. It was a powerful high-level-language-based, processor-independent, multiprocessing, multiuser operating system with features comparable to Unix. It was intended to complement...
in July 1992. The OS/2 version was discontinued in 2003 but the Windows version continues to be actively supported.
Design
Hamilton C shell differs from the Unix C shell in several respects, its compilerCompiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...
architecture, its use of threads
Thread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
, and the decision to follow Windows rather than Unix conventions.
Compiler
The original C shell used an ad hoc parser and that led to complaints about its limitations. It worked well enough for the kinds of things users typed interactively but not very well on the more complex commands a user might take time to write in a script. Attempting to pipe the output of a foreach statement into grepGrep
grep is a command-line text-search utility originally written for Unix. The name comes from the ed command g/re/p...
simply didn't work. There was a limit to how complex a command it could handle.
By contrast, Hamilton uses a top-down recursive descent parser
Recursive descent parser
A recursive descent parser is a top-down parser built from a set of mutually-recursive procedures where each such procedure usually implements one of the production rules of the grammar...
that allows it to compile commands and procedures to an internal form before running them. As a result, statements can be nested arbitrarily.
Threads
The Unix C shell supports subshells and concurrencyConcurrency (computer science)
In computer science, concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other...
. A subshell is a separate child
Child process
A child process in computing is a process created by another process .A child process inherits most of its attributes, such as open files, from its parent. In UNIX, a child process is in fact created as a copy of the parent...
copy of the shell that inherits the current state but can then make changes, e.g., to the current directory, without affecting the parent. When the Unix C shell runs a script, it runs it in a subshell. A subshell can also be specified by putting parentheses around a group of statements. Concurrency occurs in pipelines, where all the stages are intended to run concurrently, or when a command is run in the background.
The Unix C shell's implementation of both these features depends on being able to make copies of its entire process state very inexpensively, which in turn depends on the Unix fork
Fork (operating system)
In computing, when a process forks, it creates a copy of itself. More generally, a fork in a multithreading environment means that a thread of execution is duplicated, creating a child thread from the parent thread....
system call, which has access to the hardware. The semantics
Semantics
Semantics is the study of meaning. It focuses on the relation between signifiers, such as words, phrases, signs and symbols, and what they stand for, their denotata....
of fork are that it creates a child process
Child process
A child process in computing is a process created by another process .A child process inherits most of its attributes, such as open files, from its parent. In UNIX, a child process is in fact created as a copy of the parent...
which is a duplicate of the caller, differing only in the return value from fork. The parent and child are otherwise identical with duplicate sets of open file descriptor
File descriptor
In computer programming, a file descriptor is an abstract indicator for accessing a file. The term is generally used in POSIX operating systems...
s, duplicate current directories and duplicate memory images. The memory image, which can be quite large, is duplicated using the hardware page table
Page table
A page table is the data structure used by a virtual memory system in a computer operating system to store the mapping between virtual addresses and physical addresses. Virtual addresses are those unique to the accessing process...
and a technique called "copy-on-write
Copy-on-write
Copy-on-write is an optimization strategy used in computer programming. The fundamental idea is that if multiple callers ask for resources which are initially indistinguishable, they can all be given pointers to the same resource...
": Initially, parent and child share the same physical pages in memory but all the pages are marked read-only. When one or the other tries to write to a page, a hardware exception
Interrupt
In computing, an interrupt is an asynchronous signal indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
is raised and the Unix kernel
Kernel (computing)
In computing, the kernel is the main component of most computer operating systems; it is a bridge between applications and the actual data processing done at the hardware level. The kernel's responsibilities include managing the system's resources...
makes a copy of the page, gives the original to one process and the copy to the other and marks them both writable.
But Windows doesn't support a fork primitive under its native Win32 API
Windows API
The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces available in the Microsoft Windows operating systems. It was formerly called the Win32 API; however, the name "Windows API" more accurately reflects its roots in 16-bit Windows and its support on...
(even though it is supported in the kernel for the POSIX subsystem), in part because Windows was conceived as graphical OS and it was unclear what it would mean to fork a graphical application with message queue
Message queue
In computer science, message queues and mailboxes are software-engineering components used for interprocess communication, or for inter-thread communication within the same process. They use a queue for messaging – the passing of control or of content...
s. It's possible to simulate the functionality of fork on Windows at the application layer
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
, but without access to the hardware page tables, it's awkward and not nearly as performant.
Lacking fork or a performant way to recreate that functionality, Hamilton uses the Windows threads facilities instead. When a new thread is created, it runs within the same process space and it shares all of the process state. If one thread changes the current directory or the contents of memory, it's changed for all the threads. It's much cheaper to create a thread than a process but there's no isolation between them. To recreate the missing isolation of separate processes, the threads cooperate to share resources using locks
Lock (computer science)
In computer science, a lock is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution. Locks are one way of enforcing concurrency control policies.-Types:...
.