Misplaced Pages

Hamilton C shell

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

This is an old revision of this page, as edited by Msnicki (talk | contribs) at 16:52, 8 April 2013 (Replace broken link for the Software QA Magazine article that's disappeared from the web with a link to a snapshot at archive.org.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Revision as of 16:52, 8 April 2013 by Msnicki (talk | contribs) (Replace broken link for the Software QA Magazine article that's disappeared from the web with a link to a snapshot at archive.org.)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Hamilton C shell
File:HamiltonCshellx64onWindows7.png64-bit Hamilton C shell on a Windows 7 desktop.
Original author(s)Nicole Hamilton
Initial releaseDec 12 1988 (Dec 12 1988)
Stable release5.1 / August 30, 2012; 12 years ago (2012-08-30)
Written inC
Operating systemWindows
TypeUnix Shell on Windows
LicenseHamilton Laboratories EULA
Websitehttp://www.hamiltonlabs.com/Cshell.htm

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.

Design

Hamilton C shell differs from the Unix C shell in several respects, its compiler architecture, its use of threads, and the decision to follow Windows rather than Unix conventions.

Compiler

Hamilton C shell and Cygwin bash on Windows 7, showing the use of recursion for factoring.

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 grep 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.

Threads

Hamilton C shell and Cygwin bash date loops.

The Unix C shell supports subshells and concurrency. 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 descriptors, 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 queues. 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.

Windows Conventions

Finally, Hamilton differs from other Unix shells in that it follows Windows conventions instead of Unix conventions for filename slashes, escape characters, etc.

References

  1. ^ Early Hamilton C shell Quick Reference (PDF). Hamilton Laboratories, Wayland, MA. Jul 10 1990. Retrieved Nov 22 2010. {{cite book}}: Check date values in: |accessdate= and |date= (help)
  2. Faught, Danny (Aug 31 1996). "The shell game". Software QA Magazine. 3 (4). Retrieved Apr 8 2013. {{cite journal}}: Check date values in: |accessdate= and |date= (help)
  3. The author has discussed her transition from Douglas Hamilton on a panel discussion at Stanford, beginning at 29:37. Nicole Hamilton, Carl Ingram, Liz Kennedy Myers, Tom Mills, John Ordway, Scott Thatcher, Kirstie Wilde (Moderator) (Nov 28 2007). Class of 1972 Panel Discussion: Hell No We Won't Go (Quietly Into the Night)!. Stanford Alumni Association, iTunes U. Retrieved Nov 23 2010. {{cite AV media}}: Check date values in: |accessdate= and |date= (help)
  4. Machlis, Sharon. "Wayland writer for IBM" (PDF). Middlesex News (Dec 18 1988): 2E. Retrieved Nov 22 2010. {{cite journal}}: Check date values in: |accessdate= (help)
  5. Sussman, Ann. "Hamilton C Shell Speeds Development Of OS/2 Applications" (PDF). PC Week (Dec 26 1988 - Jan 2 1989): 37. Retrieved Nov 22 2010. {{cite journal}}: Check date values in: |accessdate= (help)
  6. ^ Hamilton, Douglas A. "Hamilton C shell Announcement" (PDF). IBM Personal Systems Developer (Summer 1989): 119–121. Retrieved Nov 22 2010. {{cite journal}}: Check date values in: |accessdate= (help)
  7. Richman, Scott (Jan 1991). "Examining the Hamilton C Shell" (PDF). Dr. Dobb's Journal. Retrieved Nov 22 2010. {{cite journal}}: Check date values in: |accessdate= (help)
  8. ^ Goutal, Kenneth G. "The Hamilton C shell" (PDF). MIPS Magazine (Sep 1989). Retrieved Nov 22 2010. {{cite journal}}: Check date values in: |accessdate= (help)
  9. ^ Yager, Tom. "OS/2, Unix Style" (PDF). BYTE Magazine (Feb 1990). Retrieved Nov 22 2010. {{cite journal}}: Check date values in: |accessdate= (help)
  10. Hamilton C shell for Windows Release Notes 4.0, retrieved June 19, 2010.
  11. Hamilton, Doug (Jul 27 1995). "Looking for C-Shell on NT". Newsgroupcomp.os.ms-windows.nt.misc. hamilton.806823765@BIX.com. Retrieved Oct 8 2010. {{cite newsgroup}}: Check date values in: |accessdate= and |date= (help)
  12. Deignan, Michael P. (Apr 01 1998). "Hamilton C Shell". Windows IT PRo. Retrieved Mar 23 2013. {{cite journal}}: Check date values in: |accessdate= and |date= (help)
  13. Csh Programming Considered Harmful by Tom Christiansen
  14. Hamilton, Douglas A. (Jan 9 1997). "Why doesn't OS/2 have fork()?". Newsgroupcomp.os.os2.programmer.misc. Retrieved Oct 8 2010. {{cite newsgroup}}: Check date values in: |accessdate= and |date= (help)
  15. Hamilton, Doug (Feb 6 1994). "fork() on NT! or info on porting Unix apps to NT". Newsgroupcomp.os.ms-windows.nt.misc. Retrieved Oct 8 2010. {{cite newsgroup}}: Check date values in: |accessdate= and |date= (help)
  16. "Cygwin FAQ: How is fork() implemented?". Retrieved Oct 10 2010. {{cite web}}: Check date values in: |accessdate= (help)
  17. "Highlights of Cygwin Functionality: Process Creation". Retrieved Oct 10 2010. {{cite web}}: Check date values in: |accessdate= (help)
  18. Blake, Eric (Jan 15 2009). "Bash doesn't launch the applications directly". Cygwin project (Mailing list). Retrieved Oct 10 2010. {{cite mailing list}}: Check date values in: |accessdate= and |date= (help); Unknown parameter |mailinglist= ignored (|mailing-list= suggested) (help)
  19. Hamilton, Doug (Apr 21 1995). "Suggestions for multiple-reader/single-writer lock?". Newsgroupcomp.os.ms-windows.nt.misc. hamilton.798430053@BIX.com. Retrieved Oct 8 2010. {{cite newsgroup}}: Check date values in: |accessdate= and |date= (help)

External links

Unix shells
Categories: