Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?
Sun Microsystems Books Media Operating Systems Software Unix Book Reviews

Solaris Systems Programming 181

Ben Rockwood writes "UNIX, in all its many forms, was developed by developers for developers. This is evident in the connection between UNIX and C. In many ways, you can't truly understand one without the other. Certainly, there are plenty of UNIX users and admins who understand semaphores but have never written a threaded application, and C programmers who have never left the Windows world, but nevertheless at some point you'll encounter the symbiotic relationship the two share. Often, though, we find system administration books that discuss programming topics but not programming itself -- and conversely, C programming books that don't address the essence of UNIX. When we combine the two topics we get a systems programming book, an epic guide that clarifies relationships essential to understanding both entities in a truly holistic manner." Read on for Rockwood's review of Solaris Systems Programming, a book he describes as reaching this ideal.
Solaris Systems Programming
author Rich Teer
pages 1248
publisher Prentice Hall PTR
rating 10
reviewer Ben Rockwood
ISBN 0201750392
summary Guide to systems programming using C on UNIX systems, not limited to Solaris

Several such guides have popped up over the years, such as The UNIX Programming Environment (Kernighan & Pike 84), Advanced UNIX Programming (Rochkind 85), The Magic Garden Explained (Goodheart & Cox 94), Advanced UNIX Programming (Gay 00) (that's not a typo, there really are two books with the same name), UNIX Systems Programming (Robbins & Robbins 03), UNIX Systems Programming for SVR4 (Curry 96), and the undisputed heavyweight champ, Advanced Programming in the UNIX Environment (Stevens 92).

Each of these books is distinctive, yet they share a number of topics. Essential topics include low- and high-level IO, signal handling, processes, IPC, and basic file system mechanics. In the more modern books, we see the inclusion of popular topics such as threading. Discussion directed toward broader topics of UNIX vary widely, namely due to the OS agnostic nature of such guides, despite the fact that until recently many books tended to slant toward SunOS/Solaris. Regardless of how many systems programming texts have appear, however, most programmers will agree that Stevens' guide is the only truly definitive choice. Since its release, there has been little challenge to its prominence, despite the emergence of Linux as a major UNIX implementation, despite several newer systems programming books, and even the 2nd edition of Rochkind's guide. But all of this now changes thanks to the release of Rich Teer's Solaris Systems Programming.

At a whopping 1248 pages, this volume dwarfs just about every systems programming book available by over 500 pages. It avoids the distractions of OS ambivalence by being tailored to Solaris, but is applicable to any UNIX platform available including Linux. Its layout is similar to that of Stevens' or Curry's books but builds significantly on each topic.

New systems programmers will immediately appreciate Teer's completeness, both in topic coverage and in his example code. Almost every code example is complete and runnable, unlike many of the other guides that demonstrate a topic only in an abstract function rather than complete program. Essential topics for completeness which have remained surprisingly absent from nearly every guide available (such as memory, code security and 64-bit topics) are thoroughly covered. A striking example is coverage of memory topics. When I pulled volume after volume off the shelf of my local bookstore and looked up "memory" in the index of each, I found surprisingly few even cover the topic beyond explaining the difference between stack and heap. In fact, many don't even include the malloc() function. Solaris Systems Programming is the only book I've ever found so complete in its memory discussion that it not only covered stack and heap, all the available memory management functions, but even discusses such important topics as memory alignment!

A complete chapter on secure C programming is provided, thoroughly discussing such important topics as buffer overflows, chroot jails, and program environment. A good number of tips are provided to help you immediately incorporate better security into your app whether it's a real concern (for now) or not. Combine this with a complete chapter on resource control and limits, including discussions on system information, the /proc file system, and some Solaris-specific resource control facilities, you can write more intelligent, less obtrusive, and better-tuned applications.

The coverage of advanced IO topics (including STREAMS) and file system coverage are superior to that in any other text I've seen. System admins will appreciate the in-depth coverage of file system topics that have only seen this sort of detail in books such as Solaris Internals (Mauro & McDougall, 00). This level of discussion allows not only a better understanding of file system and IO techniques, but also the clarity to immediately start building your own tools that allow you to interact with file system with far greater precision than ever before. Other topics, such as memory mapped IO, have rarely seen such detailed coverage.

A full treatment of IPC topics are handled, but like Stevens', these techniques are discussed using conventional concurrency techniques such as fork(). A discussion of POSIX threading is absent and regarded as too large a topic to address properly in a systems programming book and the reader is urged to consult a complete guide to the topic such as Programming with POSIX Threads (Butenhof, 97). While some readers might be put off by this, you'll appreciate how this keeps IPC discussions unencumbered. POSIX threading is mentioned where applicable, so it's not at all ignored, but readers of Rochkind's 2nd Edition or Robbins' books will notice that introduction of a PThreads overview can quickly overwhelm the rest of the text. Unique to any other text with which I am familiar is the inclusion of a section on Solaris Doors (also applicable to the Linux implementation), which is the fastest IPC method in Solaris, introduced with Solaris 2.6.

Something that both new and seasoned programmers will appreciate is the inclusion of a chapter on utility functions, and another on localization. The utility chapter provides great a discussion of (and reference to) the often-used functions that many other books ignore, such as string handling and manipulation functions, memory management, byte arrays, temporary files, error reporting, command-line argument parsing, character classes and more. While it's true that these aren't strictly systems programming topics, they are inevitably going to be topics of interest to most programmers. It is the inclusion of such topics that allows you to take your pile of reference books and replace it with this single volume.

A major topic to systems programmers today is 64-bit programming. Naturally, Solaris is a robust 64-bit environment, and is well handled in this book. programmers new to 64-bit environments, whether on Linux, Solaris, or other UNIX platforms, will greatly appreciate the gentle introduction to 64-bit coding, as well as best-practice techniques and sprinkled 64-bit wisdom throughout the text.

Like it or not, Solaris is the dominant commercial UNIX platform in the market today and will be for the foreseeable future. This guide doesn't pull any punches in giving you the best information available to exploit that environment to its full potential. If you're a programmer, this book gives you a single reference to consolidate your library and give you a new appreciation for familiar topics and entry point to things that you might have never leveraged before (Doors, 64-bit optimization, etc). If you're a system admin, you'll find a whole new appreciation for Solaris and UNIX in general with unparalleled understanding of how they really work under the covers, especially if you've already read Solaris Internals. Everyone will love the detail and completeness, combined with with the hundreds of tips (not to mention nifty Solaris trivia) scattered throughout the book. Rich's style is compelling and relaxed, very readable in front of your keyboard or with a cup of coffee on the porch. And readers will enjoy his sense of humor, which is admittedly subtle; experienced programmers and system admins, though, will enjoy the book's wit.

Finally, given the impending release of Solaris 10, yet another aspect of this book needs to be considered: it's an essential companion for DTrace users! Rich couldn't have possibly foreseen this need when he started writing the book, but it is extremely important today. Solaris 10 provides more visibility and debugging tools than any other UNIX system in existence today, the most popular of which is DTrace. But all of these tools expect the user to have a certain level of understanding of the system itself. This book should be standard issue for any sysadmin that ever plays with Solaris 10. When doing system root-cause analysis with DTrace, this book becomes an essential reference, especially if you are allergic to system headers. If you have been using DTrace and getting lost, or feel that you just don't know Solaris the way you need to, buy this book and you'll find the confidence and skills to get you back on track.

You can learn more about Solaris Systems Programming on Rich Teer's home page for the book. On that page the full contents and index are available, including a sample chapter (Ch 8 "System Information and Resource Limits," 62 pages!). You can also visit Teer's personal home page to learn more about him and his work. You can purchase Solaris Systems Programming from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

Solaris Systems Programming

Comments Filter:
  • by Kiryat Malachi ( 177258 ) on Tuesday October 12, 2004 @05:47PM (#10507879) Journal
    There are many things you can only do with C compiled directly to the core on an embedded system, effectively writing your own OS. This does not make programming to the raw iron any better than UNIX or even Windows, just different.
  • by Anonymous Coward on Tuesday October 12, 2004 @06:06PM (#10508080)
    that it's not even considered as something worth mentioning in programming job ads? I mean it's automatically assumed that you know it. Or maybe it's not needed. When was the last time you were asked by a recruiter whether you knew unix IPC?
  • by KenSeymour ( 81018 ) on Tuesday October 12, 2004 @06:32PM (#10508363)
    I haven't been asked about Unix programming at all in quite a long time.
    A lot of that work has gone over to Windows and/or Java.
    Similarly, I don't see a lot of X Windows programming jobs either.

    I learned Unix IPC with M. Rochkind, "Advanced Unix Programming."
    But I haven't done it for about 10 years.

    I've used threads in Windows and Java since then but not a lot of IPC.
    IPC is fun stuff, but just try and get some one to pay you to do it.
  • by Anonymous Coward on Tuesday October 12, 2004 @06:32PM (#10508370)
    You and your colleagues are way out of touch. Solaris has been smashig Linux performance on several new benchmarks. See Sun's web site...
  • by KenSeymour ( 81018 ) on Tuesday October 12, 2004 @06:39PM (#10508448)
    I think it is a culture thing. For a long time, Unix thread code didn't port.
    Some flavors didn't even have threads.
    So if you wanted to write a product that worked on multiple Unix variants, you used forking and IPC instead of threading.
    It took a long time for pthreads to catch on.

    Windows programmers generally don't worry about porting so they took to threads more quickly.
  • by Anonymous Coward on Tuesday October 12, 2004 @06:46PM (#10508512)
    I know what you're trying to say. However, it doesn't quite help your argument when you throw around things like 'knowing how to create and use a semaphore in a C program'. Of course, you can't do it in a C program, except through an external API. Or with inline assembler and a SWAP instruction or somesuch, but that's cheating. :)

    Unless there's some new C standard that has synchronization primitives built in?
  • Of course, you can use shared memory, but thats more of a hassle to set up.

    Perhaps. But it's also far less error prone than threads sharing variables when one thread forgets to get its locks right. That in turn leads to more reliable and stable software, and is generally considered a better model. With mmap/MAP_SHARED, you have to explicitly reference the data you wish to share, so the programmer tends to think more about what they're doing. With threads, everything is shared by default, and it's much easier to overlook the fact that another thread might be using that data.

  • by Pseudonym ( 62607 ) on Tuesday October 12, 2004 @09:56PM (#10509923)
    Guess what? Typical UNIX software doesn't use threading. Forking is much easier, was there first, and is usually not significantly less efficient.

    It depends what you call "typical".

    A web server generally doesn't need shared data. Apache 1.x only uses shared data for a small amount of statistics gathering/monitoring, which is a very small amount of work compared with the job of actually serving HTTP, so the minor overhead in managing the shared data doesn't hurt very muvh at all.

    The same applies to other kinds of server where little or no synchronisation is needed (e.g. telnet server, ftp server, ssh server).

    At the other end of the spectrum is a program which does need synchronisation, but each request/response is quick. An X server is a good example. In this case, a single-task tight event loop architecture is appropriate.

    And in the middle, you have a lot of jobs which aren't so simple. A typical DBMS is a good example of this. You have multiple concurrent tasks, which may take an unbounded amount of time, and which may require a nontrivial amount of synchronisation. The jobs aren't effectively sequential, meaning that SMP scalability is possible, but they're not completely isolated either. This is the kind of task where multi-threading is almost always the right answer.

    Multi-threading is also commonly found in interactive GUI applications, where there may be long background tasks in conjunction with low-latency requirements.

    So while it's true to say that typical Unix software, in the sense of most software that comes packaged on the CD from your vendor, is not multi-threaded, that's because most of that software doesn't have difficult synchronisation or scalability problems to solve. On the other hand, a lot of the software that you might buy or obtain after that is indeed multi-threaded.

e-credibility: the non-guaranteeable likelihood that the electronic data you're seeing is genuine rather than somebody's made-up crap. - Karl Lehenbauer