[PDF] Linux System Programming - IGM



Previous PDF Next PDF







Start With Why - Earthgifts

its own game For Steve Wozniak and Steve Jobs, the cofounders of Apple Computer, the battlefield was business and the weapon of choice was the personal computer The personal computer revolution was beginning to brew when Wozniak built the Apple I Just starting to gain attention, the tech-nology was primarily seen as a tool for business



Special Education in Ontario

The Ontario Public Service endeavours to demonstrate leadership with respect to accessibility in Ontario Our goal is to ensure that Ontario government services, products, and facilities are



Knowledge Management in Theory and Practice

Key Points 46 Discussion Points 46 References 46 3 KNOWLEDGE MANAGEMENT MODELS 47 Learning Objectives 47 Introduction 48 Major Theoretical KM Models 49 The von Krogh and Roos Model of Organizational



Linux System Programming - IGM

Overview This book is about writing software that makes the most effective use of the system you're running on -- code that interfaces directly with the kernel and core system libraries, including



Chapter 3 Apply the 80/20 Rule to Everything Chapter 5

Over the years, I have worked in twenty-two different jobs, started and built several companies, earned a business degree from a major university, learned to speak French, German and Spanish and been a speaker, trainer or consultant for more than 1000 companies I currently give talks and seminars to more than 250,000 people each



Telecharger Lire En Ligne Ce livre est destiné à liPhone 5

Steve Jobs présentant l'iPhone 4 lors du discours d' ouverture (keynote) de sa ebook gratuit telecharger iPhone 4S et 5 édition iOS 7 poche pour les Nuls epub



Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future

rockets peddling false hope Forget Steve Jobs Musk is a sci-fi version of P T Barnum who has gotten extraordinarily rich by preying on people’s fear and self-hatred Buy a Tesla Forget about the mess you’ve made of the planet for a while I’d long been a subscriber to this latter camp Musk had struck me as a well-intentioned dreamer



Linux Shell Scripting Tutorial v2

functions Finally, book covers various sys admin related scripts such as making a backup, using cron jobs, writing interactive tools, web based tools, remote login, ftp and database backup related scripts This book is intended for Linux system administrators or students who have mastered the basics of a Linux Operating System You should be



You’re holding a guide to the world’s best business models

Customer Development (Steve Blank) and Agile Engineering / Lean Startup (Eric Ries), Test Card, Learning Card The Startup Owner’s Manual (Steve Blank, 2012), Lean Startup (Eric Ries, 2011), Value Proposition Design (2014) Pick the right experiments to test your idea What are the most appropriate experiments to test and de-risk your ideas?



[PDF] héros de l'olympe 5 epub gratuit

[PDF] exercices corrigés transformée de fourier traitement du signal

[PDF] héros de l'olympe tome 5 pdf

[PDF] transformée de fourier équation différentielle+exercices corrigés pdf

[PDF] les héros de l'olympe pdf gratuit

[PDF] produit de convolution et transformée de fourier

[PDF] le sang de l'olympe lecture en ligne

[PDF] héros de l'olympe tome 1 epub

[PDF] transformée de fourier propriétés

[PDF] héros de l'olympe 2 pdf

[PDF] cours transformée de fourier

[PDF] les héros de l'olympe tome 1 ebook gratuit

[PDF] produit de convolution exercices corrigés

[PDF] heros francais

[PDF] héros de l olympe le fils de neptune pdf

Overview

This book is about writing software that makes the most effective use of the system you"re running on -- code that interfaces directly with the kernel and core system libraries, including the shell, text editor, compiler, debugger, core utilities, and system daemons. The majority of both Unix and Linux code is still written at the system level, and

Linux System Programming

focuses on everything above the kernel, where applications such as Apache, bash, cp, vim,

Emacs, gcc, gdb, glibc, ls, mv, and X exist.

