Skip to main content

Beginning Linux Programming, 2nd Edition

Beginning Linux Programming, 2nd Edition

Richard Stones, Neil Matthew, Alan Cox (Foreword by)

ISBN: 978-0-764-54373-9

Jan 2000

1008 pages

Select type: Paperback

Product not available for purchase


What is this book about?

If you've installed Linux, or have access to a version of UNIX, you've probably gotten used to the environment and its configuration, but if you want to start programming, most Linux books leave you on your own. This book takes off where they stop, showing you how to make the most of the tools UNIX offers (which are included as standard with any distribution of Linux) and start programming UNIX for real.

Beginning Linux Programming, 2nd Edition, concentrates on C programming, looking at the GNU tools, and the UNIX C libraries, to teach you step by step how to write, build, and debug serious application code. Throughout the book, you develop a fully featured CD Database application, allowing you to see the theory of each new topic applied to a real application. As well as handling basic file operations, input and output and dealing with the way UNIX handles data, you discover such advanced topics as inter-process communication, networking, and using CGI scripting to build a Web interface — all the elements of client-server programming. You are also introduced the GTK+ and you find out how to build rich graphical user interfaces for X with GNOME. Finally, there's an introduction to device drivers, to give you a window into the way the Linux kernel itself works.

You'll also learn shell scripting for BASH, as well as two more powerful scripting languages — Tcl and Perl.

What does this book cover?

  • The Perl language
  • Programmming for GNOME(TM)
  • POSIX(r) threads
  • Kernel(r) programming
  • Latest Linux kernel, current tools and C libraries

Who is this book for?

You need to be comfortable with the basics of using Linux, with a good working knowledge of how to use and configure your system. You should also know some simple C. If you're familiar with basic programming concepts, the working examples in the book will soon give you the confidence to explore Linux's C libraries.

You'll find the programming tools used in this book are included with virtually any Linux distribution, so this book is all you need to get started as a Linux programmer.



Chapter 1. Getting Started.

Chapter 2. Shell Programming.

Chapter 3. Working with Files.

Chapter 4. The UNIX Environment.

Chapter 5. Terminals.

Chapter 6. Curses.

Chapter 7. Data Management.

Chapter 8. Development Tools.

Chapter 9. Debugging.

Chapter 10. Processes and Signals.

Chapter 11. POSIX Threads.

Chapter 12. Inter-process Communication: Pipes.

Chapter 13. Semaphores, Message Queues and Shared Memory.

Chapter 14. Sockets.

Chapter 15. Tcl: Tool Command Language.

Chapter 16. Programming for X.

Chapter 17. Programming GNOME using GTK+.

Chapter 18. The Perl Programming Language.

Chapter 19. Programming for the Internet: HTML.

Chapter 20. Internet Programming 2: CGI.

Chapter 21. Device Drivers.

Appendix A. Portability.

Appendix B. FSF and the GNU Project.

Appendix C. Internet Resources.

Appendix D. Bibliography.


Download source code tarball - gunzip, then tar -xvf to extract
ChapterPageDetailsDatePrint Run
0'Gnome clock' code - missing brackets around the else statement

Page 665, point no. 12, 'else' section of code - braces missing.

  gnome_canvas_item_set (hand, "points", points, NULL);
  gnome_canvas_item_set (second_hand, "points", second_hand_points, NULL);

234file mstakenly named as 'first' in code bundle

The script is provided in the code bundle available for download, with the name 'first'. It should be renamed to ''.


240File try_variables named as try_var in code bundle

The file try_variables is provided with the name try_var in the code bundle avaible online for download.


128ISO/ANSI C states that main() must return int

Line 16:

It is stated that:
"Although ISO/ANSI C leaves open the return type of main (it may be void or int)....

In fact, ISO/ANSI C states that main() must return int.

Thanks to Jordan Katz for spotting this.


137Current Date and Time / Code gmtime.c

The current year, as returned by the code in the program, is the number of years past the year 1900. This looks strange for years past 2000. Adding 1900 to the result gives a more comprehendible result, like 2002, for that year, instead of 102, as would be returned by the code in the book.

#include <stdio.h>
#include <time.h>
int main ()
struct tm *tm_ptr;
time_t the_time;

(void) time(&the_time);
tm_ptr = gmtime(&the_time);
printf("Raw time is %ld \n", the_time);
printf("gmtime gives :\n");

printf("date: %04d/%02d/%02d\n", tm_ptr->tm_year+1900, tm_ptr->tm_mon+1,tm_ptr->tm_mday);
printf("time: %02d/%02d/%02d\n", tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec);

141strftime: complier warning

Patch for code section strftime.c (required on Linux, where the the prototype for strptime() is not seen). Addition made to code - #define _XOPEN_SOURCE Without this, compling on Linux would produce the following warning: assignment makes pointer from integer without a cast


#include <time.h>
#include <stdio.h>

int main()
    struct tm *tm_ptr, timestruct;
    time_t the_time;
    char buf[256];
    char *result;

    (void) time(&the_time);
    tm_ptr = localtime(&the_time);
    strftime(buf, 256, "%A %d %B, %I:%S %p", tm_ptr);

    printf("strftime gives: %s\n", buf);

    strcpy(buf,"Mon 26 July 1999, 17:53 will do fine");

    printf("calling strptime with: %s\n", buf);
    tm_ptr = &timestruct;

    result = strptime(buf,"%a %d %b %Y, %R",tm_ptr);
    printf("strptime consumed up to: %s\n", result);

    printf("strptime gives:\n");
    printf("date: %02d/%02d/%02d\n",
    tm_ptr->tm_year, tm_ptr->tm_mon+1,tm_ptr->tm_mday);
    printf("time: %02d:%02d\n",tm_ptr->tm_hour, tm_ptr->tm_min);    

10354char* const

In the exec function to start the ps program, the line:
const char *ps_argv[]="{"ps", "-ax", 0}";
needs to be replaced by:
char * const ps_argv[]="{"ps", "-ax", 0}";


366Misplaced word

Line 5:
"Ctrl-C, which." should be "Ctrl-C."


367missing piece of code
Line 25:
The code in step number 2 should start with the following (before pid_t pid;)

int main()

380 Spelling Errors

Line 13:
"where" should be "were"

Line 22:
"it's" should be "its"


389Change in the text

The first sentence (4th prragraph) is "It is to overlook subtle timing faults". It should be "A common source of problem is to overlook subtle timing faults"