









Advanced Unix Programming, 2nd Ed. 143
Advanced Unix Programming, 2nd Ed. | |
author | Marc Rochkind |
pages | 736 |
publisher | Addison Wesley Professional |
rating | 9/10 |
reviewer | Alex Moskalyuk |
ISBN | 0131411543 |
summary | An introduction and guided course through the world of Linux I/O and interprocess communications, with C++ source code provided for your viewing pleasure. More than 1100 functions explained. |
Advanced Unix Programming (AUP) has been updated to include information relevant to Solaris, Linux, FreeBSD, Darwin and Mac OS X. Rochkind has added more than 200 system calls, according to the preface. But who is the book for?
First off, if you look at the table of contents, you will find that AUP is largely a book on input-output in Unix operating systems. The input-output varies from Basic (Chapter 2) and Advanced (Chapter 3) File I/O to Interprocess Communications (Chapters 6, 7), Network I/O (Chapter 8) and Terminal I/O (Chapter 4). The rest of the book consists of purely informational chapters on fundamental concepts of Unix operating systems (Chapter 1), working with threads and processes (Chapter 5) and signals and timers (Chapter 9).
If you get the impression that this is an academic title, you're not mistaken - if your university has some kind of Advanced Unix/Linux or Unix Networking course, they probably use some AUP material. Note that the book is not a how-to or manual on setting up Apache, Samba, FTP, various filesystems or Jabber servers - it does have a chapter on networking but teaches Unix I/O concepts from developer's perspective only, meaning you have to know C and C++. If you prefer to look at the source code, it's on the author's Web site.
There are two types of readers for AUP: those who start off programming in Unix/Linux, and those who are quite good at it, have read the first edition and are now wondering whether the second one is worth it.
If you are just starting with programming in Unix/Linux environment, don't let the word "Advanced" scare you off. The first chapter is pretty good in getting the reader up to speed with the concepts discussed in the book. It talks about such common tasks as getting the system to tell you what it has in terms of POSIX, getting a Unix box to tell you the date and time inside a C++ application, and counting your app's execution time. In many aspects, the second half of each chapter falls under O'Reilly cookbook format, where you are given a certain task and then provided the source code and explanations of what needs to be done to accomplish the task.
The author also "falls" into the trap of using some quick solutions only to "discover" that they do not work on all the systems. For example, subchapter 3.6.1 Reading Directories first tries to access the contents of the directory via ec_neg (fd = open (".", O_RDONLY) and ec_neg (nread = read (fd, buffer, sizeof(buffer))) only to find out that under Linux the call retrieves unhelpful "*** EISDIR (21: "Is a directory") ***" message. After that we are introduced into proper, not quick and dirty ways, to access Unix directories via opendir(), closedir() and readdir().
From experience, it looks like most of the people I know who own a copy of the first edition of AUP bought it because of its section on Interprocess Communications. The author does indeed provide a great learning and reference resource when in Chapter 5 he takes the reader through Unix processes and threads, explains how fork() works. The simple pop quizzes are there as well. A way to win friends and amuse the opposite sex during watercooler talks is to offer the following example:
void forktest (void)
{
int pid;
printf ("Start of test.\n");
pid = fork();
printf ("Returned %d.\n", pid);
}
Run this example as forktest and you will get a message:
Start of test.
Returned 11111.
Returned 0.
Run this test as forktest > tmp and suddenly the message in tmp file changes:
Start of test.
Returned 22222.
Start of test.
Returned 0.
Why is "Start of test" printed twice in the second example? Warning: the book contains an early spoiler in 5.5 fork System Call
By this point, you probably wonder whether the code examples will work on your system. The author tested the code on Solaris 8, SuSE Linux 8, FreeBSD 4.6 and Darwin (Mac OS X kernel) 6.8. In the preface, he talks about using a Windows box with SSH client to upload the code to the destination systems and run them there.
The book is very convenient to read; the chapter numbering system always gives you a good feel of where you are at. As reading of the entire book is not required, and a lot of people use AUP as a reference, an index containing just functions and system calls is included in Appendix D. Don't know what tcgetpgrp() does? The index will point you to 4.3.4. All the code is printed in monospace font, so it's quite easy to differentiate from the regular text. All the function definitions are boxed with function name, description and signature provided. The signature itself contains comments on what the parameter represents. They also are not saving whitespace on function samples, using the style where each line of source code and each { gets a separate line in text. Overall, more than 1100 functions are covered.
The book is quite practical, too, so don't think of it as pure API rehash. For example, in 8.4.3 (the chapter 8 deals with Networking), you are given the source code for a text-based browser that's written in less than 50 lines of code (although it doesn't quite understand HTML and just dumps everything to standard output).
Overall, if any part of your job description or hobby list includes Unix/Linux development, especially if it's high on that list, this book is a must have. Moreover, looking at the job market defined by keyword "unix", it looks like half the positions include some kind of "Sr." or "Architect" or "Networking" attribute, for which the knowledge provided in AUP would be indispensable.
You can purchase Advanced Unix Programming, 2nd Ed. from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, carefully read the book review guidelines, then visit the submission page.
slashdotted already? (Score:2, Informative)
Advanced Unix Programming [amazon.com] They have 27 used copies, and the book's gotten high reviews.
Re:slashdotted already? (Score:5, Informative)
Advanced Unix Programming [amazon.com].
Re:slashdotted already? (Score:2)
This is $34 at Amazon.COM and 40 at Amazon.CO.UK!!!! That's the equivalent of $70!!!!!!
If I bought AUP and APUE together from Amazon.COM and used standard international airmail shipping, I'd get AUP FREE!!!!!!
Does does it print twice? (Score:5, Informative)
It wasn't flushed in the second example, it would only write out data once there was a full buffer's worth (e.g. 32kb or such), or when the stream was closed. Because it wasn't flushed, both fork()ed copies had this unflushed data in their buffer and both printed it.
I'm sure it scares a few newbies, but it's fairly obvious.
Re:Does does it print twice? (Score:5, Informative)
setvbuf(stdout, NULL, _IOLBF, 0);
You must do this before you use stdout in any way.
Re:Does does it print twice? (Score:2)
Isn't the forked process supposed to begin its execution just after the fork() call???
If so, there should be only ONE "Start of test"...
Can anyone tell me what's happening?
Re:Does does it print twice? (Score:1)
The printf IS indeed executed only ONCE, it's the stdio buffer containing the first printf's string that's duplicated by the fork...
Please forget me and my post...
Terminal I/O? (Score:5, Funny)
Re:Terminal I/O? (Score:1, Informative)
Re:Terminal I/O? (Score:2, Funny)
Re:Terminal I/O? (Score:4, Funny)
Re:Terminal I/O? (Score:4, Funny)
Re:Terminal I/O? (Score:2)
Perhaps I'm in the minority, but the vast majority of applications I use in Linux are console apps. They're simply more efficient and easier to work with than "point and click" GUI apps. You definately need to know how to program console apps to call yourself a master UNIX programmer.
Re:Terminal I/O? (Score:2)
Good UNIX Reference (Score:3, Informative)
I spotted the first edition of this book in my university library when I was doing some coding on FreeBSD. Whilst it didn't have anything specific to FreeBSD it was still a handy reference. I look forward to reading the additions in this version. Perhaps I'll get the university library to order it for me ;-)
Re:Good UNIX Reference (Score:2, Funny)
*NIX (Score:2)
Re:*NIX (Score:5, Informative)
Re:*NIX (Score:2)
Re:*NIX (Score:2, Interesting)
In the corporate server market savings on Linux are minimal compared to Sun etc because of two things:
1. Server quality x86 boxes for hosting business critical applications can cost as much as Sun / HP Boxes. So no real hardware savings that justify the "risk".
2. Most companies do not have /dedicated/ Linux admin support skills and need to outsource some degree of support in order to provide that supp
opendir() (Score:1, Redundant)
Who knew?!
Re:opendir() (Score:2)
% ls -1 *foo |
opendir() is a new feature (Score:2, Informative)
then simply use read() to get an array of structs.
Each struct had a 16-bit inode number and a
14-character filename.
Linux broke support for this, because 32-bit inode
numbers and 255-character filenames would not fit.
Linux would get stuck with DOS-style name mangling
and some sort of inode remapping. Like this:
Linux_i~1.html
(but hey, 14 characters beats 8.3 style names)
Re:opendir() is a new feature (Score:1)
Did I ever say Linux was the first? Linux did
support read() on directories long ago though,
as did many other systems around 1990.
It was portable until Berkeley invented FFS.
Interesting change of pace... (Score:5, Funny)
Marc vs. Stevens (Score:5, Interesting)
It's very unfortunate Stevens died so young, his books including "Advanced Unix Programming" are extraordinary.
Re:Marc vs. Stevens (Score:4, Interesting)
And I fondly remember MTS, too.
Re:Marc vs. Stevens (Score:4, Interesting)
If you're working in C (or C++ I suppose, Oh you youngsters!) on and form of Unix, you probably already have the first edition, or at least have read it. If not, go and get it (or this second edition). Along with The Unix Programming Environment, it's one of the classic texts that's not too large to read, but too useful to skip.
Liam
Re:Marc vs. Stevens (Score:5, Informative)
I believe you mean:
"Advanced Programming in the UNIX Environment" [barnesandnoble.com]
His "TCP/IP Illustrated" volumes 1-3 are also great.
I havn't read AUP, so I can't compare him to Stevens.
-metric
Re:Marc vs. Stevens (Score:1)
Re:Marc vs. Stevens (Score:1)
But he (Stevens) wrote Advanced Programming in the Unix Environment (APUE), not Advanced Unix Programming...I can see buying AUP and getting myself thouroughly confused..."Hand me that copy of APUE, er, AUP, um, the one with the RED stripe on the cover!!!"
I find it strange Addison-Wesley doesn't include Unix Network Programming Vol 2 (IPC) in its "Professional Computing Series" [awprofessional.com]...APUE,
Re:Marc vs. Stevens (Score:2)
(What you really meant was if we could understand the damn thing, too. At long last. Biochemists are obviously just lazy. :-)
Anyway, I agree -- the world would be a better place with Stevens still in it, writing books.
Re:Marc vs. Stevens (Score:1)
Copyright infringement (Score:5, Funny)
void forktest (void)
{
int pid;
printf ("Start of test.\n");
pid = fork();
printf ("Returned %d.\n", pid);
}
I'm certain you did. It's code and it can be used in Unix so it belongs to SCO.
Re:Copyright infringement (Score:2)
Copyright infringement is a vicious cycle. Anonymous, let us create a support group. We'll start by licensing the code from SCO.
Obvious question (Score:5, Insightful)
Re:Obvious question (Score:1, Funny)
Re:Obvious question (Score:2)
Re:Obvious question (Score:3, Interesting)
Buy APUE and Unix Network Programming volumes 1 and 2 all by Stevens if you're serious.
APUE: great quality, but showing age (Score:3, Insightful)
There's just something wrong with trying
to write a UNIX book while running Windows.
Stevens wrote APUE with *roff macros! FYI,
that beats TeX for nerd value.
Problem is, APUE is getting obsolete.
Re:Obvious question (Score:3, Interesting)
A book with the rigour and depth of Stevens without the obsolete stuff (Stevens deliberately includes obsolete calls and functions, and with good reason, but it still can be frust
Excellent Reference (Score:4, Informative)
I have used this book for the past few years mostly as a reference for some of the really hairy stuff/problems that I have sometimes run into.
It belongs on my bookshelf right along with my Unix Network Programming books (Richard Stevens auth).
Um... (Score:5, Funny)
Or would that be the 10th edition?
Re:Um... (Score:2)
Re:Um... (Score:5, Funny)
You should call it the 10nd edition. It confuses people better that way.
Re:Um... (Score:2)
Re:Um... (Score:1)
Uh, no, that would be the 10nd Edition.
Re:Um... (Score:2)
Re:Um... (Score:1)
-Lasse
Re:Um... (Score:2)
Oh Joy! (Score:5, Funny)
Re:Oh Joy! (Score:1)
POSIX Reference (Score:5, Informative)
Nowdays though, my definitive reference for writing portable unix programs is the merged IEEE POSIX and Open groups's Single Unix Specification [opengroup.org]. Registration is free.
Re:POSIX Reference (Score:1)
worth getting? (Score:1)
First Edition? (Score:5, Funny)
I am an avid book collector who has appeared on "Antique Roadshow" and "Cover to Cover Classics". I consider myself an authority in this matter. I have touched original Guttenberg bibles, been in the presence of the "War and Peace" transcripts, thumbed through the notes of DaVinci...but never, and I mean never, have I stumbled across this true classic! Ebay, Sothebys, 7 Mile Fair in Racine, Wisconsin...NO WHERE have I been able to zero in on this rareity.
I will gladly sacrifice a small fortune to be in same vicinity as this timeless classic known by a few rare collectors as "Advanced Unix Programming, 1st Edition." Extra if it is bound by that cool shiny metal spirally stuff.
Unix programming reference... (Score:2, Insightful)
Re:Unix programming reference... (Score:2)
What!? (Score:2, Insightful)
No testing - or even discussion - under cygwin, MS's native POSIX subsystem, linux-on-windows or MS's unix services for windows?
People need to develop for unix - for windows. All those killer win32 apps end up unix compatible, and future migrations are a snap once you tell y
Fork() (Score:3, Funny)
Re:Fork() (Score:2)
Water cooler? (Score:2)
I don't think any of the opposite sex will be amused. In fact, I seriously doubt it.
Re:Water cooler? (Score:2)
Au contraire!
They may not be particularly interested, but I am certain that they will be amused, although they will probably wait for you to leave before ROTFLTAO at what a geek you are.
Or maybe it's just me...
Re:Water cooler? (Score:2)
File handle passing (Score:3, Informative)
Sure, it's easy to have two processes open the same file. If it's something like a pipe that exists anonymously, you can still give it to a child process by having it open when you fork. But to pass it to a process that isn't a child? Tougher, but not, surprisingly, impossible. (It involves Unix domain sockets, of all things.)
I generally don't find too many people that know about this, but it can be very useful on occasion. I think it definitely qualifies as an important technique, and the fact that this book doesn't appear to mention it is a strike against it. (Stevens discusses the topic, of course.)
Re:File handle passing (Score:2)
you need APUE, pages 479 to 489 (Score:1)
pass file handles between arbitrary processes.
Re:File handle passing (Score:2)
"Unix sockets support passing file descriptors or process credentials to other processes using ancillary data."
Re:File handle passing (Score:3, Informative)
Notice:
Yet somehow /tmp/foobar gets the message in it anyway.
Credit Kragen Sitaker for the original code which I hacked to be a better demo. (I never claimed I could remember offhand how to do this, and I no longer have my copy of Stevens, but I
Looking for other good UNIX programming books (Score:1)
damn, I just purchased this a year or so ago (Score:1)
I'm Buying It (Score:2)
a true classic (Score:3, Interesting)
with K&R's C book and K&P's unix book as a must
have.
The style is light and engaging, and humorous.
e.g. on the 'new' lseek call there's a footnote:
"The extra letter (l) was available, since
creat was one letter short"
I still have my dog-eared copy which I refer to
from time to time.
HP distributed it with their first Unix systems
in lieu of a an official HP manual.
This 2nd edition adds a Java POSIX library
which is excellent. I am already using it
in production systems.
(Comparison's with Stevens book are a little
unfair as they have different emphases.
Rochkinds is on Unix, Steven's are less on
Unix and more on networking)
Re:a true classic (Score:2, Interesting)
No way. Stevens wrote a UNIX book, not just the networking books. The UNIX book is about file IO, directory operations, system data files (passwd), process control and job control, signals, terminals, mmap, daemon writing, pipes, shared memory, message queues, FIFOs, semaphores, passing file descriptors, serial port IO, PTYs, etc.
Re:a true classic (Score:1)
Re:a true classic (Score:2)
Re:a true classic (Score:1)
tcgetpgrp, huh? (Score:1)
Allman style [dict.org]. (Yay! Was starting to think I was alone in the world.)
Big deal. /usr/bin/man will just tell me.
termios(3):
Sounds interesting enough, though, and everyone else seems to be
I prefer the old cover (Score:1)
Best Linux programming books (Score:2, Interesting)
Those two books gain you an understanding of the linux kernel (and OS concepts in the meanwhile) only rivaled by reading the kernel source (and http://lxr.linux.no/ is the best for that!)
Something wrong in the code? (Score:3, Funny)
Am i doing something wrong?
Re:Something wrong in the code? (Score:1)
Re:Something wrong in the code? (Score:2)
NAME
fork - create a child process
SYNOPSIS
#include
#include
pid_t fork(void);
The 731 you get is the pid of the child process.
Re:Something wrong in the code? (Score:3, Funny)
Yes. Before running the it the first way (stdout is the terminal), you need to wait until your system's process id counter is in the low 11100s -- check by using ps, top, or similar. That will ensure you get the "Returned 11111" output. (You might need to try it a few times.)
Similarly before running it with the output directed to tmp, wait for the highest PID numbers returned by ps to get up to around 22218 before running it.
Of course, if you don't care if your forked proc
1st edition was great (Score:1, Insightful)
From my friend who still works there, I heard that they had managed somehow to lose the copy. I was so sad, that I decided to buy one. Shipping costs were much larger that cost of the second hand book...
Just when book arived, I heard about new edition!
Compared with Stevens? (Score:1, Insightful)
All I want to know is, would adding this book to my collection be redundant, or would it actually be useful? Given the quality of the late, great Stevens' writing, I suspect the former...
not just advanced programming (Score:1)
looks like advanced compiling if the author can get that code to run ...
The "feel" of the 1st edition (Score:2)
I just love the Addison Wesley books.
It all depends how you define "Timeless" (Score:2, Interesting)
Re:It all depends how you define "Timeless" (Score:2, Interesting)
Interestingly, this is the first comment I've gotten on the matter. I wasn't aware of it myself until about 18 months ago.
Re:It all depends how you define "Timeless" (Score:1)
Re:Free Software (Score:5, Interesting)
As you say in the 2nd paragraph of the article, "Linux is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system."
My book really is about the kernel API. There's nothing there about commands, shells, compilers, or anything else at the GNU level, except how to implement them. GNU commands are often used as examples, and the reader is pointed to GNU code for research material. (And encouraged not to read it before doing the exercises!)
I suppose we probably disagree about what the term "operating system" refers to. Back when I was at Bell Labs and studying computer science, we didn't think shells and other commands were part of the OS. In fact, removing the shell, the file access methods (e.g., ISAM), and lots of other stuff from the OS was one of the key contributions of UNIX.
The book and its website also strongly support part of your last point, the part about the importance of Free Software. The part about the evils is outside the scope of the book. (All of the code from the book is Open Source under the BSD license.)
Re:Free Software (Score:2)
I have karma to burn so I'm going to point to the moderators out that it is in fact the parent AC that's the troll and not R. M. Stallman or Marc Rochekind. Probably a troll with an axe to grind against Stallman or something.
If you look at the user page for Marc Rochekind he posted only on the article on Marc Rochekind's book. We'd have to be really getting into conspiracy theories if we thought he wasn't really Marc Rochekind.
As for Stallman, the comments are very Stallmanesque so unless you think Stal
Re:Free Software (Score:1)
Free Tips on GNU/Whoring Karma (Score:1)
You have to get your karma up if you want your message to be heard. This is the way we do it around here. Never correct slashdotters with low number because they have 5 or 10 accounts with about half of those having mod points at any one time so they can mod-bomb you into submission. Only say things that teenage boys would want to hear, like "Doom3 rülz d00dz!" or "RIAA sucks rocks!". It is also important to pay attention to which catch phrases are currently hip. You don't want to still be say
Re:Free Software (Score:2)