Lions' Commentary on UNIX 6th Edition, with Source Code


Lions' Commentary on UNIX 6th Edition, with Source Code by John Lions contains source code of the 6th Edition Unix kernel plus a commentary. It is commonly referred to as the Lions Book. Despite its age, it is still considered an excellent commentary on simple but high quality code.
For many years, the Lions book was the only Unix kernel documentation available outside Bell Labs. Although the license of 6th Edition allowed classroom use of the source code, the license of 7th Edition specifically excluded such use, so the book spread through illegal copy machine reproductions. It was commonly held to be the most copied book in computer science.
The book was reprinted in 1996 by Peer-To-Peer Communications.

Synopsis

Unix Operating System Source Code Level Six is the kernel source code, lightly edited by Lions to better separate the functionality — system initialization and process management, interrupts and system calls, basic I/O, file systems and pipes and character devices. All procedures and symbols are listed alphabetically with a cross reference.
The code as presented will run on a PDP-11/40 with RK-05 disk drive, LP-11 line printer interface, PCL-11 paper tape writer and KL-11 terminal interface, or a suitable PDP-11 emulator, such as SIMH.
A Commentary on the Unix Operating System starts with notes on Unix and other useful documentation, a section on the architecture of the PDP-11 and a chapter on how to read C programs. The source commentary follows, divided into the same sections as the code. The book ends with suggested exercises for the student.
As Lions explains, this commentary supplements the comments in the source. It is possible to understand the code without the extra commentary, and the reader is advised to do so and only read the notes as needed. The commentary also remarks on how the code might be improved.

History

The source code and commentary were originally produced in May 1976 as a set of lecture notes for Lions's computer science courses at the University of New South Wales Department of Computer Science.
UNIX News March 1977 announced the availability of the book to Unix licensees. Lions had trouble keeping up with its popularity, and by 1978 it was available only from Bell Labs.
When AT&T announced Unix Version 7 at USENIX in June 1979, the academic/research license no longer automatically permitted classroom use. Thus, licensees were no longer able to use the Lions notes for classes on operating systems.
However, thousands of computer science students around the world spread photocopies. As they could not study it legally in class, they would sometimes meet after hours to discuss the book. Many pioneers of Unix and open source had a treasured multiple-generation photocopy.
Other follow-on effects of the license change included Andrew S. Tanenbaum creating Minix. As Tanenbaum wrote in Operating Systems :
Various Unix people, particularly Peter H. Salus, Dennis Ritchie and Berny Goodheart, lobbied Unix's various owners for many years to allow the book to be published officially. In 1996, the Santa Cruz Operation finally authorised the release of the twenty-year-old 6th Edition source code, and the full code plus the 1977 version of the commentary was published by Peer-To-Peer Communications. The reissue includes commentary from Michael Tilson, Peter Salus, Dennis Ritchie, Ken Thompson, Peter Collinson, Greg Rose, Mike O'Dell, Berny Goodheart and Peter Reintjes.

"You are not expected to understand this"

The infamous program comment "You are not expected to understand this" occurs on line 2238 of the source code at the end of a comment explaining the process exchange mechanism. It refers to line 325 of the file slp.c. The source code reads:

/*
* If the new process paused because it was
* swapped out, set the stack level to the last call
* to savu. This means that the return
* which is executed immediately after the call to aretu
* actually returns from the last routine which did
* the savu.
*
* You are not expected to understand this.
*/
if

A major reason why this piece of code was hard to understand was that it depended on a quirk of the way the C-compiler for the PDP-11 saved registers in procedure calls. This code failed when ported to other machines and had to be redesigned in Version 7 Unix. Dennis Ritchie later explained the meaning of this remark: