Details

Beginning Linux Programming


Beginning Linux Programming


4. Aufl.

von: Neil Matthew, Richard Stones

27,99 €

Verlag: Wiley
Format: PDF
Veröffentl.: 23.10.2007
ISBN/EAN: 9780470249130
Sprache: englisch
Anzahl Seiten: 816

DRM-geschütztes eBook, Sie benötigen z.B. Adobe Digital Editions und eine Adobe ID zum Lesen.

Beschreibungen

<b>Beginning Linux Programming,</b> Fourth Edition continues its unique approach to teaching UNIX programming in a simple and structured way on the Linux platform. Through the use of detailed and realistic examples, students learn by doing, and are able to move from being a Linux beginner to creating custom applications in Linux. The book introduces fundamental concepts beginning with the basics of writing Unix programs in C, and including material on basic system calls, file I/O, interprocess communication (for getting programs to work together), and shell programming. Parallel to this, the book introduces the toolkits and libraries for working with user interfaces, from simpler terminal mode applications to X and GTK+ for graphical user interfaces. Advanced topics are covered in detail such as processes, pipes, semaphores, socket programming, using MySQL, writing applications for the GNOME or the KDE desktop, writing device drivers, POSIX Threads, and kernel programming for the latest Linux Kernel.
<p>Acknowledgements x</p> <p>Foreword xxiii</p> <p>Introduction xxv</p> <p><b>Chapter 1: Getting Started 1</b></p> <p>An Introduction to UNIX, Linux, and GNU 1</p> <p>What Is UNIX? 1</p> <p>What Is Linux? 3</p> <p>The GNU Project and the Free Software Foundation 3</p> <p>Linux Distributions 4</p> <p>Programming Linux 4</p> <p>Linux Programs 5</p> <p>Text Editors 6</p> <p>The C Compiler 7</p> <p>Development System Roadmap 8</p> <p>Getting Help 14</p> <p>Summary 16</p> <p><b>Chapter 2: Shell Programming 17</b></p> <p>Why Program with a Shell? 18</p> <p>A Bit of Philosophy 18</p> <p>What Is a Shell? 19</p> <p>Pipes and Redirection 21</p> <p>Redirecting Output 21</p> <p>Redirecting Input 22</p> <p>Pipes 22</p> <p>The Shell as a Programming Language 23</p> <p>Interactive Programs 23</p> <p>Creating a Script 24</p> <p>Making a Script Executable 25</p> <p>Shell Syntax 27</p> <p>Variables 27</p> <p>Conditions 31</p> <p>Control Structures 34</p> <p>Functions 46</p> <p>Commands 49</p> <p>Command Execution 68</p> <p>Here Documents 73</p> <p>Debugging Scripts 74</p> <p>Going Graphical — The dialog Utility 75</p> <p>Putting It All Together 81</p> <p>Requirements 82</p> <p>Design 82</p> <p>Summary 91</p> <p><b>Chapter 3: Working with Files 93</b></p> <p>Linux File Structure 94</p> <p>Directories 94</p> <p>Files and Devices 95</p> <p>System Calls and Device Drivers 96</p> <p>Library Functions 97</p> <p>Low-Level File Access 98</p> <p>write 98</p> <p>read 99</p> <p>open 100</p> <p>Initial Permissions 101</p> <p>Other System Calls for Managing Files 106</p> <p>The Standard I/O Library 109</p> <p>fopen 110</p> <p>fread 110</p> <p>fwrite 111</p> <p>fclose 111</p> <p>fflush 111</p> <p>fseek 112</p> <p>fgetc, getc, and getchar 112</p> <p>fputc, putc, and putchar 112</p> <p>fgets and gets 113</p> <p>Formatted Input and Output 113</p> <p>printf, fprintf, and sprintf 113</p> <p>scanf, fscanf, and sscanf 115</p> <p>Other Stream Functions 117</p> <p>Stream Errors 119</p> <p>Streams and File Descriptors 119</p> <p>File and Directory Maintenance 120</p> <p>chmod 120</p> <p>chown 120</p> <p>unlink, link, and symlink 121</p> <p>mkdir and rmdir 121</p> <p>chdir and getcwd 122</p> <p>Scanning Directories 122</p> <p>opendir 123</p> <p>readdir 123</p> <p>telldir 123</p> <p>seekdir 124</p> <p>closedir 124</p> <p>Errors 127</p> <p>strerror 127</p> <p>perror 127</p> <p>The /proc File System 128</p> <p>Advanced Topics: fcntl and mmap 132</p> <p>fcntl 132</p> <p>mmap 133</p> <p>Summary 135</p> <p><b>Chapter 4: The Linux Environment 137</b></p> <p>Program Arguments 137</p> <p>getopt 140</p> <p>getopt_long 142</p> <p>Environment Variables 144</p> <p>Use of Environment Variables 146</p> <p>The environ Variable 147</p> <p>Time and Date 148</p> <p>Temporary Files 156</p> <p>User Information 158</p> <p>Host Information 161</p> <p>Logging 163</p> <p>Resources and Limits 167</p> <p>Summary 173</p> <p><b>Chapter 5: Terminals 175</b></p> <p>Reading from and Writing to the Terminal 175</p> <p>Talking to the Terminal 180</p> <p>The Terminal Driver and the General Terminal Interface 182</p> <p>Overview 183</p> <p>Hardware Model 183</p> <p>The termios Structure 184</p> <p>Input Modes 186</p> <p>Output Modes 186</p> <p>Control Modes 187</p> <p>Local Modes 188</p> <p>Special Control Characters 188</p> <p>Terminal Speed 192</p> <p>Additional Functions 192</p> <p>Terminal Output 196</p> <p>Terminal Type 197</p> <p>Identify Your Terminal Type 197</p> <p>Using terminfo Capabilities 200</p> <p>Detecting Keystrokes 205</p> <p>Virtual Consoles 207</p> <p>Pseudo-Terminals 208</p> <p>Summary 209</p> <p><b>Chapter 6: Managing Text-Based Screens with curses 211</b></p> <p>Compiling with curses 212</p> <p>Curses Terminology and Concepts 213</p> <p>The Screen 216</p> <p>Output to the Screen 216</p> <p>Reading from the Screen 217</p> <p>Clearing the Screen 218</p> <p>Moving the Cursor 218</p> <p>Character Attributes 218</p> <p>The Keyboard 221</p> <p>Keyboard Modes 221</p> <p>Keyboard Input 222</p> <p>Windows 224</p> <p>The WINDOW Structure 224</p> <p>Generalized Functions 225</p> <p>Moving and Updating a Window 225</p> <p>Optimizing Screen Refreshes 229</p> <p>Subwindows 230</p> <p>The Keypad 232</p> <p>Using Color 235</p> <p>Redefining Colors 238</p> <p>Pads 238</p> <p>The CD Collection Application 240</p> <p>Starting a New CD Collection Application 240</p> <p>Looking at main 243</p> <p>Building the Menu 243</p> <p>Database File Manipulation 245</p> <p>Querying the CD Database 250</p> <p>Summary 254</p> <p><b>Chapter 7: Data Management 255</b></p> <p>Managing Memory 255</p> <p>Simple Memory Allocation 256</p> <p>Allocating Lots of Memory 257</p> <p>Abusing Memory 260</p> <p>The Null Pointer 261</p> <p>Freeing Memory 262</p> <p>Other Memory Allocation Functions 264</p> <p>File Locking 264</p> <p>Creating Lock Files 265</p> <p>Locking Regions 268</p> <p>Use of read and write with Locking 271</p> <p>Competing Locks 276</p> <p>Other Lock Commands 280</p> <p>Deadlocks 280</p> <p>Databases 281</p> <p>The dbm Database 281</p> <p>The dbm Routines 283</p> <p>dbm Access Functions 283</p> <p>Additional dbm Functions 287</p> <p>The CD Application 289</p> <p>Updating the Design 289</p> <p>The CD Database Application Using dbm 290</p> <p>Summary 309</p> <p><b>Chapter 8: MySQL 311</b></p> <p>Installation 312</p> <p>MySQL Packages 312</p> <p>Post-Install Configuration 314</p> <p>Post-Installation Troubleshooting 319</p> <p>MySQL Administration 320</p> <p>Commands 320</p> <p>Creating Users and Giving Them Permissions 325</p> <p>Passwords 327</p> <p>Creating a Database 328</p> <p>Data Types 329</p> <p>Creating a Table 330</p> <p>Graphical Tools 333</p> <p>Accessing MySQL Data from C 335</p> <p>Connection Routines 337</p> <p>Error Handling 341</p> <p>Executing SQL Statements 342</p> <p>Miscellaneous Functions 357</p> <p>The CD Database Application 358</p> <p>Creating the Tables 359</p> <p>Adding Some Data 362</p> <p>Accessing the Application Data from C 364</p> <p>Summary 375</p> <p><b>Chapter 9: Development Tools 377</b></p> <p>Problems of Multiple Source Files 377</p> <p>The make Command and Makefiles 378</p> <p>The Syntax of Makefiles 378</p> <p>Options and Parameters to make 379</p> <p>Comments in a Makefile 382</p> <p>Macros in a Makefile 382</p> <p>Multiple Targets 384</p> <p>Built-in Rules 387</p> <p>Suffix and Pattern Rules 388</p> <p>Managing Libraries with make 389</p> <p>Advanced Topic: Makefiles and Subdirectories 391</p> <p>GNU make and gcc 391</p> <p>Source Code Control 392</p> <p>RCS 393</p> <p>SCCS 399</p> <p>Comparing RCS and SCCS 399</p> <p>CVS 400</p> <p>CVS Front Ends 404</p> <p>Subversion 405</p> <p>Writing a Manual Page 406</p> <p>Distributing Software 409</p> <p>The patch Program 410</p> <p>Other Distribution Utilities 411</p> <p>RPM Packages 413</p> <p>Working with RPM Package Files 414</p> <p>Installing RPM Packages 415</p> <p>Building RPM Packages 415</p> <p>Other Package Formats 424</p> <p>Development Environments 424</p> <p>KDevelop 425</p> <p>Other Environments 425</p> <p>Summary 427</p> <p><b>Chapter 10: Debugging 429</b></p> <p>Types of Errors 429</p> <p>General Debugging Techniques 430</p> <p>A Program with Bugs 430</p> <p>Code Inspection 433</p> <p>Instrumentation 434</p> <p>Controlled Execution 436</p> <p>Debugging with gdb 437</p> <p>Starting gdb 437</p> <p>Running a Program 438</p> <p>Stack Trace 438</p> <p>Examining Variables 439</p> <p>Listing the Program 440</p> <p>Setting Breakpoints 441</p> <p>Patching with the Debugger 444</p> <p>Learning More about gdb 445</p> <p>More Debugging Tools 445</p> <p>Lint: Removing the Fluff from Your Programs 446</p> <p>Function Call Tools 449</p> <p>Execution Profiling with prof/gprof 451</p> <p>Assertions 452</p> <p>Memory Debugging 453</p> <p>ElectricFence 454</p> <p>valgrind 455</p> <p>Summary 459</p> <p><b>Chapter 11: Processes and Signals 461</b></p> <p>What Is a Process? 461</p> <p>Process Structure 462</p> <p>The Process Table 463</p> <p>Viewing Processes 463</p> <p>System Processes 464</p> <p>Process Scheduling 467</p> <p>Starting New Processes 468</p> <p>Waiting for a Process 475</p> <p>Zombie Processes 477</p> <p>Input and Output Redirection 479</p> <p>Threads 480</p> <p>Signals 481</p> <p>Sending Signals 484</p> <p>Signal Sets 489</p> <p>Summary 493</p> <p><b>Chapter 12: POSIX Threads 495</b></p> <p>What Is a Thread? 495</p> <p>Advantages and Drawbacks of Threads 496</p> <p>A First Threads Program 497</p> <p>Simultaneous Execution 501</p> <p>Synchronization 503</p> <p>Synchronization with Semaphores 503</p> <p>Synchronization with Mutexes 508</p> <p>Thread Attributes 512</p> <p>Canceling a Thread 517</p> <p>Threads in Abundance 520</p> <p>Summary 524</p> <p><b>Chapter 13: Inter-Process Communication: Pipes 525</b></p> <p>What Is a Pipe? 525</p> <p>Process Pipes 526</p> <p>Sending Output to popen 528</p> <p>Passing More Data 529</p> <p>How popen Is Implemented 530</p> <p>The Pipe Call 531</p> <p>Parent and Child Processes 535</p> <p>Reading Closed Pipes 536</p> <p>Pipes Used as Standard Input and Output 537</p> <p>Named Pipes: FIFOs 540</p> <p>Accessing a FIFO 542</p> <p>Advanced Topic: Client/Server Using FIFOs 549</p> <p>The CD Database Application 553</p> <p>Aims 554</p> <p>Implementation 555</p> <p>Client Interface Functions 558</p> <p>The Server Interface, server.c 565</p> <p>The Pipe 569</p> <p>Application Summary 574</p> <p>Summary 575</p> <p><b>Chapter 14: Semaphores, Shared Memory, and Message Queues 577</b></p> <p>Semaphores 577</p> <p>Semaphore Definition 579</p> <p>A Theoretical Example 579</p> <p>Linux Semaphore Facilities 580</p> <p>Using Semaphores 582</p> <p>Shared Memory 586</p> <p>shmget 588</p> <p>shmat 588</p> <p>shmdt 589</p> <p>shmctl 589</p> <p>Message Queues 594</p> <p>msgget 594</p> <p>msgsnd 595</p> <p>msgrcv 595</p> <p>msgctl 596</p> <p>The CD Database Application 599</p> <p>Revising the Server Functions 600</p> <p>Revising the Client Functions 602</p> <p>IPC Status Commands 604</p> <p>Displaying Semaphore Status 604</p> <p>Displaying Shared Memory Status 604</p> <p>Displaying Message Queue Status 605</p> <p>Summary 605</p> <p><b>Chapter 15: Sockets 607</b></p> <p>What Is a Socket? 608</p> <p>Socket Connections 608</p> <p>Socket Attributes 612</p> <p>Creating a Socket 614</p> <p>Socket Addresses 615</p> <p>Naming a Socket 616</p> <p>Creating a Socket Queue 617</p> <p>Accepting Connections 617</p> <p>Requesting Connections 618</p> <p>Closing a Socket 619</p> <p>Socket Communications 619</p> <p>Host and Network Byte Ordering 622</p> <p>Network Information 624</p> <p>The Internet Daemon (xinetd/inetd) 629</p> <p>Socket Options 631</p> <p>Multiple Clients 632</p> <p>select 635</p> <p>Multiple Clients 638</p> <p>Datagrams 642</p> <p>Summary 644</p> <p><b>Chapter 16: Programming GNOME Using GTK+ 645</b></p> <p>Introducing X 645</p> <p>X Server 646</p> <p>X Client 646</p> <p>X Protocol 646</p> <p>Xlib 647</p> <p>Toolkits 647</p> <p>Window Managers 647</p> <p>Other Ways to Create a GUI — Platform-Independent Windowing APIs 648</p> <p>Introducing GTK+ 648</p> <p>GLib Type System 649</p> <p>GTK+ Object System 650</p> <p>Introducing GNOME 651</p> <p>Installing the GNOME/GTK+ Development Libraries 652</p> <p>Events, Signals, and Callbacks 655</p> <p>Packing Box Widgets 658</p> <p>GTK+ Widgets 661</p> <p>GtkWindow 662</p> <p>GtkEntry 663</p> <p>GtkSpinButton 666</p> <p>GtkButton 668</p> <p>GtkTreeView 672</p> <p>GNOME Widgets 676</p> <p>GNOME Menus 677</p> <p>Dialogs 682</p> <p>GtkDialog 682</p> <p>Modal Dialog Box 684</p> <p>Nonmodal Dialogs 685</p> <p>GtkMessageDialog 686</p> <p>CD Database Application 687</p> <p>Summary 699</p> <p><b>Chapter 17: Programming KDE Using Qt 701</b></p> <p>Introducing KDE and Qt 701</p> <p>Installing Qt 702</p> <p>Signals and Slots 705</p> <p>Qt Widgets 712</p> <p>QLineEdit 712</p> <p>Qt Buttons 716</p> <p>QComboBox 721</p> <p>QListView 724</p> <p>Dialogs 727</p> <p>QDialog 728</p> <p>QMessageBox 730</p> <p>QInputDialog 731</p> <p>Using qmake to Simplify Writing Makefiles 733</p> <p>Menus and Toolbars with KDE 733</p> <p>CD Database Application Using KDE/Qt 738</p> <p>MainWindow 738</p> <p>AddCdDialog 742</p> <p>LogonDialog 743</p> <p>main.cpp 745</p> <p>Summary 746</p> <p><b>Chapter 18: Standards for Linux 747</b></p> <p>The C Programming Language 748</p> <p>A Brief History Lesson 748</p> <p>The GNU Compiler Collection 749</p> <p>gcc Options 749</p> <p>Interfaces and the Linux Standards Base 751</p> <p>LSB Standard Libraries 752</p> <p>LSB Users and Groups 754</p> <p>LSB System Initialization 754</p> <p>The Filesystem Hierarchy Standard 755</p> <p>Further Reading about Standards 758</p> <p>Summary 759</p> <p>Index 761</p>
<b>Neil Matthew</b> 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.<br />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.<br />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. <p><b>Rick Stones</b> 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.<br />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.<br />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.)</p>
<p><b>Beginning Linux<sup>®</sup> Programming 4th Edition</b> <p>Building on the success of its previous editions, this must-have guide continues its popular tutorial approach and brings you a straightforward introduction to developing programs for Linux and other UNIX-style operating systems. The author duo of experienced Linux programmers covers a wide range of topics to help you learn more about what Linux has to offer so you can maximize your programming time and your use of the Linux system. <p>You'll progress from the basics of compiling programs, linking to libraries, and dealing with terminal input and output to more advanced subjects such as writing applications for the GNOME<sup>®</sup> and KDE<sup>®</sup> environments, storing data using MySQL<sup>®</sup>, and debugging. As each topic is covered, the authors introduce an appropriate programming theory and then illustrate it with practical examples, clear explanations, and a step-by-step approach with the intent that you will learn by doing. You'll quickly evolve from being a Linux beginner to confidently creating custom applications in Linux. <p><b>What you will learn from this book</b> <ul> <li>How to use the standard Linux C libraries and other facilities</li> <li>Ways to make the most of the standard Linux development tools</li> <li>Tips on basic system calls, file I/O, interprocess communication, and shell programming </li> <li>How to build graphical user interfaces using the GTK+ or Qt toolkits</li> <li>Using sockets to support TCP/IP networking to different machines</li> <li>How to write programs that will work on different distributions of Linux</li> </ul> <p><b>Who this book is for</b> <p>This book is for programmers and developers who want to increase their skill level using Linux. Experience in C and/or C+ + programming is helpful. <p>Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing a structured, tutorial format that will guide you through all the techniques involved.

Diese Produkte könnten Sie auch interessieren:

Windows Vista For Dummies
Windows Vista For Dummies
von: Andy Rathbone
PDF ebook
15,99 €
Mastering Digital Audio Production
Mastering Digital Audio Production
von: Cliff Truesdell
PDF ebook
26,99 €