Beginning Linux Programming
Häftad, Engelska, 2007
Av Neil Matthew, Richard Stones, Celesio) Matthew, Neil (Northamptonshire, UK, Celesio) Stones, Richard (Leicestershire, UK
389 kr
Produktinformation
- Utgivningsdatum2007-11-02
- Mått188 x 235 x 40 mm
- Vikt1 320 g
- FormatHäftad
- SpråkEngelska
- Antal sidor816
- Upplaga4
- FörlagJohn Wiley & Sons Inc
- ISBN9780470147627
Tillhör följande kategorier
Neil Matthew has been interested in and has programmed computers since 1974. A mathematics graduate from the University of Nottingham, Neil is just plain keen on programming languages and likes to explore new ways of solving computing problems. He’s written systems to program in BCPL, FP (Functional Programming), Lisp, Prolog, and a structured BASIC. He even wrote a 6502 microprocessor emulator to run BBC microcomputer programs on UNIX systems. In terms of UNIX experience, Neil has used almost every flavor since the late 1970s, including BSD UNIX, AT&T System V, Sun Solaris, IBM AIX, many others, and of course Linux. He can claim to have been using Linux since August 1993 when he acquired a floppy disk distribution of Soft Landing (SLS) from Canada, with kernel version 0.99.11. He’s used Linux-based computers for hacking C, C++, Icon, Prolog, Tcl, and Java at home and at work.All of Neil’s "home" projects are developed using Linux. He says Linux is much easier because it supports quite a lot of features from other systems, so that both BSD- and System V-targeted programs will generally compile with little or no change.Neil is currently working as an Enterprise Architect specializing in IT strategy at Celesio AG. He has a background in technical consultancy, software development techniques, and quality assurance. Neil has also programmed in C and C++ for real-time embedded systems. Rick Stones started programming at school (more years ago than he cares to remember) on a 6502-powered BBC micro, which, with the help of a few spare parts, continued to function for the next 15 years. He graduated from Nottingham University with a degree in Electronic Engineering, but decided software was more fun.Over the years he has worked for a variety of companies, from the very small with just a dozen employees, to the very large, including the IT services giant EDS. Along the way he has worked on a range of projects, from real-time communications to accounting systems, to very large help desk systems. He is currently working as an IT architect, acting as a technical authority on various major projects for a large pan-European company.A bit of a programming linguist, he has programmed in various assemblers, a rather neat proprietary telecommunications language called SL-1, some FORTRAN, Pascal, Perl, SQL, and smidgeons of Python and C++, as well as C. (Under duress he even admits that he was once reasonably proficient in Visual Basic, but tries not to advertise this aberration.)
- Acknowledgements xForeword xxiiiIntroduction xxvChapter 1: Getting Started 1An Introduction to UNIX, Linux, and GNU 1What Is UNIX? 1What Is Linux? 3The GNU Project and the Free Software Foundation 3Linux Distributions 4Programming Linux 4Linux Programs 5Text Editors 6The C Compiler 7Development System Roadmap 8Getting Help 14Summary 16Chapter 2: Shell Programming 17Why Program with a Shell? 18A Bit of Philosophy 18What Is a Shell? 19Pipes and Redirection 21Redirecting Output 21Redirecting Input 22Pipes 22The Shell as a Programming Language 23Interactive Programs 23Creating a Script 24Making a Script Executable 25Shell Syntax 27Variables 27Conditions 31Control Structures 34Functions 46Commands 49Command Execution 68Here Documents 73Debugging Scripts 74Going Graphical — The dialog Utility 75Putting It All Together 81Requirements 82Design 82Summary 91Chapter 3: Working with Files 93Linux File Structure 94Directories 94Files and Devices 95System Calls and Device Drivers 96Library Functions 97Low-Level File Access 98write 98read 99open 100Initial Permissions 101Other System Calls for Managing Files 106The Standard I/O Library 109fopen 110fread 110fwrite 111fclose 111fflush 111fseek 112fgetc, getc, and getchar 112fputc, putc, and putchar 112fgets and gets 113Formatted Input and Output 113printf, fprintf, and sprintf 113scanf, fscanf, and sscanf 115Other Stream Functions 117Stream Errors 119Streams and File Descriptors 119File and Directory Maintenance 120chmod 120chown 120unlink, link, and symlink 121mkdir and rmdir 121chdir and getcwd 122Scanning Directories 122opendir 123readdir 123telldir 123seekdir 124closedir 124Errors 127strerror 127perror 127The /proc File System 128Advanced Topics: fcntl and mmap 132fcntl 132mmap 133Summary 135Chapter 4: The Linux Environment 137Program Arguments 137getopt 140getopt_long 142Environment Variables 144Use of Environment Variables 146The environ Variable 147Time and Date 148Temporary Files 156User Information 158Host Information 161Logging 163Resources and Limits 167Summary 173Chapter 5: Terminals 175Reading from and Writing to the Terminal 175Talking to the Terminal 180The Terminal Driver and the General Terminal Interface 182Overview 183Hardware Model 183The termios Structure 184Input Modes 186Output Modes 186Control Modes 187Local Modes 188Special Control Characters 188Terminal Speed 192Additional Functions 192Terminal Output 196Terminal Type 197Identify Your Terminal Type 197Using terminfo Capabilities 200Detecting Keystrokes 205Virtual Consoles 207Pseudo-Terminals 208Summary 209Chapter 6: Managing Text-Based Screens with curses 211Compiling with curses 212Curses Terminology and Concepts 213The Screen 216Output to the Screen 216Reading from the Screen 217Clearing the Screen 218Moving the Cursor 218Character Attributes 218The Keyboard 221Keyboard Modes 221Keyboard Input 222Windows 224The WINDOW Structure 224Generalized Functions 225Moving and Updating a Window 225Optimizing Screen Refreshes 229Subwindows 230The Keypad 232Using Color 235Redefining Colors 238Pads 238The CD Collection Application 240Starting a New CD Collection Application 240Looking at main 243Building the Menu 243Database File Manipulation 245Querying the CD Database 250Summary 254Chapter 7: Data Management 255Managing Memory 255Simple Memory Allocation 256Allocating Lots of Memory 257Abusing Memory 260The Null Pointer 261Freeing Memory 262Other Memory Allocation Functions 264File Locking 264Creating Lock Files 265Locking Regions 268Use of read and write with Locking 271Competing Locks 276Other Lock Commands 280Deadlocks 280Databases 281The dbm Database 281The dbm Routines 283dbm Access Functions 283Additional dbm Functions 287The CD Application 289Updating the Design 289The CD Database Application Using dbm 290Summary 309Chapter 8: MySQL 311Installation 312MySQL Packages 312Post-Install Configuration 314Post-Installation Troubleshooting 319MySQL Administration 320Commands 320Creating Users and Giving Them Permissions 325Passwords 327Creating a Database 328Data Types 329Creating a Table 330Graphical Tools 333Accessing MySQL Data from C 335Connection Routines 337Error Handling 341Executing SQL Statements 342Miscellaneous Functions 357The CD Database Application 358Creating the Tables 359Adding Some Data 362Accessing the Application Data from C 364Summary 375Chapter 9: Development Tools 377Problems of Multiple Source Files 377The make Command and Makefiles 378The Syntax of Makefiles 378Options and Parameters to make 379Comments in a Makefile 382Macros in a Makefile 382Multiple Targets 384Built-in Rules 387Suffix and Pattern Rules 388Managing Libraries with make 389Advanced Topic: Makefiles and Subdirectories 391GNU make and gcc 391Source Code Control 392RCS 393SCCS 399Comparing RCS and SCCS 399CVS 400CVS Front Ends 404Subversion 405Writing a Manual Page 406Distributing Software 409The patch Program 410Other Distribution Utilities 411RPM Packages 413Working with RPM Package Files 414Installing RPM Packages 415Building RPM Packages 415Other Package Formats 424Development Environments 424KDevelop 425Other Environments 425Summary 427Chapter 10: Debugging 429Types of Errors 429General Debugging Techniques 430A Program with Bugs 430Code Inspection 433Instrumentation 434Controlled Execution 436Debugging with gdb 437Starting gdb 437Running a Program 438Stack Trace 438Examining Variables 439Listing the Program 440Setting Breakpoints 441Patching with the Debugger 444Learning More about gdb 445More Debugging Tools 445Lint: Removing the Fluff from Your Programs 446Function Call Tools 449Execution Profiling with prof/gprof 451Assertions 452Memory Debugging 453ElectricFence 454valgrind 455Summary 459Chapter 11: Processes and Signals 461What Is a Process? 461Process Structure 462The Process Table 463Viewing Processes 463System Processes 464Process Scheduling 467Starting New Processes 468Waiting for a Process 475Zombie Processes 477Input and Output Redirection 479Threads 480Signals 481Sending Signals 484Signal Sets 489Summary 493Chapter 12: POSIX Threads 495What Is a Thread? 495Advantages and Drawbacks of Threads 496A First Threads Program 497Simultaneous Execution 501Synchronization 503Synchronization with Semaphores 503Synchronization with Mutexes 508Thread Attributes 512Canceling a Thread 517Threads in Abundance 520Summary 524Chapter 13: Inter-Process Communication: Pipes 525What Is a Pipe? 525Process Pipes 526Sending Output to popen 528Passing More Data 529How popen Is Implemented 530The Pipe Call 531Parent and Child Processes 535Reading Closed Pipes 536Pipes Used as Standard Input and Output 537Named Pipes: FIFOs 540Accessing a FIFO 542Advanced Topic: Client/Server Using FIFOs 549The CD Database Application 553Aims 554Implementation 555Client Interface Functions 558The Server Interface, server.c 565The Pipe 569Application Summary 574Summary 575Chapter 14: Semaphores, Shared Memory, and Message Queues 577Semaphores 577Semaphore Definition 579A Theoretical Example 579Linux Semaphore Facilities 580Using Semaphores 582Shared Memory 586shmget 588shmat 588shmdt 589shmctl 589Message Queues 594msgget 594msgsnd 595msgrcv 595msgctl 596The CD Database Application 599Revising the Server Functions 600Revising the Client Functions 602IPC Status Commands 604Displaying Semaphore Status 604Displaying Shared Memory Status 604Displaying Message Queue Status 605Summary 605Chapter 15: Sockets 607What Is a Socket? 608Socket Connections 608Socket Attributes 612Creating a Socket 614Socket Addresses 615Naming a Socket 616Creating a Socket Queue 617Accepting Connections 617Requesting Connections 618Closing a Socket 619Socket Communications 619Host and Network Byte Ordering 622Network Information 624The Internet Daemon (xinetd/inetd) 629Socket Options 631Multiple Clients 632select 635Multiple Clients 638Datagrams 642Summary 644Chapter 16: Programming GNOME Using GTK+ 645Introducing X 645X Server 646X Client 646X Protocol 646Xlib 647Toolkits 647Window Managers 647Other Ways to Create a GUI — Platform-Independent Windowing APIs 648Introducing GTK+ 648GLib Type System 649GTK+ Object System 650Introducing GNOME 651Installing the GNOME/GTK+ Development Libraries 652Events, Signals, and Callbacks 655Packing Box Widgets 658GTK+ Widgets 661GtkWindow 662GtkEntry 663GtkSpinButton 666GtkButton 668GtkTreeView 672GNOME Widgets 676GNOME Menus 677Dialogs 682GtkDialog 682Modal Dialog Box 684Nonmodal Dialogs 685GtkMessageDialog 686CD Database Application 687Summary 699Chapter 17: Programming KDE Using Qt 701Introducing KDE and Qt 701Installing Qt 702Signals and Slots 705Qt Widgets 712QLineEdit 712Qt Buttons 716QComboBox 721QListView 724Dialogs 727QDialog 728QMessageBox 730QInputDialog 731Using qmake to Simplify Writing Makefiles 733Menus and Toolbars with KDE 733CD Database Application Using KDE/Qt 738MainWindow 738AddCdDialog 742LogonDialog 743main.cpp 745Summary 746Chapter 18: Standards for Linux 747The C Programming Language 748A Brief History Lesson 748The GNU Compiler Collection 749gcc Options 749Interfaces and the Linux Standards Base 751LSB Standard Libraries 752LSB Users and Groups 754LSB System Initialization 754The Filesystem Hierarchy Standard 755Further Reading about Standards 758Summary 759Index 761