Beginning Linux Programming
Authors: Neil Matthew and Richard Stones
Publisher: Wrox Press
Reviewer: Mark Shacklette
Every once in a while a book appears which so perfectly fills a void that its acceptance is all but guaranteed. For Linux programmers or anyone interested in learning Unix programming, there is a new volume to add to your library: Beginning Linux Programming by Neil Matthew and Richard Stones. The book is an achievement both in terms of its subject coverage as well as its surprising depth for a text whose focus, as the title states, is the neophyte. The authors' aim is “to cover enough about a wide range of topics to give you a good beginning in each subject.” In this they succeed magnificently. Inside are full chapters on shell programming (/bin/sh), an introduction to the Unix file system, terminal I/O, the curses library and a chapter on processes and signals. There is a chapter on how to use the GNU gcc compiler, the gdb debugger, make, RCS and other development tools. (They even teach you the basics of how to write a man page for all those new applications you'll write after mastering Linux programming.) The authors cover Linux's X/Open-compliant dbm database (some distributions have gdbm, the GNU flavor of dbm). They devote one hundred and fourteen pages to interprocess communication alone, including pipes, FIFOs, System V IPC (Semaphores, Message Queues, Shared Memory) and Berkeley sockets. There is a 93-page introduction to X programming which focuses primarily on Tcl, Tk and Wish, along with a sip of Java. The book concludes with two chapters devoted to Internet programming, one covering HTML and the other CGI.
With such a vast scope, something had to be left out. Coverage of Expect is assigned to two short paragraphs. Python is missing, as is the majority of Motif programming outside of Tcl/Tk (Xlib and Xt are only mentioned in passing). The only coverage of Perl is an example CGI script, and the section on Java could pass by you entirely, if your nose is not careful to pick up the scent of the fresh brew at the close of the discussion of X programming. (Interesting that Java is appended to X programming, not the Internet programming chapters.) Nevertheless, such focus is necessary to avoid a text of several volumes and to concentrate on the omissions would be to miss the point of the work, which is to introduce you to Linux programming through the use of hands-on code examples, which are graduated and presented in a step-by-step fashion. Each new topic is presented in a few short paragraphs and is followed by a succinct but complete “Try It Out” code example.
Over 10,000 lines of source code fill the pages, all of which are available for download (the ubiquitous CD is missing from the back cover). With such a supply of source code, the usual peccadilloes occur, such as a case statement in the section on shell programming, that lists the case as “[nN]*” (with quotes) instead of [nN]* without the quotation marks (the former fails if you enter anything beginning with a n or a N); or when, during the discussion of pipes, the line:
sprintf(buffer, "Once apon a time, there ..."\n)
is magically spell-checked to “Once upon a time” in the book's output listing (unfortunately, my compiler isn't as smart as the editors and keeps the spelling as “apon”). All in all, the source code compiles and runs fine. Wrox Press, the publisher, has the source and a sample chapter on its web site for your perusal, at http://www.wrox.com/.
The example code gets to the point. The authors present the minimum amount of code to illustrate an idea which, once given, is quickly summarized as they move on to the next extrapolation or improvement. This approach allows the new Linux programmer to get a firm grasp on the subject without too much diversion or interdependence. All examples are self-contained and may be compiled and run—there are no code fragments here. Such an approach facilitates and encourages the reader to experiment with the code examples, since they are so confined few side effects can be introduced, even by the most intrepid of newbies.
Although most of the examples are focused, the authors do present and develop a larger application that implements a simple audio CD cataloging program. The application begins life early in Chapter 2 as an extremely simple shell script that exercises the use of flow-control statements in shell programming and uses simple text files for a database. The application reappears in Chapter 6. This time rewritten in C with the same functionality as the shell script version and with a new interface designed to exercise the curses terminal library. In Chapter 7, the application acquires a real database, dbm. In Chapter 11, the application evolves into a small client-server system, which separates the database from the user interface through the use of named pipes. This example illustrates process synchronization and bi-directional data flow between a single server and multiple clients. In Chapter 12, the application substitutes a message queue for the named pipes from the previous chapter, which solves some problems with I/O synchronization previously encountered with named pipes. Finally, the CD application takes to the Web in Chapter 17 as an example of an HTML interface talking out a CGI layer to the database server. This chameleon-like application greatly enhances the communication of many of the principles presented in the book.
In short, Beginning Linux Programming is a tutorial on the major topics in Linux programming. If you are willing to spend some time getting up to speed, you will find yourself with a book that not only will hold your hand in the midst of the Magic Garden, but will eventually provide you with a fine pair of walking shoes, well preparing you for your own explorations. With this book at your side, as my son's beginning reader puts it:
You have brains in your head.You have feet in your shoes.You can steer yourselfany direction you choose.
Mark Shacklette is a Principal with Lake Shore MicroTech Group, a Chicago-based consultancy specializing in client-server development in Unix and Windows NT. When he's not with a client, he works on his Ph.D. in the “Committee on Social Thought” at the University of Chicago. He lives in Des Plaines, Illinois with his wife Karen, son David and two cats. He can be reached at firstname.lastname@example.org.
Free DevOps eBooks, Videos, and more!
Regardless of where you are in your DevOps process, Linux Journal can help!
We offer here the DEFINITIVE DevOps for Dummies, a mobile Application Development Primer, and advice & help from the expert sources like:
- Linux Journal
- Readers' Choice Awards 2014
- Handling the workloads of the Future
- diff -u: What's New in Kernel Development
- How Can We Get Business to Care about Freedom, Openness and Interoperability?
- Synchronize Your Life with ownCloud
- Days Between Dates?
- December 2014 Issue of Linux Journal: Readers' Choice
- Non-Linux FOSS: Don't Type All Those Words!
- Computing without a Computer