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


Forgot your password?
Check out the new SourceForge HTML5 internet speed test! No Flash necessary and runs on all devices. ×
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 agent dero ( 680753 ) on Tuesday October 12, 2004 @04:44PM (#10507852) Homepage
    Third newsflash: there are many things that you can only really do with C on Unix systems, POSIX anybody?
  • So much cheaper here (Score:2, Informative)

    by cloudkj ( 685320 ) on Tuesday October 12, 2004 @04:45PM (#10507860)
    You can save a lot of money if you buy it at amazon.com [amazon.com].
  • by Rosco P. Coltrane ( 209368 ) on Tuesday October 12, 2004 @04:49PM (#10507895)
    Don't mix C and libraries. C is C, the core of the language is so small its list of reserved keywords fits on a half sheet of paper, and the rest isn't much bigger.

    Whatever useful you can do on top of C depends on whatever libraries you slap on top of it, that gives you, the programmer, easy access to various abstractions of whatever the OS offers you. conio for example reflects what DOS and the BIOS can do and doesn't exist (originally) in Unix. Some libs are common though, like stdio and stdlib. Those are said to be portable, but they're still not part of the C language per se.

    The core of the C la
  • by Anonymous Coward on Tuesday October 12, 2004 @05:06PM (#10508093)
    They were on crack.
  • by RAMMS+EIN ( 578166 ) on Tuesday October 12, 2004 @05:11PM (#10508153) Homepage Journal
    ``fork() is a cheap operation on unix so what is advantage of threading?''

    Guess what? Typical UNIX software doesn't use threading. Forking is much easier, was there first, and is usually not significantly less efficient.

    ``why did apache 2.0 use threads?''

    Probably because it runs on systems that don't have cheap forking (like Windows). Besides, IIRC threading is only one of the mechanisms that apache2 can use, and you can use forking if that suits you better.
  • by AuMatar ( 183847 ) on Tuesday October 12, 2004 @05:12PM (#10508168)
    Not quite. COW: copy on write. Basicly you use the same physical page in both processes, until one or the other makes a write to that page. Then and only then do you make a copy.
  • by AuMatar ( 183847 ) on Tuesday October 12, 2004 @05:16PM (#10508201)
    Easy access to shared variables. If you fork, each process gets their own copy of a variable. An update by process A does not propogate to process B. This is a two sides issue, as it also makes race conditions possible if you don't protect data structures correctly. Of course, you can use shared memory, but thats more of a hassle to set up.

    The other advantage is task switching speed. When switchign between applications (such as forked processes), you need to do a full task switch- registers, stack, memory, cache invalidate, etc. Very expensive. When switching between threads you only need to swap out the registers, stack, and program counter. Very cheap.
  • by stevey ( 64018 ) on Tuesday October 12, 2004 @05:17PM (#10508211) Homepage
    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

    Security should always be important whether you're providing a network server, a setuid application, or neither of these things.

    In many cases security issues arise from having malicious input cause an exploit, even in non-security-sensitive applications if you're not careful unexpected input can cause a crash which might be just as painful from a user point of view.

    Too many people forget that security is a process, and not an addon.

    Many good tips on secure programming can be found in David Wheeler's Secure Programming For Linux and Unix HOWto [dwheeler.com].

    Read it, even if you dont think security is important for you yet. It's only a matter of time until it will be.

  • by Anonymous Coward on Tuesday October 12, 2004 @06:12PM (#10508706)
    well for one threads have shared memory so communication is simply reading/writing a globally protected variable.

    not to mention that most (not linux, until very recently) have a kernel level threads, which can map n-to-m to user-space threads. that means when some app creates some number of threads n, that they may only be backed by m real context executions within the kernel. this is a major advantage over forking. if you need a thread for just I/O where an execution context isn't required, it's much lighter weight than creating an entirely new process.

    if you don't know why threads are better than creating processes, then you should read a good intro to threads. I'd suggest one that talks about solaris threads or the linx ntpl threads.
  • by 12357bd ( 686909 ) on Tuesday October 12, 2004 @06:34PM (#10508876)

    Oh!, True, but the underlying mindset in C is just a set of variables/registers on a simple memory space, that's why is so simple.
    C++ on the other side, is an 'object metaphor', and so needs to have a new() keyword and his related memory behaviour. C has no built-in memory requeriments (except a stack/memory abstraction).

  • by photon317 ( 208409 ) on Tuesday October 12, 2004 @06:34PM (#10508879)

    stdio/stdlib aren't really libraries, they're just header files. The technical distinction you're looking for is actually between 4 things:

    1) The C language (the half page of reserved keywords you mentioned - you get no header files with this (I don't think?))

    2) "Standard C" or "The Standard C Library", which now comes in two major flavors - C89 and C99. This is all those headers like stdlib.h and stdio.h. This is an official standard, and barring a few isolated compilers made for specialized embedded systems that might support the core C syntax but not the Standard C environment, almost all remotely modern C compiler environments support "Standard C" (aka ISO C, aka ANSI C, whatever...).

    3) POSIX, which comes in a few different levels, flavors, and revisions. POSIX builds on top of Standard C and adds a few more portable things. Most OSes support the vast majority of POSIX, and they'll usually document somewhere what parts of POSIX they're conformant with to what degree. Related to POSIX are several other standards and pseudo-standards that are more unix-centric than POSIX (POSIX is quite unixy in its nature, but it also focuses on being as OS-neutral as it can) with names like SUS (Single Unix Standard), X/OPEN, SVR4, BSD, SVID, Unix98, etc... Many of them overlap (and sometimes contradict) the areas that POSIX and Standard C cover, and many unixes support some set of those standards to some degree.

    4) Other libraries... this is where you branch out into all the millions of libraries that may or may not exist on various systems and may or may not be covered by their own standards.
  • by guacamole ( 24270 ) on Tuesday October 12, 2004 @07:29PM (#10509337)
    What do you mean by open? Solaris is not open source, nor its source code is freely available. However, a couple years ago, for a limited amount of time, much of Solaris 8 source code was available for download from Sun. It had many limitations: 1. some parts were shipped as object files since those parts of sourcer contained code that sun doesn't own. 2. The source code was provided only for the original version of Solaris 8 (so, it didn't include any updates and improvements since Solaris 8 was released). 3. The source code was meant for education and research purposes only. technically, you couldn't even legally use in production the programs compiled from this code (modified or not).

  • by swillden ( 191260 ) * <shawn-ds@willden.org> on Tuesday October 12, 2004 @08:19PM (#10509690) Homepage Journal

    Is clone() the clone of vfork in linux ? (Pun intended)


    Actually vfork(), as defined by POSIX at least, doesn't create a child with a shared memory space, exactly. Well, maybe it does, but you're not supposed to use the memory. In a POSIX program you're not supposed to modify any memory in a vforked child (behavior is undefined if you do). The only purpose of vfork() is to avoid wasting time copying all of the page tables immediately before calling exec(), which will replace the whole current process anyway.

    I wouldn't be surprised if there are some implementations of vfork that do act like Linux clone() with the CLONE_VM flag, but you can't portably depend on that behavior (of course you can't portably depend on clone() at all).

    On Linux, vfork() is a special case of clone().

  • Open Source Solaris (Score:3, Informative)

    by Tpenta ( 197089 ) on Tuesday October 12, 2004 @10:21PM (#10510502) Homepage

    Keep your eyes out, Solaris is being open sourced. The pilot has been underway now for a few weeks. I'm sure that there will be a big announcement and press release when it happens, and you can bet that Jonathon [sun.com] will certainly mention it.

    Before the license flames start, there is a commitment that the license will be OSI compliant. There would be little point to the exercise otherwise.


  • by be-fan ( 61476 ) on Tuesday October 12, 2004 @11:11PM (#10510755)
    It's quite possible to bind POSIX to any language. Many Lisps can natively call C API using the platform's C calling convention.

"The C Programming Language -- A language which combines the flexibility of assembly language with the power of assembly language."