Cover image for Beginning Linux programming
Title:
Beginning Linux programming
Author:
Matthew, Neil.
Personal Author:
Edition:
Second edition, revised and updated with additional material.
Publication Information:
Birmingham, UK ; Chicago : Wrox Press, [1999]

©1999
Physical Description:
xxvii, 945 pages : illustrations ; 24 cm.
Language:
English
Title Subject:
ISBN:
9781861002976
Format :
Book

Available:*

Library
Call Number
Material Type
Home Location
Status
Item Holds
Searching...
QA76.76.O63 M3719 1999 Adult Non-Fiction Central Closed Stacks
Searching...

On Order

Summary

Summary

If you've already got Linux up and running on your machine and you really want to exploit its capabilities, Beginning Linux Programming is packed full of useful information that will keep you busy for weeks. In spite of its title, Beginning Linux Programming isn't oriented toward novices. It assumes that you're a competent C programmer but are simply new to the specifics of Linux. Authors Neil Matthew and Richard Stones introduce a plethora of fundamental concepts including shell programming, file access, and using curses to write full-screen, character-based programs. But that's just the start. They cover advanced topics such as processes, pipes, semaphores, and sockets - and of course, they address issues common to Internet programming such as using CGI (Common Gateway Interface). The book is a superb resource for anyone who has really wanted to put the pedal to the metal in Linux. This revised Second Edition has been completely updated, and now also covers: Programming in Perl Writing applications for the GNOME desktop Writing device drivers POSIX Threads Kernel Programming for the latest Linux Kernel and current tools and C libraries. Building on the proven success of the first


Table of Contents