Written primarily for engineers looking to program (better) at the low level, this book is an ideal teaching tool for any programmer. Even with the trend toward high-level development, either through web software (such as PHP) or managed code (C#), someone still has to write the PHP interpreter and the C# virtual machine.

Linux System Programming gives you an

understanding of core internals that makes for better code, no matter where it appears in the stack. Debugging high-level code often requires you to understand the system calls and kernel behavior of your operating system, too.

Key topics include:

• An overview of Linux, the kernel, the C library, and the C compiler • Reading from and writing to files, along with other basic file I/O operations, including how the Linux kernel implements and manages file I/O • Buffer size management, including the Standard I/O library • Advanced I/O interfaces, memory mappings, and optimization techniques • The family of system calls for basic process management • Advanced process management, including real-time processes • File and directories-creating, moving, copying, deleting, and managing them • Memory management -- interfaces for allocating memory, managing the memory you have, and optimizing your memory access • Signals and their role on a Unix system, plus basic and advanced signal interfaces • Time, sleeping, and clock management, starting with the basics and continuing through POSIX clocks and high resolution timers With Linux System Programming, you will be able to take an in-depth look at Linux from both a theoretical and an applied perspective as you cover a wide range of programming topics.

Linux System Programming

2 of 396

Linux System Programming

by Robert Love Copyright © 2007 O"Reilly Media, Inc. All rights reserved.

Printed in the United States of America.

Published by O"Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O"Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles ( safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.

Editor: Andy Oram

Production Editor: Sumita Mukherji

Copyeditor: Rachel Head

Proofreader: Sumita Mukherji

Indexer: John Bickelhaupt

Cover Designer: Karen Montgomery

Interior Designer: David Futato

Illustrator: Jessamyn Read

Printing History:

September 2007: First Edition.

Nutshell Handbook, the Nutshell Handbook logo, and the O"Reilly logo are registered trademarks of O"Reilly Media, Inc. The Linux series designations, Linux System Programming, images of the man in the flying machine, and related trade dress are trademarks of O"Reilly

Media, Inc.

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O"Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.

ISBN-10: 0-596-00958-5

ISBN-13: 978-0-596-00958-8

[M]

Linux System Programming

3 of 396

Table of Contents

Linux System Programming...............................................................................2

P3.1. Audience and Assumptions............................................................................11

P3.2. Contents of This Book...................................................................................11

P3.3. Versions Covered in This Book.......................................................................13

P3.4. Conventions Used in This Book......................................................................13

P3.5. Safari® Books Online...................................................................................15

P3.6. Using Code Examples ...................................................................................15

P3.7. How to Contact Us .......................................................................................15

P3.8. Acknowledgments........................................................................................16

Chapter 1. Introduction and Essential Concepts...........................................................17

1.1. System Programming.....................................................................................17

1.1.1. System Calls ..........................................................................................18

1.1.2. The C Library..........................................................................................19

1.1.3. The C Compiler.......................................................................................19

1.2. APIs and ABIs ...............................................................................................19

1.2.1. APIs ......................................................................................................19

1.2.2. ABIs......................................................................................................20

1.3. Standards.....................................................................................................20

1.3.1. POSIX and SUS History............................................................................21

1.3.2. C Language Standards.............................................................................21

1.3.3. Linux and the Standards ..........................................................................22

1.3.4. This Book and the Standards....................................................................22

1.4. Concepts of Linux Programming ......................................................................23

1.4.1. Files and the Filesystem...........................................................................23

1.4.2. Processes...............................................................................................28

1.4.3. Users and Groups ...................................................................................29

1.4.4. Permissions............................................................................................30

1.4.5. Signals ..................................................................................................31

1.4.6. Interprocess Communication ....................................................................31

1.4.7. Headers.................................................................................................31

1.4.8. Error Handling ........................................................................................31

1.5. Getting Started with System Programming .......................................................35

Chapter 2. File I/O...................................................................................................36

2.1. Opening Files................................................................................................36

2.1.1. The open( ) System Call ..........................................................................36

2.1.2. Owners of New Files................................................................................39

2.1.3. Permissions of New Files..........................................................................40

2.1.4. The creat( ) Function...............................................................................42

2.1.5. Return Values and Error Codes .................................................................43

2.2. Reading via read( )........................................................................................43

2.2.1. Return Values.........................................................................................43

2.2.2. Reading All the Bytes ..............................................................................44

2.2.3. Nonblocking Reads..................................................................................45

2.2.4. Other Error Values ..................................................................................45

2.2.5. Size Limits on read( ) ..............................................................................46

2.3. Writing with write( ) ......................................................................................46

2.3.1. Partial Writes..........................................................................................47

2.3.2. Append Mode .........................................................................................47

2.3.3. Nonblocking Writes .................................................................................48

2.3.4. Other Error Codes...................................................................................48

2.3.5. Size Limits on write( ) .............................................................................49

2.3.6. Behavior of write( ).................................................................................49

2.4. Synchronized I/O ..........................................................................................50

2.4.1. fsync( ) and fdatasync( )..........................................................................50

Linux System Programming

4 of 396

2.4.2. sync( )...................................................................................................52

2.4.3. The O_SYNC Flag....................................................................................52

2.4.4. O_DSYNC and O_RSYNC..........................................................................53

2.5. Direct I/O.....................................................................................................53

2.6. Closing Files..................................................................................................54

2.6.1. Error Values ...........................................................................................54

2.7. Seeking with lseek( ) .....................................................................................55

2.7.1. Seeking Past the End of a File...................................................................56

2.7.2. Error Values ...........................................................................................56

2.7.3. Limitations.............................................................................................57

2.8. Positional Reads and Writes............................................................................57

2.8.1. Error Values ...........................................................................................58

2.9. Truncating Files.............................................................................................58

2.10. Multiplexed I/O............................................................................................59

2.10.1. select( )...............................................................................................60

2.10.2. poll( ) ..................................................................................................65

2.10.3. poll( ) Versus select( ) ...........................................................................69

2.11. Kernel Internals...........................................................................................70

2.11.1. The Virtual Filesystem............................................................................70

2.11.2. The Page Cache ....................................................................................71

2.11.3. Page Writeback.....................................................................................72

2.12. Conclusion..................................................................................................73

Chapter 3. Buffered I/O............................................................................................74

3.1. User-Buffered I/O..........................................................................................74

3.1.1. Block Size ..............................................................................................75

3.2. Standard I/O ................................................................................................75

3.2.1. File Pointers ...........................................................................................76

3.3. Opening Files................................................................................................76

3.3.1. Modes ...................................................................................................76

3.4. Opening a Stream via File Descriptor ...............................................................78

3.5. Closing Streams ............................................................................................78

3.5.1. Closing All Streams .................................................................................78

3.6. Reading from a Stream ..................................................................................79

3.6.1. Reading a Character at a Time..................................................................79

3.6.2. Reading an Entire Line.............................................................................80

3.6.3. Reading Binary Data................................................................................81

Issues of Alignment .................................................................................................81

3.7. Writing to a Stream .......................................................................................82

3.7.1. Writing a Single Character........................................................................82

3.7.2. Writing a String of Characters...................................................................82

3.7.3. Writing Binary Data.................................................................................83

3.8. Sample Program Using Buffered I/O ................................................................83

3.9. Seeking a Stream..........................................................................................83

3.9.1. Obtaining the Current Stream Position.......................................................85

3.10. Flushing a Stream........................................................................................85

3.11. Errors and End-of-File ..................................................................................86

3.12. Obtaining the Associated File Descriptor .........................................................86

3.13. Controlling the Buffering...............................................................................87

3.14. Thread Safety .............................................................................................88

3.14.1. Manual File Locking ...............................................................................89

3.14.2. Unlocked Stream Operations ..................................................................90

3.15. Critiques of Standard I/O..............................................................................90

3.16. Conclusion..................................................................................................91

Chapter 4. Advanced File I/O ....................................................................................92

4.1. Scatter/Gather I/O ........................................................................................92

4.1.1. readv( ) and writev( )..............................................................................93

Optimizing the Count ...............................................................................................95

4.2. The Event Poll Interface .................................................................................97

4.2.1. Creating a New Epoll Instance ..................................................................98

Linux System Programming

5 of 396

4.2.2. Controlling Epoll......................................................................................99

4.2.3. Waiting for Events with Epoll .................................................................. 102

4.2.4. Edge- Versus Level-Triggered Events....................................................... 104

4.3. Mapping Files into Memory ........................................................................... 104

4.3.1. mmap( ).............................................................................................. 104

Protection Flags, Architectures, and Security............................................................. 105

4.3.2. munmap( )........................................................................................... 111

4.3.3. Mapping Example.................................................................................. 112

4.3.4. Advantages of mmap( ) ......................................................................... 113

4.3.5. Disadvantages of mmap( )..................................................................... 114

4.3.6. Resizing a Mapping ............................................................................... 114

4.3.7. Changing the Protection of a Mapping...................................................... 116

4.3.8. Synchronizing a File with a Mapping ........................................................ 116

4.3.9. Giving Advice on a Mapping.................................................................... 118

Readahead............................................................................................................ 120

4.4. Advice for Normal File I/O ............................................................................ 121

4.4.1. The posix_fadvise( ) System Call ............................................................ 121

4.4.2. The readahead( ) System Call ................................................................ 124

4.4.3. Advice Is Cheap.................................................................................... 124

4.5. Synchronized, Synchronous, and Asynchronous Operations .............................. 125

4.5.1. Asynchronous I/O ................................................................................. 126

4.6. I/O Schedulers and I/O Performance.............................................................. 127

4.6.1. Disk Addressing.................................................................................... 128

4.6.2. The Life of an I/O Scheduler................................................................... 128

4.6.3. Helping Out Reads ................................................................................ 129

4.6.4. Selecting and Configuring Your I/O Scheduler........................................... 131

4.6.5. Optimizing I/O Performance ................................................................... 131

4.7. Conclusion.................................................................................................. 137

Chapter 5. Process Management.............................................................................. 138

5.1. The Process ID............................................................................................ 138

5.1.1. Process ID Allocation............................................................................. 139

5.1.2. The Process Hierarchy ........................................................................... 139

5.1.3. pid_t ................................................................................................... 139

5.1.4. Obtaining the Process ID and Parent Process ID........................................ 139

5.2. Running a New Process ................................................................................ 140

5.2.1. The Exec Family of Calls ........................................................................140

5.2.2. The fork( ) System Call.......................................................................... 144

5.3. Terminating a Process.................................................................................. 147

5.3.1. Other Ways to Terminate....................................................................... 148

5.3.2. atexit( )............................................................................................... 149

5.3.3. on_exit( ) ............................................................................................ 150

5.3.4. SIGCHLD ............................................................................................. 150

5.4. Waiting for Terminated Child Processes.......................................................... 150

5.4.1. Waiting for a Specific Process ................................................................. 153

5.4.2. Even More Waiting Versatility ................................................................. 155

5.4.3. BSD Wants to Play: wait3( ) and wait4( )................................................. 158

5.4.4. Launching and Waiting for a New Process................................................. 160

5.4.5. Zombies .............................................................................................. 161

5.5. Users and Groups........................................................................................ 162

5.5.1. Real, Effective, and Saved User and Group IDs......................................... 162

5.5.2. Changing the Real or Saved User or Group ID .......................................... 163

5.5.3. Changing the Effective User or Group ID.................................................. 164

5.5.4. Changing the User and Group IDs, BSD Style ........................................... 164

5.5.5. Changing the User and Group IDs, HP-UX Style ........................................ 165

5.5.6. Preferred User/Group ID Manipulations.................................................... 165

5.5.7. Support for Saved User IDs.................................................................... 165

5.5.8. Obtaining the User and Group IDs........................................................... 166

5.6. Sessions and Process Groups ........................................................................ 166

5.6.1. Session System Calls............................................................................. 168

Linux System Programming

6 of 396

5.6.2. Process Group System Calls ................................................................... 170

5.6.3. Obsolete Process Group Functions........................................................... 171

5.7. Daemons.................................................................................................... 172

5.8. Conclusion.................................................................................................. 173

Chapter 6. Advanced Process Management ............................................................... 175

6.1. Process Scheduling...................................................................................... 175

6.1.1. Big-Oh Notation.................................................................................... 176

6.1.2. Timeslices............................................................................................ 176

6.1.3. I/O- Versus Processor-Bound Processes................................................... 177

6.1.4. Preemptive Scheduling .......................................................................... 177

6.1.5. Threading ............................................................................................ 178

6.2. Yielding the Processor.................................................................................. 178

6.2.1. Legitimate Uses .................................................................................... 179

6.2.2. Yielding, Past and Present...................................................................... 179

6.3. Process Priorities......................................................................................... 180

6.3.1. nice( ) ................................................................................................. 181

6.3.2. getpriority( ) and setpriority( ) ...............................................................182

6.3.3. I/O Priorities......................................................................................... 183

6.4. Processor Affinity......................................................................................... 184

6.4.1. sched_getaffinity() and sched_setaffinity( ).............................................. 184

6.5. Real-Time Systems...................................................................................... 187

6.5.1. Hard Versus Soft Real-Time Systems....................................................... 187

6.5.2. Latency, Jitter, and Deadlines................................................................. 188

6.5.3. Linux"s Real-Time Support......................................................................188

6.5.4. Linux Scheduling Policies and Priorities .................................................... 189

6.5.5. Setting Scheduling Parameters ............................................................... 192

6.5.6. sched_rr_get_interval( ) ........................................................................ 195

6.5.7. Precautions with Real-Time Processes...................................................... 197

6.5.8. Determinism ........................................................................................ 197

6.6. Resource Limits........................................................................................... 199

6.6.1. The Limits............................................................................................ 200

6.6.2. Setting and Retrieving Limits..................................................................204

Chapter 7. File and Directory Management................................................................ 206

7.1. Files and Their Metadata .............................................................................. 206

7.1.1. The Stat Family .................................................................................... 206

7.1.2. Permissions.......................................................................................... 209

7.1.3. Ownership............................................................................................ 212

7.1.4. Extended Attributes............................................................................... 215

A Better Way to Store MIME Types........................................................................... 215

7.2. Directories.................................................................................................. 225

7.2.1. The Current Working Directory ............................................................... 226

7.2.2. Creating Directories............................................................................... 232

7.2.3. Removing Directories ............................................................................234

7.2.4. Reading a Directory"s Contents ............................................................... 236

7.3. Links.......................................................................................................... 238

7.3.1. Hard Links............................................................................................ 239

7.3.2. Symbolic Links...................................................................................... 241

7.3.3. Unlinking ............................................................................................. 244

7.4. Copying and Moving Files ............................................................................. 246

7.4.1. Copying ............................................................................................... 246

7.4.2. Moving ................................................................................................ 246

7.5. Device Nodes.............................................................................................. 249

7.5.1. Special Device Nodes............................................................................. 250

7.5.2. The Random Number Generator.............................................................. 250

7.6. Out-of-Band Communication.........................................................................251

7.7. Monitoring File Events.................................................................................. 252

7.7.1. Initializing inotify .................................................................................. 253

7.7.2. Watches............................................................................................... 254

7.7.3. inotify Events ....................................................................................... 257

Linux System Programming

7 of 396

7.7.4. Advanced Watch Options ....................................................................... 260

7.7.5. Removing an inotify Watch..................................................................... 261

7.7.6. Obtaining the Size of the Event Queue..................................................... 261

7.7.7. Destroying an inotify Instance ................................................................ 262

Chapter 8. Memory Management............................................................................. 263

8.1. The Process Address Space........................................................................... 263

8.1.1. Pages and Paging.................................................................................. 263

8.1.2. Memory Regions ................................................................................... 264

8.2. Allocating Dynamic Memory..........................................................................265

8.2.1. Allocating Arrays................................................................................... 266

8.2.2. Resizing Allocations............................................................................... 267

8.2.3. Freeing Dynamic Memory....................................................................... 269

8.2.4. Alignment ............................................................................................ 270

8.3. Managing the Data Segment......................................................................... 274

8.4. Anonymous Memory Mappings ...................................................................... 274

8.4.1. Creating Anonymous Memory Mappings................................................... 276

8.4.2. Mapping /dev/zero ................................................................................ 277

8.5. Advanced Memory Allocation.........................................................................278

8.5.1. Fine-Tuning with malloc_usable_size( ) and malloc_trim( ) ........................ 280

8.6. Debugging Memory Allocations......................................................................281

8.6.1. Obtaining Statistics ............................................................................... 281

8.7. Stack-Based Allocations ............................................................................... 282

8.7.1. Duplicating Strings on the Stack ............................................................. 284

8.7.2. Variable-Length Arrays .......................................................................... 284

8.8. Choosing a Memory Allocation Mechanism ...................................................... 285

8.9. Manipulating Memory................................................................................... 286

8.9.1. Setting Bytes........................................................................................ 286

8.9.2. Comparing Bytes .................................................................................. 287

8.9.3. Moving Bytes........................................................................................ 288

8.9.4. Searching Bytes.................................................................................... 289

8.9.5. Frobnicating Bytes ................................................................................ 290

8.10. Locking Memory ........................................................................................ 290

8.10.1. Locking Part of an Address Space.......................................................... 291

8.10.2. Locking All of an Address Space ............................................................ 292

8.10.3. Unlocking Memory...............................................................................293

8.10.4. Locking Limits..................................................................................... 294

8.10.5. Is a Page in Physical Memory? .............................................................. 294

8.11. Opportunistic Allocation.............................................................................. 295

8.11.1. Overcommitting and OOM .................................................................... 296

Chapter 9. Signals ................................................................................................. 297

9.1. Signal Concepts .......................................................................................... 297

9.1.1. Signal Identifiers................................................................................... 298

9.1.2. Signals Supported by Linux .................................................................... 298

9.2. Basic Signal Management............................................................................. 305

9.2.1. Waiting for a Signal, Any Signal.............................................................. 306

9.2.2. Examples............................................................................................. 307

9.2.3. Execution and Inheritance...................................................................... 308

9.2.4. Mapping Signal Numbers to Strings......................................................... 309

9.3. Sending a Signal ......................................................................................... 310

9.3.1. Permissions.......................................................................................... 311

9.3.2. Examples............................................................................................. 311

9.3.3. Sending a Signal to Yourself................................................................... 311

9.3.4. Sending a Signal to an Entire Process Group ............................................ 312

9.4. Reentrancy................................................................................................. 313

9.4.1. Guaranteed-Reentrant Functions............................................................. 313

9.5. Signal Sets ................................................................................................. 315

9.5.1. More Signal Set Functions...................................................................... 315

9.6. Blocking Signals .......................................................................................... 316

9.6.1. Retrieving Pending Signals .....................................................................317

Linux System Programming

8 of 396

9.6.2. Waiting for a Set of Signals.................................................................... 317

9.7. Advanced Signal Management....................................................................... 318

9.7.1. The siginfo_t Structure ..........................................................................320

9.7.2. The Wonderful World of si_code.............................................................. 323

9.8. Sending a Signal with a Payload.................................................................... 328

9.8.1. Example .............................................................................................. 329

9.9. Conclusion.................................................................................................. 330

Chapter 10. Time................................................................................................... 331

10.1. Time"s Data Structures............................................................................... 333

10.1.1. The Original Representation.................................................................. 333

10.1.2. And Now, Microsecond Precision............................................................ 333

10.1.3. Even Better: Nanosecond Precision........................................................ 334

10.1.4. Breaking Down Time............................................................................334

10.1.5. A Type for Process Time....................................................................... 336

10.2. POSIX Clocks ............................................................................................ 336

10.2.1. Time Source Resolution........................................................................ 337

10.3. Getting the Current Time of Day.................................................................. 338

A Naïve Approach to Time....................................................................................... 339

10.3.1. A Better Interface................................................................................ 339

10.3.2. An Advanced Interface......................................................................... 339

10.3.3. Getting the Process Time ..................................................................... 340

10.4. Setting the Current Time of Day .................................................................. 341

10.4.1. Setting Time with Precision................................................................... 341

10.4.2. An Advanced Interface for Setting the Time............................................ 342

10.5. Playing with Time ...................................................................................... 343

10.6. Tuning the System Clock ............................................................................ 345

10.7. Sleeping and Waiting ................................................................................. 349

10.7.1. Sleeping with Microsecond Precision ...................................................... 349

10.7.2. Sleeping with Nanosecond Resolution .................................................... 350

10.7.3. An Advanced Approach to Sleep............................................................ 352

10.7.4. A Portable Way to Sleep.......................................................................353

10.7.5. Overruns............................................................................................ 354

10.7.6. Alternatives to Sleeping .......................................................................354

10.8. Timers...................................................................................................... 354

10.8.1. Simple Alarms .................................................................................... 355

10.8.2. Interval Timers ................................................................................... 355

10.8.3. Advanced Timers................................................................................. 357

Appendix A. GCC Extensions to the C Language......................................................... 363

A.1. GNU C ....................................................................................................... 363

A.2. Inline Functions........................................................................................... 363

A.3. Suppressing Inlining .................................................................................... 364

A.4. Pure Functions ............................................................................................ 364

A.5. Constant Functions...................................................................................... 365

A.6. Functions That Do Not Return .......................................................................365

A.7. Functions That Allocate Memory.................................................................... 365

A.8. Forcing Callers to Check the Return Value ...................................................... 366

A.9. Marking Functions As Deprecated.................................................................. 366

A.10. Marking Functions As Used ......................................................................... 366

A.11. Marking Functions or Parameters As Unused ................................................. 366

A.12. Packing a Structure.................................................................................... 367

A.13. Increasing the Alignment of a Variable ......................................................... 367

A.14. Placing Global Variables in a Register........................................................... 368

A.15. Branch Annotation..................................................................................... 368

A.16. Getting the Type of an Expression ............................................................... 369

A.17. Getting the Alignment of a Type .................................................................. 369

A.18. The Offset of a Member Within a Structure ................................................... 370

A.19. Obtaining the Return Address of a Function .................................................. 371

A.20. Case Ranges............................................................................................. 371

A.21. Void and Function Pointer Arithmetic............................................................ 372

Linux System Programming

9 of 396

A.22. More Portable and More Beautiful in One Fell Swoop ...................................... 372

Bibliography.......................................................................................................... 374

Books on the C Programming Language................................................................ 374

Books on Linux Programming .............................................................................. 374

The Sockets Networking API ............................................................................ 375

Interprocess Communications.......................................................................... 375

Appendix. About the Author .................................................................................... 376

Appendix. Colophon ............................................................................................... 376

Index ................................................................................................................... 378

Linux System Programming

10 of 396

Foreword

There is an old line that Linux kernel developers like to throw out when they are feeling grumpy: "User space is just a test load for the kernel." By muttering this line, the kernel developers aim to wash their hands of all responsibility for any failure to run user-space code as well as possible. As far as they"re concerned, user-space developers should just go away and fix their own code, as any problems are definitely not the kernel"s fault.quotesdbs_dbs11.pdfusesText_17