Linux Application Development 171
Linux Application Development, 2nd Ed. | |
author | Michael K. Johnson and Erik W. Troan |
pages | 736 |
publisher | Prentice Addison-Wesley Professional |
rating | 9/10 |
reviewer | Ray Lodato (rlodato AT yahoo DOT com) |
ISBN | 0321219147 |
summary | Covers just about everything intermediate to advanced programmers need to interface with Linux from their applications. |
The overall structure has the book divided into four major parts: Getting Started, Development Tools and Environment, System Programming and Development Libraries. Part 1, Getting Started, is a very high-level overview of Linux itself. The three chapters cover barely 20 pages, and discuss the history of Linux, its licensing, and the online documentation.
Part 2, Development Tools and Environment, gets more detailed, but ends up as a medium-level view of what tools you might use to actually create and debug your application. Six chapters covering about 75 pages discuss editors (Emacs and vi), make, the GNU debugger gdb, tracing, gcc options, glibc, memory debugging tools, libraries, and the environment. Each chapter feels a little lightweight except for the one on memory debugging tools. Here the authors dive into the common issues of buffer overflows and underruns, and the various utilities you can use to discover them. Not only the glibc features mcheck(), MALLOC_CHECK_ and mtrace(), but the memory profiler (mpr), Valgrind, and Electric Fence are discussed in enough detail to be useful.
If the first two parts seemed to just skim the surface somewhat, Part 3, System Programming, definitely dives into the deep end of the pool. Each chapter covers its topic in detail, and many code examples are given to clarify the concepts. Part 3 has 13 chapters and covers 450 pages, almost two-thirds of the total book. My major complaint with Part 3 is that related chapters appear to be separated by others. I will discuss them as I see the relationships.
Chapter 10 covers the Unix/Linux process model. Signals, job control, processes and threads are explained in detail. The authors also describe the 'gotcha's involved with setuid and setgid programs. The chapter ends with the first iteration of a sample shell program, ladsh. This shell is expanded as the book progresses to explain newer concepts. This topic should be followed by chapter 15 (Job Control), which goes into job control, including how to stop and start processes, move jobs between the foreground and the background, and handle job control signals.
Skipping back, chapter 11 introduces the file handling metaphor and how it relates to files, pipes, directories, devices, links, and sockets. It also explains inodes, file permissions, file descriptors, and the read/write/seek system calls. Chapter 13 expands on chapter 11 by discussing the advanced topics of multiple file handling, memory-mapped files, file locking, and scatter reads/gather writes. The next chapter goes over directory operations, such as handling the working directory, file name globbing, walking trees and directory change notification.
Signal Processing (chapter 12) discusses simple interprocess communication including signals and handlers. It describes the Linux and POSIX Signal API, real-time signals, and how to transmit data with a signal. Remote interprocess communication occurs over sockets. Chapter 17, Networking with Sockets, shows how to use the socket API, which can be used for IP, IPX, AppleTalk and Unix domain sockets. Michael and Erik show how to write a client and server, how to handle name resolution, the differences between session (e.g. TCP) and datagram (e.g. UDP) communications, and finish with an example tftp server.
Obviously, many programs need to interact with the user, and that's where chapters 16, 20, and 21 come into play. Chapter 16 talks about terminals (tty) and pseudo terminals (ptty) and how to program them. The POSIX termios interface is discussed in depth. Chapter 20 gives you tools to manipulate virtual consoles, which create the abstraction needed to multiplex different sessions on the same keyboard, video, and mouse. The following chapter talks about the Linux Console including text-based screen-drawing with S-Lang and curses, the terminal capabilities (termcap) and terminal information (terminfo) databases, ANSI Escape sequences, as well as direct screen writing.
Chapters 18 covers basic system calls for time/date representation and formatting and timer usage, and chapter 19 covers pseudo-random number generation and its use in cryptography. Finally, part 3 wraps up with chapter 22 discussing how to write secure programs. Common exploits such as buffer overflows and unauthorized directory traversals, and the ways you can prevent them (length checking and chroot, for example) only scratch the surface. The authors recognize this is just an introduction and refer you to another book to fill in the blanks.
The final part of the book covers the various development libraries commonly available to the programmer. The six chapters cover a wide range of topics. Chapter 23 covers the ins and outs of string handling, including processing regular expressions. A simple grep program demonstrates the ideas. Using S-Lang to handle the terminal is the main interest of the next chapter. Basic input/output handling, and line drawing using text characters seem mundane in this day and age of GUI interfaces, but they have their place. Check out a Red Hat install to see what I mean.
Chapter 25 discusses database interfaces. While gdbm and Berkeley db are better known, Michael and Erik chose to focus on qdbm, which is licensed under the LGPL, making it more attractive. Linux programmers are used to typing in commands with all of their options. Getopt and getopt_long are the standard for processing those options, but popt is detailed due to its extended capabilities, such as nested options which allow libraries to define options for them to handle which the main program can effectively ignore.
The final two chapters cover dynamic loading of shared objects (as opposed to shared libraries) with the advantages that provides, and user identification and authentication, covering id-to-name translation, and Pluggable Authentication Modules (PAM). As usual, example code shows clearly how to use the interfaces.
I know this review is lengthier than usual, but this book has so much packed within its covers, I didn't want to give short shrift to any part of it. When programming, one needs a number of reference books at hand, and Linux Application Development should definitely be one of the handiest. Just about every aspect of how to interface to Linux from your application program is covered, and the numerous code snippets and examples keep things understandable. An extremely useful book such as this deserves a high ranking. My only concerns were how the first two parts seemed skimpy compared to the rest of the book, and the part on System Programming could have been laid out better. That said, Linux Application Development rates a 9 out of 10.
You can purchase Linux Application Development, 2nd Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
question (Score:2, Insightful)
Re:question (Score:2, Insightful)
If anything in the OSS/Linux world needs some more thought it is the horrid man pages.
Re:question (Score:2)
They are not meant as complete newbie introduction to , but rather as a reminder or dense description of something. It's invaluable when you need some information on how certain library calls work, commands and similar.
Re:question (Score:3, Insightful)
What does my user name have to do with the quality or content of my post? It's people like you who mod based on username or sig that make /. moderation the horribly biased and awkward system that it is.
I find it funny I'm branded troll for offering my opinion that man pages are inadequate. When someone says RTFM they more generally mean go online and look for real documentation as man pages rarely if ever cut it.
I w
Re:question (Score:2)
O
Re:question (Score:2)
Ah, but when do you look at the info page, which may or may not be there? I'm not a big fan of doing a man foo and then an info foo for everything that I want to look up. 'Course there's a note at the bottom of some man pages that say to look at the more extensive in
Re:question (Score:5, Insightful)
I see the greater problem in the fast pace of Open Source development. Lots of books especially on new and developing topics are already outdated once they appear on the shelves.
Re:question (Score:2)
Re:question (Score:2)
No, in your case the man with the book might only now 4 options, but the man with the man page wouldn't even now that the command exist in the first place. Man pages are good to lookup the options when you already know what you want, for anything else they are quite horrible.
Re:question (Score:2)
well, gosh, I want to remove this symlink to
let's look up how to do that in the manpages
hmm. okay. that sounds about right.
shit
Re:question (Score:1)
answer (Score:2, Interesting)
Really, before you mod me down, do you really believe that the majority of mans provide enough information for people just learning the tool?
Re:answer (Score:3, Interesting)
I have to agree, man is not like it was in the old days. Manpages and a few AT&T reports and the 'C' book was all you needed.
But thats was then, and now is now, with all sorts
of stuff hidden away in info pages or some confounded desktop system. Its much harder to
find the clues you need to get things done.
Re:question (Score:1)
Guess when it comes down to it, it's really a matter of preference.
Re:question (Score:1)
Because until you have read a well written book you have no idea what the man pages are trying to say. You need to start with a tutorial.
For further reference you should then read mans.
Well see? You knew the answer yourself all along. The man pages are a reference source once you have had a tutorial.
KFG
Re:question (Score:3, Funny)
Re:question (Score:1)
Also, a man page is never going to give you thorough enough examples. Most people learn much better by example than technical jargon. No man page is going to be able to provide enough examples to gain any true understanding of the
Re:question (Score:2)
If I know what command to use the man page is great for telling me the details on using it. (in fopen(3) did I want w+, a, or a+) However if you don't know a that strtol(3) exists you will write one yourself that doesn't work as well.
I don't know if this book covers the above though. I've often wished there was some magical "clippy" that would pop up and say "It looks like you are doing a bad re-write of strtok(3)" everytime I re-invent the wheel. Of course it needs to be smart enough to also do "It
Good introduction aggregates appropriate man pages (Score:1, Insightful)
To become productive on a platform, you need to know what that platform is fundamentally capable of, and the APIs that provide access to that functionality. And, as a programmer, I find a quick and well-ordered tour through key APIs the best way to get a handle on both before diving in to some serious development.
Now man pages become useful - now that you know what you _can_ do, have a rough idea of the platform's design
Re:question (Score:3, Funny)
For further reference you should then read mans.
Because I hate dragging my DEC Terminal to the bathroom. Besides, my RS232 cable is only 25' long.
btw... "mans"? shouldn't that be "men"?
Re:question (Score:3, Interesting)
I don't know why everybody assumes that man pages must be read online. When I really had to learn UNIX seriously, I bought myself one of the five-volume Berkeley manual sets to keep at home. These consisted of the man pages plus various technical reports. In addition to looking things up, I would read through them. It was a great way to get an idea of what the system consists of and what programs, library functions, system calls, and so forth are available. That was very handy set of books. I'd still be us
Review? (Score:1, Insightful)
Re:Review? (Score:1, Insightful)
Ans: Excellent, excellent (Score:2)
I have had this book for three years, and it's excellent in both writing quality and examples. It's strictly console oriented, go somewhere else for GUI programming, but it's by far the best, most clear, and comprehensive source of info for creating programs that need to do Linux system calls.
LWN Review (Score:4, Informative)
Application development? (Score:4, Insightful)
While such things as pipes, regular expressions, setting date & time etc. are all fundamentals of any kind of programming, it seems a more apt name for the book would be Linux Command-Line Application Development, or Linux Daemon Development.
Re:Application development? (Score:2)
I don't really see the need for these books anymore, the man pages, info pages, online manuals cover all of this. But it's just me...
Re:Application development? (Score:2)
Re:Application development? (Score:2)
Whilst GUI applications require lots of knowledge to implement correctly, the innards usually need a good understanding of pipes, regex etc.
Re:Application development? (Score:2)
But don't worry, it must be me.
Re:Application development? (Score:4, Insightful)
How many of those GUI apps use tools from this guide, in spite of being GUI-oriented?
Knowing how to write *nix applications without concerning one's self with the GUI is a necessary issue, regardless of the end-target.
Consider also that "drawing buttons" is done entirely by libraries that handle such things for you if you know what you're doing and you'll realize most of what you're looking for just isn't programming, its GUI design -- and shouldn't be done by programmers anyway. See grip for evidence.
Re:Application development? (Score:4, Insightful)
Perhaps the distinction wasn't so obvious in 1998 or whenever the first edition came out, but it is now.
Fedora does contain console apps such as vi, emacs, mc, etc. that run through curses and respond to user input, but the vast majority are GUI based applications.
Command-line programs like grep, ls etc. are tools, not applications. Programs like sshd, inetd, apache etc. are daemons, not applications.
Re:Application development? (Score:1)
Re:Bollocks (Score:2)
Thank you, King Obvious. I was obviously talking about the GUI libraries and RAD tools available for
but from what I can see, it's Python-based. That's fine if you know Python (and I do), but not everyone does
Qt is a C++ library usable from many languages. PyQt is its Python bindings. Not everyone does, but everyone should, because it is the
Re:Bollocks (Score:2)
Slashdot was always a contest of who yells more towards which side, and I find it fun sometimes to participate in it..
Anyhow I was just responding in the same spirit of "Sadly Windows is far ahead of Linux in the GUI and development department" with the opposite.
If a real discussion is due, I can participate in that as well.
Ruby is a nice language too, but too bad all the sheeple are stuck with C# and other Microsoft-said-so languages.
Re:Application development? (Score:2)
Re:Application development? (Score:2)
Oh sure [reference.com].
Re:Application development? (Score:2)
Looks like any program to me. As I said- the term predates GUIs.
So where does it say the UI is graphical? (Score:2)
Re:So where does it say the UI is graphical? (Score:2)
So unless your definition of application is restricted to fscanf, the term makes no sense for non-graphical UIs either.
Re:Application development? (Score:3, Informative)
What is the command line then?
I'm sorry, but a lot of programs just need that. If we can get more services the daemons you mentioned, yay for us.
Re:Application development? (Score:2)
So is Gtk+ and Qt.
And so, by the way, is the CLI.
find
That's a nasty looking user interface, but a user interface it is.
cdrecord -v dev=0,0,0 -eject speed=24
That's also a user-interface.
Incidentally, I always tell my clients to edit files with 'vi' when on the phone, it lets me guide their fingers easier.
"Hit '/', then type 'root:', now hit '$', hit 'a', type 'loser', hit ESC, type ':wq', thanks."
User interface
Re:Application development? (Score:2)
Re:Application development? (Score:1)
Re:Application development? (Score:1)
This book covers the interesting stuff in an application (whether Gooey or CLI).
Re:Application development? (Score:2)
Have you ever designed applications using Trolltech's Qt? The entire GUI of an application can be designed using editing tools - everything from pulldown menu's to dialog windows, entire pages of tab controls. Not forgetting that entire dialog windows can be made automatically resizable (Maybe there are other design tools that can d
Don't I just want to write Linux apps right now! (Score:2, Funny)
It is fun! (Score:2)
Hope it is better than the first edition (Score:4, Informative)
I ended up finding what I needed in the man pages for various memory-related system calls, and in the very good but older Interprocess Communications in Unix by John Gray.
What kind of IPC you really use? (Score:2)
I would like to know, what do you use in your apps?
Don't want to troll, but... where's the RAD? (Score:3, Interesting)
C'mon guys, where's the RAD for Linux?
Re:Don't want to troll, but... where's the RAD? (Score:2)
Here you go. [wxpython.org]
Re:Don't want to troll, but... where's the RAD? (Score:3, Interesting)
Seriously, the Unix "toolbox" metaphor is more powerful that people seem to realize. For one example of how the shell is often underestimated, take a look at The UNIX Shell As a Fourth Generation Language [rdb.com], by Evan Schaffer and Mike Wolf. That's from the 1980s.
Re:Don't want to troll, but... where's the RAD? (Score:2)
Re:Don't want to troll, but... where's the RAD? (Score:2)
I would have thought that a recently published book on application development would talk more about kdevelop and qtdesigner than emacs and vi.
Don't get me wrong. I use emacs every day. It's just that there are literally decades of books written about the "old school" way of command line application development. Do we really need another?
Re:Don't want to troll, but... where's the RAD? (Score:3, Interesting)
Same place it is for OS X, in the NeXTSTEP API.
see gnustep [gnustep.org]
I installed gnustep on my FreeBSD box last night and ported one of my Mac GUI apps in just a few minutes.
Re:Don't want to troll, but... where's the RAD? (Score:2)
http://www.amazon.com/exec/obidos/tg/detail/-/157 2 31995X/qid=1107987162/sr=8-4/ref=sr_8_xs_ap_i4_xgl 14/102-6770576-5407306?v=glance&s=books&n=507846 [amazon.com] (no referrer link or anything)
Re:Don't want to troll, but... where's the RAD? (Score:1)
Where's the open source Delphi ? or even Visual Basic ?
Actually there is a OS VB like environment, can't remeber its name offhand.
Re:Don't want to troll, but... where's the RAD? (Score:2)
It's called Qt and its found at TrollTech [trolltech.com]. I've used Delphi, VB (from versions 1 to 5) and Qt, I like Qt the best of all of them. Create your GUI graphically, define what signals and slots to hook up, write the functions and go. And you aren't stuck with BASIC or Pascal, two languages that should die.
Re:Don't want to troll, but... where's the RAD? (Score:2)
Gambas [sourceforge.net]. I really wish it wasn't based off of Basic, though.
Re:Don't want to troll, but... where's the RAD? (Score:2)
"development"? (Score:3, Funny)
Another must have... (Score:5, Funny)
Please, do not rely upon the "Linux Man Page Howto". For example, in the "few thoughts about documentation", the following guidelines are given:
Documentation must be accessible.
Documentation must be reliable and accurate.
What about "Documentation must be cryptic!!!" Face it - if you're going to go through the trouble of writing a man page, would you rather have your target audience read it once, or tens and hundreds of times!
Re:Another must have... (Score:2)
Ah hah! Perhaps the problem with Linux/Unix is that it requires the absorbtion of too many complex ideas.
Of my many frequent but short-lived encounters with Linux, I'd try to figure out how to do something. Invariably, I'd read the man page. Then, the topic under investigation would refer to some other cryptic term, which I'm sure is well understood by Linux experts, but not me. So then I'd have to research this other term.
The Art of Unix Programming.. (Score:2, Insightful)
http://www.faqs.org/docs/artu/ [faqs.org]
Its a "Linux Applications" Crazy-Tent Circus Par.. (Score:1)
as a linux application developer, 'linux' to me represents a wonderous toolset of marvel.
much as it may pain to state the obvious, the joy to be had in building your own entire OS; literally choosing only the bits you need for your application, cannot be under-valued.
weird to think of it (its gone so fast) but for 10 years i've been designing and building custom linux systems for a living
Mono GTK+ apps (Score:2, Informative)
Here are my links:
I recommend it! (Score:1)
Already one the first edition (Score:1)
I also own an electronic version so I don't have to take it with me when I have to go out on a job.
If the second edition is as good as the first then I'd advise everybody to get a copy.
autotools ? (Score:3, Insightful)
Huh ? At this time and age, no mention of automake/autoconf at all or did the review just skip that part ?
Who in their right mind still uses handwritten makefiles ?
Re:autotools ? (Score:2)
Autoconf is painful but is still useful. automake is just unneccessary pain.
Sophisticated? (Score:3, Insightful)
Is it sophisticated or poorly designed? Has anyone ever seen an X Application that looked and felt as nice as a native Windows (or Mac OS X) application? Has anyone ever gotten stuff like drag/drop between applications or ICCCM [tronche.com] to work correctly? I'd say it's far from sophisticated--it's clunky, ill conceived, and hard to apply effectively.
Re:Magic (Score:3, Interesting)
Re:Magic (Score:5, Insightful)
Maybe the author feels that in order to get the most out of a chapter about writing secture programs you first need a good base in the things discussed in earlier chapters.
Re:Magic (Score:1)
You gotta understand the concepts before you understand the dangers associated with them.
Re:Magic (Score:2)
I'd probably approach it using shared memory, a cron job, and packets with low TTLs.
Re:Magic (Score:2)
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
struct thread_info
{
pthread_t id;
pthread_mutex_t lock;
pthread_cond_t cond;
int ch;
struct thread_info *next_thread;
};
void *do_thread(void *arg)
{
struct thread_info *inf = (struct thread_info *)arg;
pthread_cond_wait(&inf->cond, &inf->lock);
printf("%c", inf->ch);
if(inf->next_thread)
{
pthread_mutex_lock(&inf
Re:Magic (Score:2)
(I thought about doing something totally ridiculous, like having the-msg be a red-black tree indexed by the Nth prime number, but then I realized that would be totally ridiculous)
Re:Magic (Score:2)
Re:Magic (Score:2, Insightful)
Re:Magic (Score:2, Funny)
My guess is hes an MCSE =)
Re:Magic (Score:1)
NO! It is the FARGATE! It is not some other kind of gate from a movie or TV show that I've never seen! Notice that it has a wheelchair and a pink mohawk? We're not getting sued!
No, it is a Fargate! From the makers of Findependence Day!
(Sorry, obligatory ATHF remark)
Re:Magic (Score:2)
Re:Magic (Score:2)
Re:Magic (Score:1)
Re:The dedication turned me off. (Score:4, Insightful)
But proselytization about the evils of proselytization is not? Here you are, in an article about a technical topic, ranting about religion? I'd say that's inappropriate proselytizing, no?
Further:
1. This is not a "science text." Not by any reasonable definition of science.
2. The dedication is a personal statement. It is directed at the dedicatee, not you.
Re:The dedication turned me off. (Score:3, Insightful)
So Mr. Johnson was not proselytizing. There was nothing in his dedication that attempted to sway you to his belief system. His grandmother may have been but even that is debatable since she was simply leading by example.
I picked up a number of computer books from my shelf and about half of them had dedications. Some mentioned "love", one mentioned "l
Re:The dedication turned me off. (Score:1, Offtopic)
CLI is an INTERFACE. (Score:2)
Re:CLI is an INTERFACE. (Score:1)
Okay, well
That's why I say that the command line has been exhausted. All the useful command-line programs have been written. We've moved on to tasks that can't be done on the co
Re:CLI is an INTERFACE. (Score:2)
This depends on your definition of "interface." Consider gnuplot. It's a command-line driven program but it displays its graphs in an X window. However, it can also save graphs to PNG files or other formats instead of displaying in a window. Is it, or is it not, a "GUI interface?" I'd say not.
That's why I say that the command line has been exhausted. All the useful command-line programs have b
Oh yeah? What's this, then? (Score:3, Informative)
You're either a troll or a dimwit.
That's odd, I spend a LOT of time writing code that ends up in command-line programs. I wonder how I do that, given that you say there's no room for such a thing.
Just take a look on the open-source project where I write the most code, mjpegtools [sourceforge.net]. It's the open-source MPEG2-video (i.e. DVD) creation package. You'll have to look at the CVS version [sourceforge.net] to see my latest contribution, t
What? (Score:2)
Would you like a clue?
Compressor, Cleaner... say I wonder if I can download a free copy of those to run on my Solaris box.
No? Well, it's back to handrolling an implementation from the ITU MPEG-2 reference documents.
I guess mjpegtools is USELESS then...
Embedded... (Score:3, Insightful)
(from someone who does embedded software development).
Re:Isn't it time to move on? (Score:3, Insightful)
It seems there is an entire generation of programmers that think that everything they write has to have a user interface. The beauty of command line utilities, interpreted
Re:Isn't it time to move on? (Score:2)
Re:Isn't it time to move on? (Score:2)
If you're in
Re:Isn't it time to move on? (Score:2)
> you're doing is not a "basic application
> parameter," or you're going about changing it in
> about the worst possible way. "Man, my car ran out
> of gas! I had to remove the fuel filter, pump gas
> back INTO the tank, then quickly replace the
> filter before it all ran onto the pavement again."
Try this for starters. In Win2k, find out how to change the W32Time service to update via the system clock via an NTP server.
> In any case, your
Re:Isn't it time to move on? (Score:2)
Not when you consider Apple's bi-polar position on providing servers (although they seemed to have settled down now) and their lousy support compared to their competitors.
For what it's worth, I sysadmin a bunch of Windows XP boxes at a hospital where we couldn't run MacOS even if we wanted. And I've always just downloaded a 100k utility to set Windows 2000 or 98 or whatnot to change the time based on an NTP server... that s
Re:Isn't it time to move on? (Score:2)
I think there is a world market for maybe five new command line applications.