43,50 €*
Versandkostenfrei per Post / DHL
Aktuell nicht verfügbar
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.
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(r) and KDE(r) environments, storing data using MySQL(r), 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.
What you will learn from this book
*
How to use the standard Linux C libraries and other facilities
*
Ways to make the most of the standard Linux development tools
*
Tips on basic system calls, file I/O, interprocess communication, and shell programming
*
How to build graphical user interfaces using the GTK+ or Qt toolkits
*
Using sockets to support TCP/IP networking to different machines
*
How to write programs that will work on different distributions of Linux
Who this book is for
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.
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.
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.
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(r) and KDE(r) environments, storing data using MySQL(r), 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.
What you will learn from this book
*
How to use the standard Linux C libraries and other facilities
*
Ways to make the most of the standard Linux development tools
*
Tips on basic system calls, file I/O, interprocess communication, and shell programming
*
How to build graphical user interfaces using the GTK+ or Qt toolkits
*
Using sockets to support TCP/IP networking to different machines
*
How to write programs that will work on different distributions of Linux
Who this book is for
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.
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.
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 x
Foreword xxiii
Introduction xxv
Chapter 1: Getting Started 1
An Introduction to UNIX, Linux, and GNU 1
What Is UNIX? 1
What Is Linux? 3
The GNU Project and the Free Software Foundation 3
Linux Distributions 4
Programming Linux 4
Linux Programs 5
Text Editors 6
The C Compiler 7
Development System Roadmap 8
Getting Help 14
Summary 16
Chapter 2: Shell Programming 17
Why Program with a Shell? 18
A Bit of Philosophy 18
What Is a Shell? 19
Pipes and Redirection 21
Redirecting Output 21
Redirecting Input 22
Pipes 22
The Shell as a Programming Language 23
Interactive Programs 23
Creating a Script 24
Making a Script Executable 25
Shell Syntax 27
Variables 27
Conditions 31
Control Structures 34
Functions 46
Commands 49
Command Execution 68
Here Documents 73
Debugging Scripts 74
Going Graphical - The dialog Utility 75
Putting It All Together 81
Requirements 82
Design 82
Summary 91
Chapter 3: Working with Files 93
Linux File Structure 94
Directories 94
Files and Devices 95
System Calls and Device Drivers 96
Library Functions 97
Low-Level File Access 98
write 98
read 99
open 100
Initial Permissions 101
Other System Calls for Managing Files 106
The Standard I/O Library 109
fopen 110
fread 110
fwrite 111
fclose 111
fflush 111
fseek 112
fgetc, getc, and getchar 112
fputc, putc, and putchar 112
fgets and gets 113
Formatted Input and Output 113
printf, fprintf, and sprintf 113
scanf, fscanf, and sscanf 115
Other Stream Functions 117
Stream Errors 119
Streams and File Descriptors 119
File and Directory Maintenance 120
chmod 120
chown 120
unlink, link, and symlink 121
mkdir and rmdir 121
chdir and getcwd 122
Scanning Directories 122
opendir 123
readdir 123
telldir 123
seekdir 124
closedir 124
Errors 127
strerror 127
perror 127
The /proc File System 128
Advanced Topics: fcntl and mmap 132
fcntl 132
mmap 133
Summary 135
Chapter 4: The Linux Environment 137
Program Arguments 137
getopt 140
getopt_long 142
Environment Variables 144
Use of Environment Variables 146
The environ Variable 147
Time and Date 148
Temporary Files 156
User Information 158
Host Information 161
Logging 163
Resources and Limits 167
Summary 173
Chapter 5: Terminals 175
Reading from and Writing to the Terminal 175
Talking to the Terminal 180
The Terminal Driver and the General Terminal Interface 182
Overview 183
Hardware Model 183
The termios Structure 184
Input Modes 186
Output Modes 186
Control Modes 187
Local Modes 188
Special Control Characters 188
Terminal Speed 192
Additional Functions 192
Terminal Output 196
Terminal Type 197
Identify Your Terminal Type 197
Using terminfo Capabilities 200
Detecting Keystrokes 205
Virtual Consoles 207
Pseudo-Terminals 208
Summary 209
Chapter 6: Managing Text-Based Screens with curses 211
Compiling with curses 212
Curses Terminology and Concepts 213
The Screen 216
Output to the Screen 216
Reading from the Screen 217
Clearing the Screen 218
Moving the Cursor 218
Character Attributes 218
The Keyboard 221
Keyboard Modes 221
Keyboard Input 222
Windows 224
The WINDOW Structure 224
Generalized Functions 225
Moving and Updating a Window 225
Optimizing Screen Refreshes 229
Subwindows 230
The Keypad 232
Using Color 235
Redefining Colors 238
Pads 238
The CD Collection Application 240
Starting a New CD Collection Application 240
Looking at main 243
Building the Menu 243
Database File Manipulation 245
Querying the CD Database 250
Summary 254
Chapter 7: Data Management 255
Managing Memory 255
Simple Memory Allocation 256
Allocating Lots of Memory 257
Abusing Memory 260
The Null Pointer 261
Freeing Memory 262
Other Memory Allocation Functions 264
File Locking 264
Creating Lock Files 265
Locking Regions 268
Use of read and write with Locking 271
Competing Locks 276
Other Lock Commands 280
Deadlocks 280
Databases 281
The dbm Database 281
The dbm Routines 283
dbm Access Functions 283
Additional dbm Functions 287
The CD Application 289
Updating the Design 289
The CD Database Application Using dbm 290
Summary 309
Chapter 8: MySQL 311
Installation 312
MySQL Packages 312
Post-Install Configuration 314
Post-Installation Troubleshooting 319
MySQL Administration 320
Commands 320
Creating Users and Giving Them Permissions 325
Passwords 327
Creating a Database 328
Data Types 329
Creating a Table 330
Graphical Tools 333
Accessing MySQL Data from C 335
Connection Routines 337
Error Handling 341
Executing SQL Statements 342
Miscellaneous Functions 357
The CD Database Application 358
Creating the Tables 359
Adding Some Data 362
Accessing the Application Data from C 364
Summary 375
Chapter 9: Development Tools 377
Problems of Multiple Source Files 377
The make Command and Makefiles 378
The Syntax of Makefiles 378
Options and Parameters to make 379
Comments in a Makefile 382
Macros in a Makefile 382
Multiple Targets 384
Built-in Rules 387
Suffix and Pattern Rules 388
Managing Libraries with make 389
Advanced Topic: Makefiles and Subdirectories 391
GNU make and gcc 391
Source Code Control 392
RCS 393
SCCS 399
Comparing RCS and SCCS 399
CVS 400
CVS Front Ends 404
Subversion 405
Writing a Manual Page 406
Distributing Software 409
The patch Program 410
Other Distribution Utilities 411
RPM Packages 413
Working with RPM Package Files 414
Installing RPM Packages 415
Building RPM Packages 415
Other Package Formats 424
Development Environments 424
KDevelop 425
Other Environments 425
Summary 427
Chapter 10: Debugging 429
Types of Errors 429
General Debugging Techniques 430
A Program with Bugs 430
Code Inspection 433
Instrumentation 434
Controlled Execution 436
Debugging with gdb 437
Starting gdb 437
Running a Program 438
Stack Trace 438
Examining Variables 439
Listing the Program 440
Setting Breakpoints 441
Patching with the Debugger 444
Learning More about gdb 445
More Debugging Tools 445
Lint: Removing the Fluff from Your Programs 446
Function Call Tools 449
Execution Profiling with prof/gprof 451
Assertions 452
Memory Debugging 453
ElectricFence 454
valgrind 455
Summary 459
Chapter 11: Processes and Signals 461
What Is a Process? 461
Process Structure 462
The Process Table 463
Viewing Processes 463
System Processes 464
Process Scheduling 467
Starting New Processes 468
Waiting for a Process 475
Zombie Processes 477
Input and Output Redirection 479
Threads 480
Signals 481
Sending Signals 484
Signal Sets 489
Summary 493
Chapter 12: POSIX Threads 495
What Is a Thread? 495
Advantages and Drawbacks of Threads 496
A First Threads Program 497
Simultaneous Execution 501
Synchronization 503
Synchronization with Semaphores 503
Synchronization with Mutexes 508
Thread Attributes 512
Canceling a Thread 517
Threads in Abundance 520
Summary 524
Chapter 13: Inter-Process Communication: Pipes 525
What Is a Pipe? 525
Process Pipes 526
Sending Output to popen 528
Passing More Data 529
How popen Is Implemented 530
The Pipe Call 531
Parent and Child Processes 535
Reading Closed Pipes 536
Pipes Used as Standard Input and Output 537
Named Pipes: FIFOs 540
Accessing a FIFO 542
Advanced Topic: Client/Server Using FIFOs 549
The CD Database Application 553
Aims 554
Implementation 555
Client Interface Functions 558
The Server Interface, server.c 565
The Pipe 569
Application Summary 574
Summary 575
Chapter 14: Semaphores, Shared Memory, and Message Queues 577
Semaphores 577
Semaphore Definition 579
A Theoretical Example 579
Linux Semaphore Facilities 580
Using Semaphores 582
Shared Memory 586
shmget 588
shmat 588
shmdt 589
shmctl 589
Message Queues 594
msgget 594
msgsnd 595
msgrcv 595
msgctl 596
The CD Database Application 599
Revising the Server Functions 600
Revising the Client Functions 602
IPC Status Commands 604
...Erscheinungsjahr: | 2007 |
---|---|
Fachbereich: | Betriebssysteme & Benutzeroberflächen |
Genre: | Informatik |
Rubrik: | Naturwissenschaften & Technik |
Medium: | Taschenbuch |
Inhalt: | Acknowledgements.Foreword.Introduction.Chapter 1: Getting Started.Chapter 2: Shell Programming.Chapter 3: Working with Files.Chapter 4: The Linux Environment.Chapter 5: Terminals.Chapter 6: Managing Text-Based Screens with curses.Chapter 7: Data Manageme |
ISBN-13: | 9780470147627 |
ISBN-10: | 0470147628 |
Sprache: | Englisch |
Herstellernummer: | 14514762000 |
Einband: | Kartoniert / Broschiert |
Autor: |
Matthew, Neil
Stones, Richard |
Auflage: | 4th edition |
Hersteller: |
Wiley
John Wiley & Sons |
Maße: | 235 x 191 x 43 mm |
Von/Mit: | Neil Matthew (u. a.) |
Erscheinungsdatum: | 01.12.2007 |
Gewicht: | 1,496 kg |
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 x
Foreword xxiii
Introduction xxv
Chapter 1: Getting Started 1
An Introduction to UNIX, Linux, and GNU 1
What Is UNIX? 1
What Is Linux? 3
The GNU Project and the Free Software Foundation 3
Linux Distributions 4
Programming Linux 4
Linux Programs 5
Text Editors 6
The C Compiler 7
Development System Roadmap 8
Getting Help 14
Summary 16
Chapter 2: Shell Programming 17
Why Program with a Shell? 18
A Bit of Philosophy 18
What Is a Shell? 19
Pipes and Redirection 21
Redirecting Output 21
Redirecting Input 22
Pipes 22
The Shell as a Programming Language 23
Interactive Programs 23
Creating a Script 24
Making a Script Executable 25
Shell Syntax 27
Variables 27
Conditions 31
Control Structures 34
Functions 46
Commands 49
Command Execution 68
Here Documents 73
Debugging Scripts 74
Going Graphical - The dialog Utility 75
Putting It All Together 81
Requirements 82
Design 82
Summary 91
Chapter 3: Working with Files 93
Linux File Structure 94
Directories 94
Files and Devices 95
System Calls and Device Drivers 96
Library Functions 97
Low-Level File Access 98
write 98
read 99
open 100
Initial Permissions 101
Other System Calls for Managing Files 106
The Standard I/O Library 109
fopen 110
fread 110
fwrite 111
fclose 111
fflush 111
fseek 112
fgetc, getc, and getchar 112
fputc, putc, and putchar 112
fgets and gets 113
Formatted Input and Output 113
printf, fprintf, and sprintf 113
scanf, fscanf, and sscanf 115
Other Stream Functions 117
Stream Errors 119
Streams and File Descriptors 119
File and Directory Maintenance 120
chmod 120
chown 120
unlink, link, and symlink 121
mkdir and rmdir 121
chdir and getcwd 122
Scanning Directories 122
opendir 123
readdir 123
telldir 123
seekdir 124
closedir 124
Errors 127
strerror 127
perror 127
The /proc File System 128
Advanced Topics: fcntl and mmap 132
fcntl 132
mmap 133
Summary 135
Chapter 4: The Linux Environment 137
Program Arguments 137
getopt 140
getopt_long 142
Environment Variables 144
Use of Environment Variables 146
The environ Variable 147
Time and Date 148
Temporary Files 156
User Information 158
Host Information 161
Logging 163
Resources and Limits 167
Summary 173
Chapter 5: Terminals 175
Reading from and Writing to the Terminal 175
Talking to the Terminal 180
The Terminal Driver and the General Terminal Interface 182
Overview 183
Hardware Model 183
The termios Structure 184
Input Modes 186
Output Modes 186
Control Modes 187
Local Modes 188
Special Control Characters 188
Terminal Speed 192
Additional Functions 192
Terminal Output 196
Terminal Type 197
Identify Your Terminal Type 197
Using terminfo Capabilities 200
Detecting Keystrokes 205
Virtual Consoles 207
Pseudo-Terminals 208
Summary 209
Chapter 6: Managing Text-Based Screens with curses 211
Compiling with curses 212
Curses Terminology and Concepts 213
The Screen 216
Output to the Screen 216
Reading from the Screen 217
Clearing the Screen 218
Moving the Cursor 218
Character Attributes 218
The Keyboard 221
Keyboard Modes 221
Keyboard Input 222
Windows 224
The WINDOW Structure 224
Generalized Functions 225
Moving and Updating a Window 225
Optimizing Screen Refreshes 229
Subwindows 230
The Keypad 232
Using Color 235
Redefining Colors 238
Pads 238
The CD Collection Application 240
Starting a New CD Collection Application 240
Looking at main 243
Building the Menu 243
Database File Manipulation 245
Querying the CD Database 250
Summary 254
Chapter 7: Data Management 255
Managing Memory 255
Simple Memory Allocation 256
Allocating Lots of Memory 257
Abusing Memory 260
The Null Pointer 261
Freeing Memory 262
Other Memory Allocation Functions 264
File Locking 264
Creating Lock Files 265
Locking Regions 268
Use of read and write with Locking 271
Competing Locks 276
Other Lock Commands 280
Deadlocks 280
Databases 281
The dbm Database 281
The dbm Routines 283
dbm Access Functions 283
Additional dbm Functions 287
The CD Application 289
Updating the Design 289
The CD Database Application Using dbm 290
Summary 309
Chapter 8: MySQL 311
Installation 312
MySQL Packages 312
Post-Install Configuration 314
Post-Installation Troubleshooting 319
MySQL Administration 320
Commands 320
Creating Users and Giving Them Permissions 325
Passwords 327
Creating a Database 328
Data Types 329
Creating a Table 330
Graphical Tools 333
Accessing MySQL Data from C 335
Connection Routines 337
Error Handling 341
Executing SQL Statements 342
Miscellaneous Functions 357
The CD Database Application 358
Creating the Tables 359
Adding Some Data 362
Accessing the Application Data from C 364
Summary 375
Chapter 9: Development Tools 377
Problems of Multiple Source Files 377
The make Command and Makefiles 378
The Syntax of Makefiles 378
Options and Parameters to make 379
Comments in a Makefile 382
Macros in a Makefile 382
Multiple Targets 384
Built-in Rules 387
Suffix and Pattern Rules 388
Managing Libraries with make 389
Advanced Topic: Makefiles and Subdirectories 391
GNU make and gcc 391
Source Code Control 392
RCS 393
SCCS 399
Comparing RCS and SCCS 399
CVS 400
CVS Front Ends 404
Subversion 405
Writing a Manual Page 406
Distributing Software 409
The patch Program 410
Other Distribution Utilities 411
RPM Packages 413
Working with RPM Package Files 414
Installing RPM Packages 415
Building RPM Packages 415
Other Package Formats 424
Development Environments 424
KDevelop 425
Other Environments 425
Summary 427
Chapter 10: Debugging 429
Types of Errors 429
General Debugging Techniques 430
A Program with Bugs 430
Code Inspection 433
Instrumentation 434
Controlled Execution 436
Debugging with gdb 437
Starting gdb 437
Running a Program 438
Stack Trace 438
Examining Variables 439
Listing the Program 440
Setting Breakpoints 441
Patching with the Debugger 444
Learning More about gdb 445
More Debugging Tools 445
Lint: Removing the Fluff from Your Programs 446
Function Call Tools 449
Execution Profiling with prof/gprof 451
Assertions 452
Memory Debugging 453
ElectricFence 454
valgrind 455
Summary 459
Chapter 11: Processes and Signals 461
What Is a Process? 461
Process Structure 462
The Process Table 463
Viewing Processes 463
System Processes 464
Process Scheduling 467
Starting New Processes 468
Waiting for a Process 475
Zombie Processes 477
Input and Output Redirection 479
Threads 480
Signals 481
Sending Signals 484
Signal Sets 489
Summary 493
Chapter 12: POSIX Threads 495
What Is a Thread? 495
Advantages and Drawbacks of Threads 496
A First Threads Program 497
Simultaneous Execution 501
Synchronization 503
Synchronization with Semaphores 503
Synchronization with Mutexes 508
Thread Attributes 512
Canceling a Thread 517
Threads in Abundance 520
Summary 524
Chapter 13: Inter-Process Communication: Pipes 525
What Is a Pipe? 525
Process Pipes 526
Sending Output to popen 528
Passing More Data 529
How popen Is Implemented 530
The Pipe Call 531
Parent and Child Processes 535
Reading Closed Pipes 536
Pipes Used as Standard Input and Output 537
Named Pipes: FIFOs 540
Accessing a FIFO 542
Advanced Topic: Client/Server Using FIFOs 549
The CD Database Application 553
Aims 554
Implementation 555
Client Interface Functions 558
The Server Interface, server.c 565
The Pipe 569
Application Summary 574
Summary 575
Chapter 14: Semaphores, Shared Memory, and Message Queues 577
Semaphores 577
Semaphore Definition 579
A Theoretical Example 579
Linux Semaphore Facilities 580
Using Semaphores 582
Shared Memory 586
shmget 588
shmat 588
shmdt 589
shmctl 589
Message Queues 594
msgget 594
msgsnd 595
msgrcv 595
msgctl 596
The CD Database Application 599
Revising the Server Functions 600
Revising the Client Functions 602
IPC Status Commands 604
...Erscheinungsjahr: | 2007 |
---|---|
Fachbereich: | Betriebssysteme & Benutzeroberflächen |
Genre: | Informatik |
Rubrik: | Naturwissenschaften & Technik |
Medium: | Taschenbuch |
Inhalt: | Acknowledgements.Foreword.Introduction.Chapter 1: Getting Started.Chapter 2: Shell Programming.Chapter 3: Working with Files.Chapter 4: The Linux Environment.Chapter 5: Terminals.Chapter 6: Managing Text-Based Screens with curses.Chapter 7: Data Manageme |
ISBN-13: | 9780470147627 |
ISBN-10: | 0470147628 |
Sprache: | Englisch |
Herstellernummer: | 14514762000 |
Einband: | Kartoniert / Broschiert |
Autor: |
Matthew, Neil
Stones, Richard |
Auflage: | 4th edition |
Hersteller: |
Wiley
John Wiley & Sons |
Maße: | 235 x 191 x 43 mm |
Von/Mit: | Neil Matthew (u. a.) |
Erscheinungsdatum: | 01.12.2007 |
Gewicht: | 1,496 kg |