Forewordp. xxix
Introductionp. 1
Chapter 1 Getting Startedp. 9
What is UNIX?p. 9
What is Linux?p. 10
Distributionsp. 10
The GNU Project and the Free Software Foundationp. 10
Programming Linuxp. 11
UNIX Programsp. 12
The C Compilerp. 13
Getting Helpp. 15
Development System Roadmapp. 17
Programsp. 17
Header Filesp. 17
Library Filesp. 18
Static Librariesp. 19
Shared Librariesp. 22
UNIX Philosophyp. 23
Simplicityp. 23
Focusp. 23
Reusable Componentsp. 23
Filtersp. 24
Open File Formatsp. 24
Flexibilityp. 24
Summaryp. 24
Chapter 2 Shell Programmingp. 27
What is a Shell?p. 28
Pipes and Redirectionp. 30
Redirecting Outputp. 30
Redirecting Inputp. 31
Pipesp. 31
The Shell as a Programming Languagep. 32
Interactive Programsp. 32
Creating a Scriptp. 34
Making a Script Executablep. 35
Shell Syntaxp. 36
Variablesp. 36
Conditionsp. 40
Control Structuresp. 43
Functionsp. 55
Commandsp. 58
Command Executionp. 70
Here Documentsp. 74
Debugging Scriptsp. 76
Putting it All Togetherp. 77
Requirementsp. 77
Designp. 77
Notesp. 86
Summaryp. 86
Chapter 3 Working with Filesp. 89
UNIX File Structurep. 90
Directoriesp. 90
Files and Devicesp. 91
System Calls and Device Driversp. 92
Library Functionsp. 93
Low-level File Accessp. 94
Other System Calls for Managing Filesp. 102
The Standard I/O Libraryp. 104
Formatted Input and Outputp. 108
Other Stream Functionsp. 112
Stream Errorsp. 113
Streams and File Descriptorsp. 114
File and Directory Maintenancep. 115
Scanning Directoriesp. 117
Errorsp. 121
Advanced Topicsp. 122
Summaryp. 125
Chapter 4 The UNIX Environmentp. 127
Program Argumentsp. 127
Environment Variablesp. 131
Time and Datep. 135
Temporary Filesp. 142
User Informationp. 143
Host Informationp. 146
Loggingp. 148
Resources and Limitsp. 152
Summaryp. 157
Chapter 5 Terminalsp. 159
Reading from and Writing to the Terminalp. 160
Handling Redirected Outputp. 162
Talking to the Terminalp. 164
The Terminal Driver and the General Terminal Interfacep. 166
Overviewp. 166
Hardware Modelp. 166
The termios Structurep. 167
Input Modesp. 169
Output Modesp. 169
Control Modesp. 170
Local Modesp. 171
Special Control Charactersp. 171
Terminal Speedp. 175
Additional Functionsp. 175
Terminal Outputp. 178
Terminal Typep. 178
Identify Your Terminal Typep. 179
Using terminfo Capabilitiesp. 182
Detecting Keystrokesp. 186
Pseudo Terminalsp. 188
Summaryp. 189
Chapter 6 Cursesp. 191
Compiling with cursesp. 192
Conceptsp. 193
Initialization and Terminationp. 195
Output to the Screenp. 196
Reading from the Screenp. 197
Clearing the Screenp. 197
Moving the Cursorp. 198
Character Attributesp. 198
The Keyboardp. 200
Keyboard Modesp. 200
Keyboard Inputp. 201
Windowsp. 202
The WINDOW Structurep. 203
Generalized Functionsp. 203
Moving and Updating a Windowp. 204
Optimizing Screen Refreshesp. 207
Subwindowsp. 208
The Keypadp. 210
Colorp. 213
Redefining Colorsp. 215
Padsp. 215
The CD Collection Applicationp. 217
Summaryp. 229
Chapter 7 Data Managementp. 231
Managing Memoryp. 231
Simple Memory Allocationp. 232
Allocating Lots of Memoryp. 233
Abusing Memoryp. 236
The Null Pointerp. 236
Freeing Memoryp. 238
Other Memory Allocation Functionsp. 239
File Lockingp. 239
Creating Lock Filesp. 240
Locking Regionsp. 243
Use of read and write with Lockingp. 246
Competing Locksp. 251
Other Lock Commandsp. 254
Deadlocksp. 254
Databasesp. 255
The dbm Databasep. 255
The dbm Routinesp. 256
dbm Access Functionsp. 257
Additional dbm Functionsp. 261
The CD Applicationp. 262
The CD Application Using dbmp. 263
Summaryp. 280
Chapter 8 Development Toolsp. 283
Problems of Multiple Source Filesp. 283
The make Command and Makefilesp. 284
The Syntax of Makefilesp. 284
Options and Parameters to makep. 285
Comments in a makefilep. 288
Macros in a makefilep. 288
Multiple Targetsp. 290
Built-in Rulesp. 292
Suffix Rulesp. 293
Managing Libraries with makep. 294
Advanced Topic: Makefiles and Subdirectoriesp. 296
GNU make and gccp. 297
Source Code Controlp. 298
RCSp. 298
SCCSp. 304
CVSp. 304
Writing a Manual Pagep. 309
Distributing Softwarep. 312
The patch Programp. 312
Other Distribution Utilitiesp. 314
Summaryp. 316
Chapter 9 Debuggingp. 319
Types of Errorp. 319
Specification Errorsp. 319
Design Errorsp. 319
Coding Errorsp. 320
General Debugging Techniquesp. 320
A Program with Bugsp. 320
Code Inspectionp. 323
Instrumentationp. 324
Controlled Executionp. 326
Debugging with gdbp. 327
Starting gdbp. 327
Running a Programp. 328
Stack Tracep. 329
Examining Variablesp. 329
Listing the Programp. 330
Setting Breakpointsp. 331
Patching with the Debuggerp. 334
Learning more about gdbp. 335
More Debugging Toolsp. 335
Lint: Removing the Fluff from Your Programsp. 336
Function Call Toolsp. 337
Execution Profilingp. 339
Assertionsp. 340
Problems with assertp. 340
Memory Debuggingp. 341
ElectricFencep. 342
Checkerp. 343
Resourcesp. 345
Summaryp. 345
Chapter 10 Processes and Signalsp. 347
What is a Process?p. 347
Process Structurep. 348
The Process Tablep. 349
Viewing Processesp. 349
System Processesp. 350
Process Schedulingp. 351
Starting New Processesp. 352
Waiting for a Processp. 358
Zombie Processesp. 360
Input and Output Redirectionp. 361
Threadsp. 363
Signalsp. 363
Sending Signalsp. 366
Signal Setsp. 371
Summaryp. 375
Chapter 11 POSIX Threadsp. 377
What is a Thread?p. 377
Advantages and Drawbacks of Threadsp. 378
Checking for Thread Supportp. 379
A First Threads Programp. 380
Simultaneous Executionp. 383
Synchronizationp. 385
Synchronization with Semaphoresp. 385
Synchronization with Mutexesp. 390
Thread Attributesp. 393
Canceling a Threadp. 397
Threads in Abundancep. 400
Summaryp. 403
Chapter 12 Inter-process Communication: Pipesp. 405
What is a Pipe?p. 405
Process Pipesp. 406
Sending Output to popenp. 408
The Pipe Callp. 411
Parent and Child Processesp. 414
Reading Closed Pipesp. 416
Pipes Used as Standard Input and Outputp. 416
Named Pipes: FIFOsp. 420
Accessing a FIFOp. 422
Advanced Topic: Client/Server using FIFOsp. 429
The CD Applicationp. 432
Aimsp. 433
Implementationp. 434
Client Interface Functionsp. 438
The Server Interfacep. 444
The Pipep. 447
Application Summaryp. 453
Summaryp. 454
Chapter 13 Semaphores, Message Queues and Shared Memoryp. 457
Semaphoresp. 457
Semaphore Definitionp. 458
A Theoretical Examplep. 458
UNIX Semaphore Facilitiesp. 459
Using Semaphoresp. 462
Semaphore Summaryp. 466
Shared Memoryp. 466
Overviewp. 466
Shared Memory Functionsp. 467
Shared Memory Summaryp. 473
Message Queuesp. 473
Overviewp. 473
Message Queue Functionsp. 474
Message Queue Summaryp. 479
The Applicationp. 479
IPC Status Commandsp. 483
Semaphoresp. 483
Shared Memoryp. 483
Message Queuesp. 484
Summaryp. 484
Chapter 14 Socketsp. 487
What is a Socket?p. 487
Socket Connectionsp. 488
Socket Attributesp. 491
Creating a Socketp. 493
Socket Addressesp. 494
Naming a Socketp. 495
Creating a Socket Queuep. 495
Accepting Connectionsp. 496
Requesting Connectionsp. 496
Closing a Socketp. 497
Socket Communicationsp. 497
Host and Network Byte Orderingp. 500
Network Informationp. 502
The Internet Daemonp. 506
Socket Optionsp. 507
Multiple Clientsp. 507
Selectp. 510
Multiple Clientsp. 513
Summaryp. 516
Chapter 15 Tcl: Tool Command Languagep. 519
A Tcl Overviewp. 519
Our First Tcl Programp. 519
Tcl Commandsp. 521
Variables and Valuesp. 521
Quoting and Substitutionp. 522
Calculationp. 525
Control Structuresp. 527
Error Handlingp. 529
String Operationsp. 530
Arraysp. 536
Listsp. 537
Proceduresp. 543
Input and Outputp. 544
A Tcl Programp. 548
Creating a New Tclp. 552
Tcl Extensionsp. 552
Expectp. 552
[incr Tcl]p. 553
TclXp. 553
Graphicsp. 553
Summaryp. 553
Chapter 16 Programming for Xp. 555
What is X?p. 555
X Toolkitsp. 557
X Window Managerp. 558
The X Programming Modelp. 558
Start Upp. 559
Main Loopp. 560
Clean Upp. 560
Fast Track X Programmingp. 561
The Tk Toolkitp. 561
Windows Programmingp. 563
Configuration Filesp. 565
More Commandsp. 565
Tk Widgetsp. 565
Tk's Built-in Dialogsp. 595
Color Schemesp. 598
Fontsp. 599
Bindingsp. 600
BindTagsp. 602
Geometry Managementp. 603
Focus and Navigationp. 606
Option Databasep. 608
Inter-application Communicationp. 609
Selectionp. 609
Clipboardp. 610
Window Managerp. 611
Dynamic/Static Loadingp. 612
Safe Tkp. 613
A Mega-Widgetp. 614
An Application Using the Tree Mega-Widgetp. 625
Tk Process Log Viewerp. 627
Internationalizationp. 637
Where Now?p. 638
Summaryp. 639
Chapter 17 Programming GNOME using GTK+p. 641
An Introduction to GNOMEp. 641
The GNOME Architecturep. 642
The GNOME Desktopp. 644
Programming in GNOME using GTK+p. 645
An Application in GNOMEp. 661
Summaryp. 671
Chapter 18 The Perl Programming Languagep. 673
An Introduction to Perlp. 673
Hello, Perlp. 674
Perl Variablesp. 675
Operators and Functionsp. 678
Regular Expressionsp. 683
Control Structures and Subroutinesp. 686
File Input and Outputp. 688
A Full Examplep. 690
Perl on the Command Linep. 696
Modulesp. 697
CPANp. 697
Installing a Modulep. 697
Documentation (perldoc)p. 698
Networkingp. 698
Databasesp. 699
The CD Database Revisitedp. 700
Summaryp. 704
Chapter 19 Programming for the Internet: HTMLp. 707
What is the World Wide Web?p. 707
Terminologyp. 708
Writing HTMLp. 710
A More Formal Look at HTMLp. 712
HTML Tagsp. 713
Imagesp. 720
Tablesp. 722
Anchors or Hyperlinksp. 726
Combining Anchors and Imagesp. 727
Non-HTML URLsp. 729
Anchors to Other Sitesp. 730
Authoring HTMLp. 732
Serving HTML Pagesp. 732
Networked HTML Overviewp. 733
Setting up a Serverp. 734
Clickable Mapsp. 734
Server-side Mapsp. 734
Client-side Mapsp. 735
Server-side Includesp. 736
Tips for Setting up WWW Pagesp. 739
Summaryp. 740
Chapter 20 Internet Programming 2: CGIp. 743
Form Elementsp. 744
The Form Tagp. 744
The Input Tagp. 744
The Select Tagp. 747
The Textarea Tagp. 747
A Sample Pagep. 747
Sending Information to the WWW Serverp. 751
Information Encodingp. 752
Server Programp. 752
Writing a Server-side CGI Programp. 753
CGI Programs Using Extended URLsp. 760
Decoding the Form Datap. 761
Returning HTML to the Clientp. 768
Tips and Tricksp. 771
Making Sure your CGI Program Exitsp. 771
Redirecting the Clientp. 772
Dynamic Graphicsp. 772
Hiding Context Informationp. 773
An Applicationp. 773
Perlp. 779
Summaryp. 785
Chapter 21 Device Driversp. 787
Devicesp. 788
Device Classesp. 788
User and Kernel Spacep. 789
Character devicesp. 795
File Operationsp. 796
A Sample Driver, Scharp. 798
How Schar Behavesp. 816
Reviewp. 816
Time and Jiffiesp. 817
Small Delaysp. 818
Timersp. 819
Giving up the Processorp. 821
Task Queuesp. 822
The Predefined Task Queuesp. 823
Reviewp. 825
Memory Managementp. 825
Virtual Memory Areasp. 826
Address Spacep. 826
Types of Memory Locationsp. 827
Getting Memory in Device Driversp. 827
Transferring Data Between User and Kernel Spacep. 830
Simple Memory Mappingp. 832
I/O Memoryp. 833
Assignment of Devices in Iomapp. 835
I/O Memory mmapp. 835
I/O Portsp. 838
Portabilityp. 839
Interrupt Handlingp. 839
The IRQ Handlerp. 842
Bottom Halvesp. 843
Reentrancyp. 844
Disabling Single Interruptsp. 845
Atomicityp. 846
Protecting Critical Sectionsp. 847
Block Devicesp. 848
Radimo -- A Simple RAM Disk Modulep. 849
Media Changep. 851
Ioctl for Block Devicesp. 852
The Request Functionp. 852
The Buffer Cachep. 855
Going Furtherp. 856
Debuggingp. 857
Oops Tracingp. 857
Debugging Modulesp. 859
The Magic Keyp. 859
Kernel Debugger - KDBp. 860
Remote Debuggingp. 860
General Notes on Debuggingp. 861
Portabilityp. 861
Data Typesp. 861
Endianessp. 861
Alignmentp. 862
Continuing the Questp. 862
Anatomy of the Kernel Sourcep. 863
Appendix A Portabilityp. 865
Language Portabilityp. 865
Hardware Portabilityp. 868
Moving to C++p. 872
Use the Compilerp. 872
Programs are Read by Peoplep. 873
Appendix B FSF and the GNU Projectp. 875
The GNU Projectp. 875
The GNU Public Licensep. 876
Appendix C Internet Resourcesp. 883
WWW Locationsp. 883
Linux Specificp. 883
Unix and General Programmingp. 885
HTML and HTTP Informationp. 887
Newsgroupsp. 889
General UNIX Groupsp. 889
Linux-specific Groupsp. 889
FTP Archive Sitesp. 889
URLs for the Tools Mentioned in Chapter 9p. 890
Appendix D Bibliographyp. 893
Standardsp. 893
Other Documentation and Resourcesp. 893
Books Worth a Lookp. 894
And Finally, Three Books to Read away from the Computerp. 897
Indexp. 899