Linux System Programming
Linux System Programming Talking Directly to the Kernel and C Library By Robert Love
September 2007
Pages: 388

Cover | Table of Contents | Colophon


Index


[ Symbol ], 
[ A ], 
[ B ], 
[ C ], 
[ D ], 
[ E ], 
[ F ], 
[ G ], 
[ H ], 
[ I ], 
[ J ], 
[ K ], 
[ L ], 
[ M ], 
[ N ], 
[ O ], 
[ P ], 
[ R ], 
[ S ], 
[ T ], 
[ U ], 
[ V ], 
[ W ], 
[ X ], 
[ Y ], 
[ Z ], 


Symbol[ Top ]
/ (forward slash), 11

A[ Top ]
ABIs (application binary interfaces), 4, 5
abort( ) function, 282
absolute pathnames, 11, 212
absolute time, 309
access control lists (ACLs), 18
ACLs (access control lists), 18
adjtime( ) function, 322
adjtimex( ) function, 322-324
aio interfaces, 112
alarm( ) function, 282, 330
alarm_handler( ) function, 331
alignment of data, 252
_ _alignof_ _ keyword, 346
alloca( ) function, 264
      duplicating strings on the stack, 266
allocation, 243
anonymous memory mappings, 256-260
      creating, 257
      mapping /dev/zero, 259
ANSI C, 7
Anticipatory I/O Scheduler, 117
anti-lock braking system (ABS) as real-time system, 176
APIs (application programming interfaces), 4
append mode, write( ), 34
applications
      time dependency and the system clock, 321
arrays, allocation of, 247
asctime( ) and asctime_r( ) functions, 320
asynchronous events, signals for (see signals)
asynchronous I/O, 112
asynchronous write operations, 111
atexit( ) function, 137
_ _attribute_ _ syntax, beautifying with preprocessor macros, 349
automatic variables, 264

B[ Top ]
background process groups, 154
batch scheduling policy, 180
bcmp( ) function, 270
bdflush threads, 61
big-oh notation, 163
binary compatibility, 5
binary files and text files, 66
block devices, 13
      sectors, 14
blocking reads, 30
blocks, 15, 62
      block size, 63
            effects on performance, 63
break point, 255
brk( ) function, 256
broken links, 12
bss segment, 245
buddy memory allocation scheme, 256
buffer size, 64
buffered I/O (input/output), 62
      associated file descriptors, obtaining, 77
      block size, 63
            effects on performance, 63
      controlling the buffering, 77
      errors and EOF, 76
      opening files, 65
            modes, 65
      sample program, 72-74
      standard I/O, 64
            file pointers, 65
            limitations, 81
      streams
            closing, 67
            closing all, 67
            flushing, 75
            opening via file descriptors, 66
            seeking a stream, 74
      streams, reading from, 67-70
            putting the character back, 68
            reading an entire line, 68
            reading arbitrary strings, 69
            reading binary data, 70
            reading one character at at time, 67
      streams, writing to, 70-72
            data alignment, 71
            writing a single character, 71
            writing a string, 72
            writing binary data, 72
      thread safety, 79-81
            manual file locking, 80
            unlocked stream operations, 81
      user-buffered I/O, 62-64
buffer_head data structure, 61
buffers, 37, 61
      dirty buffers, 60
_ _builtin_return_address keyword, 348

C[ Top ]
C compiler (see gcc)
C language, 7, 64
      GNU C, 339
C library (libc), 4
cache effects of process migration, 173
calloc( ) function, 247
capabilities system, 18
CAP_IPC_LOCK, 276
CAP_KILL capability, 292
CAP_SYS_TIME, 318
case statement, 348
cd command, 216
character devices and character device files, 13
chdir( ) function, 215
child processes, 17, 127
      memory inheritance and fork( ), 274
      (see also processes)
chmod( ) function, 200
chown( ) function, 201
clearerr( ) function, 76
clock_getres( ) function, 314
clock_gettime( ) function, 316
clockid_t type, 313
clock_nanosleep( ) function, 327
clock_settime( ) function, 319
close( ) function, 41
code examples, permissions, xv
common file model, 58
Complete Fair Queuing (CFQ) I/O Scheduler, 118
congestion avoidance, 61
const keyword, 341
controlling terminals, 154
cooperative multitasking, 163
      yielding, 163, 166-169
            legitimate uses, 167
            Linux version 2.6, changes in, 168
copy-on-write (COW), 134, 244
CPU_SETSIZE, 174
creat( ) function, 28
critical regions, 79, 297
ctime( ) function and ctime_r( ) functions, 320
current time, getting, 315-318
      microsecond resolution, 316
      nanosecond resolution, 316
current time, setting, 318, 319
current working directory (cwd), 11, 213-217
      changing, 215-217
      obtaining, 213-215

D[ Top ]
daemon( ) function, 160
daemons, 159-161
dangling symlinks, 225
data alignment, 71
data segment, 245
data segment management, 255
Deadline I/O Scheduler, 116
defined keys, 204
demand paging, 273
determinism, 187-189
/dev/zero, 259
device nodes, 231-232
      major and minor numbers, 231
      random number generators, 232
      special nodes, 231
devices, 13
      /dev/zero, 259
      out-of-band communication, 233
difftime( ) function, 321
direct I/O, 40
directories, 11, 212-223
      creating, 218
      current working directory (cwd), 213-217
            changing, 215-217
            obtaining, 213-215
      directory entries, 212
      directory entry (dentry), 11
      directory stream, 220
            closing, 221
            reading from, 221
      links, 212, 223-228
      names, legal characters for, 212
      names, length of, 212
      reading contents of, 220-223
            system calls for, 222
      removing, 219
      subdirectories, 212
dirfd( ) function, 220
dirty buffers, 60
dirty_expire_centiseconds, 37
disk addressing, 114
dnotify function, 235
dynamic memory allocation, 245-255
      alignment, 252-255
            alignment of nonstandard and complex types, 254
            allocating aligned memory, 252
            pointers, 255
      allocating arrays, 247
      freeing dynamic memory, 250-252
      resizing allocations, 249

E[ Top ]
edge-triggered events, 94
effective gid, 17
effective user ID (uid), 17, 150
eject command program, 233
elevator algorithms, 116
end-of-file (see EOF)
entropy pool, 232
EOF (end-of-file), 30
      errors and, 76
epoch, 309
epoll facility, 89
epoll interface, 57
epoll_create( ) function, 89
epoll_ctl( ) function, 90-92
epoll_wait( ) function, 93
errno, 19-22
error descriptors, 20
error handling, 19-22
errors and EOF, 76
event poll interface, 89-94
      controlling epoll, 90-92
      creating an epoll instance, 89
      edge-triggered versus level-triggered events, 94
      waiting for events, 93
exec family of functions, 129-132
      error values, 131
execl( ) function, 129-130
execute permissions, 18
exit( ) and _exit( ) functions, 136
extended attributes, 203
      keys and values, 204
      listing, 209
      namespaces, 205
      operations, 206
      removal, 210
      retrieval, 206
      security namespace, 206
      setting, 208
      system namespace, 205
      trusted namespace, 206
      user namespace, 206
external fragmentation, 256

F[ Top ]
fchdir( ) function, 215
fchmod( ) function, 200
fchown( ) function, 202
fclose( ) function, 67
fcloseall( ) function, 67
fd (see file descriptors)
fdatasync( ) function, 37
      return values and error codes, 38
feof( ) function, 76
ferror( ) function, 76
fflush( ) function, 75
fgetc( ) function, 67, 69
fgetpos( ) function, 75
fgets( ) function, 68
fgetxattr( ) function, 207
FIFO (first in, first out) class, 179
FIFOs, 13
file descriptors, 9, 23
      streams, opening via, 66
file I/O (input/output), 23-61
      advice, 108-111
            advantages, 110
            posix_fadvise( ) function, 108
      closing files, 41
      direct I/O, 40
      event poll interface (see event poll interface)
      I/O schedulers (see I/O schedulers)
      kernel internals, 57-61
            page cache, 59
            page writeback, 60
            virtual filesystem, 58
      linear output, 84
      lseek( ), 42-44
            error values, 44
            limitations, 44
            seeking past the end of a file, 43
      memory mapped I/O (see memory mapped I/O)
      multiplexed I/O, 47-57
            poll( ) function, 53-56
            poll( ) versus select( ), 57
            ppoll( ) function, 56
            pselect( ) function, 52
            select( ) function, 48-53
      opening files, 24-29
            creat( ) function, 28
            open( ) function, 24-26
            owners of new files, 26
            permissions of new files, 27
            return values and error codes, 29
      positional reads and writes, 44
            error values, 45
      readahead( ) function, 110
      reading files, 29-33
            additional error values, 32
            nonblocking reads, 32
            reading all the bytes, 31
            return values, 30
            size limits on read( ), 33
      scatter/gather I/O (see scatter/gather I/O)
      synchronized I/O, 37-40
            fsync( ) and fdatasync( ), 37
            O_DSYNC and O_RSYNC flags, 40
            O_SYNC flag, 39
            sync( ) function, 39
      truncating files, 45
      write( ), 33-37
            additional error codes, 35
            append mode, 34
            behavior of write( ), 36
            nonblocking writes, 35
            partial writes, 34
            size limits on, 36
file pointers, 65
file table, 23
FILE typedef, 65
fileno( ) function, 77
files, 9-15
      access, modification, and change times, 198
      closing files, 41
      copying, 228
      deleting, 12
      device nodes, 231-232
            major and minor numbers, 231
            random number generators, 232
            special nodes, 231
      directories (see directories)
      extended attributes (see extended attributes)
      file events, monitoring, 234-242
            inotify interface, 234
            watches, 236-242
      file I/O (see file I/O)
      file ownership, 26
      file permissions, 27
      file position or file offset, 9
      file truncation, 45
      filenames and inodes, 10
      inodes, 196
      length, 10
      links, 11, 223-228
      metadata, 196
            functions for obtaining, 196
      MIME types, storage, 205
      mode, legal values for, 200
      moving, 229
            effects of moving to and from different types of files, 230
      names, legal characters for, 212
      names, length of, 212
      ownership, 201
      permissions, 199
            mode argument, 27
      regular files, 9
      special files, 13
      usage count, 223
filesystem gid, 17
filesystem uid, 17
filesystems, 14
      blocks, 15
      filesystem-agnosticism, 204
      links and, 223
      mounting and unmounting, 14
      supported in Linux, 14
flistxattr( ) function, 210
flockfile( ) function, 80
fopen( ) function, 65
foreground process group, 154
fork( ) function, 17, 132-136, 290
forward slash (/), 11
fputc( ) function, 71
fputs( ) function, 72
fremovexattr( ) function, 211
fseek( ) function, 74
fsetpos( ) function, 74
fsetxattr( ) function, 208
fstat( ) function, 197
fsync( ) function, 37, 76
      return values and error codes, 38
ftell( ) function, 75
ftruncate( ) function, 46
ftrylockfile( ) function, 80
full device, 232
fully qualified pathnames, 11
functions
      constant functions, 341
      inline functions, 340
            suppressing inlining, 340
      marking as deprecated, 343
      marking as unused, 343
      marking as used, 343
      memory allocation functions, 342
      nonreturning functions, 342
      pure functions, 341
funlockfile( ) function, 80
fwrite( ) function, 72

G[ Top ]
gcc (binary), 4
      supported standards, 8
GCC (GNU Compiler Collection), 4
      C language extensions, 339-350
            branch annotation, 345
            case ranges, 348
            constant functions, 341
            deprecated functions, marking, 343
            expression types, getting, 346
            forcing functions to check return values, 342
            functions or parameters, marking as unused, 343
            function's return address, obtaining, 348
            global variables, placing in a register, 345
            GNU C, 339
            inline functions, 340
            inline functions, suppressing, 340
            member offset within a structure, 347
            memory allocation functions, 342
            nonreturning functions, 342
            packing structures, 343
            portability, improving, 349
            pure functions, 341
            type alignment, getting, 346
            used functions, marking, 343
            variable alignment, increasing, 344
            void and pointer arithmetic, 349
get_current_dir_name( ) function, 214
getcwd( ) function, 213, 216
getdents( ) function, 222
getitimer( ) function, 332
getpagesize( ) function, 98
getpgid( ) function, 158
getpgrp( ) function, 158
getpid( ) function, 128
getpriority( ) function, 171
getrlimit( ) functionl, 190
gets( ) function, 81
getsid( ) function, 156
gettimeofday( ) function, 316
getwd( ) function, 214
getxattr( ) function, 207
ghosts, 149
gid (group ID), 17
glibc (GNU libc), 4
      memory allocation, 256
global register variables, 345
gmtime( ) and gmtime_r( ) functions, 320
GNU C, 8, 339
GNU Compiler Collection (see gcc)
GNU libc (glibc), 4
group ID (gid), 17
groups, 17
      ownership of processes, 127
      primary or logon groups, 17
GUI file managers, MIME type sniffing behaviors, 205

H[ Top ]
hard affinity, 173
hard links, 12, 223, 224
hard real-time systems, 176
hard resource limit, 190
hardware clocks, 310
headers, 19
heap, 245
hwclock command, 310

I[ Top ]
idle processes, 126
idle scheduling policy, 180
IEEE (Institute of Electrical and Electronics Engineers), 6
init process, 17, 126
inline functions, 340
      suppressing inlining, 340
inline keyword, 340
inode number, obtaining, 196
inodes, 10, 196
      link count, 12
inotify events, 238-240
      advanced events, 239
      linking together move events, 240
      reading, 238
inotify interface, 234
      initializing, 235
inotify_add_watch( ) function, 236, 238
inotify_event structure, 238
inotify_init( ) function, 235
Institute of Electrical and Electronics Engineers (IEEE), 6
internal fragmentation, 256
International Organization for Standardization (ISO), 7
interprocess communications (IPCs), 13, 19
interval timers, 331
invalid page, 244
I/O (input/output)
      asynchronous I/O, 112
      buffered I/O (see buffered I/O)
      file I/O (see file I/O)
      I/O priorities, 172
      I/O schedulers (see I/O schedulers)
      I/O wait time, 40
      I/O-bound processes, 164
      system calls and, 77
I/O schedulers, 114-125
      disk addressing, 114
      lifecycle, 115
      merging and sorting, 115
      performance optimization, 119-125
      reads, 116-119
            Anticipatory I/O Scheduler, 117
            Complete Fair Queuing (CFQ) I/O Scheduler, 118
            Deadline I/O Scheduler, 116
            Noop I/O Scheduler, 119
      scheduling in user space, 120
            sorting by inode, 121
            sorting by path, 120
            sorting by physical block, 122
      selection and configuration, 119
ioctl( ) function, 233
IOV_MAX, 85
IPCs (interprocess communications), 13
ISO (International Organization for Standardization), 7
itimerval structure, 332

J[ Top ]
jiffies counter, 309
jitter, 177
job control, 154

K[ Top ]
kernel
      file mapping interface (see memory mapped I/O)
      I/O (input/output), implementation of, 57-61
            page cache, 59
            page writeback, 60
            virtual filesystem, 58
      I/O schedulers (see I/O schedulers), 114
      kernel buffering contrasted with user-buffered I/O, 62
      mapping advice and, 106
      readahead, 107
      system timer, 309
      time measurement, 308
      usage of file descriptors, 23
      user-space applications, communication with, 3
kernel time, 40
keys, 204
kill( ) function, 284, 291, 307
      signal for, 303
kill command, 281

L[ Top ]
latency, 177
lchown( ) function, 201
level-triggered events, 94
lgetxattr( ) function, 207
libc (C library), 4
likely( ) wrapper, 345
linear I/O, 84
link( ) function, 224
links, 11, 212, 223-228
      broken links, 12
      hard links, 12, 224
      link count, 12
      symbolic links, 12, 225
      unlinking, 227
Linus Elevator, 116
Linux, 1
      C standards and, 7
      forward compatibility, 8
      Linux Standard Base (LSB), 8
      Unix compared to, 1
Linux Foundation, 8
Linux system interface, xiii
listxattr( ) function, 209
llistxattr( ) function, 210
load balancing, 173
locality of reference, 59
localtime( ) and localtime_r( ) functions, 321
login, 17
login shell, 17, 154
logon group, 17
lremovexattr( ) function, 211
ls command, 196
LSB (Linux Standard Base), 8
lseek( ) function, 42-44
      error values, 44
      limitations, 44
      seeking past the end of a file, 43
lsetxattr( ) function, 208
lstat( ) function, 197

M[ Top ]
machine register, 3
madvise( ) function, 106-108
      return values and error codes, 108
make, time dependency of, 321
mallinfo( ) function, 263
malloc( ) function, 246
      xmalloc( ) wrapper for, 247
malloc0( ) function, 248
MALLOC_CHECK_ environment variable, 263
malloc_usable_size( ) and malloc_trim( ) functions, 262
mallopt( ) function, 260
      parameters, 261
mapped files, 245
mappings, 245
maximum buffer age, 37
memchr( ) function, 272
memcmp( ) function, 270
memfrob( ) function, 272
memmem( ) function, 272
memmove( ) function, 271
memory addressing and data alignment, 71
memory allocation, 243
      advanced memory allocation, 260-263
            malloc_usable_size( ) and malloc_trim( ) functions, 262
            mallopt( ) function, 260
      choosing a mechanism, 268
      debugging, 263
            MALLOC_CHECK_, 263
            obtaining statistics, 263
      dynamic memory, allocating, 245-255
            alignment, 252-255
            allocating arrays, 247
            freeing dynamic memory, 250-252
            resizing allocations, 249
      opportunistic allocation, 277
            overcommitment and OOM, 277
      stack-based allocations, 264-268
            duplicating strings on the stack, 266
            variable-length arrays, 267
      unlocking memory, 275
memory management, 243
      anonymous memory mappings, 256-260
            creating, 257
            mapping /dev/zero, 259
      data segment, managing, 255
      locking memory, 273-277
            demand paging, 273
            locking all of an address space, 275
            locking limits, 276
            locking part of an address space, 274
      manipulating memory, 269-273
            comparing bytes, 270
            frobnicating bytes, 272
            moving bytes, 271
            searching bytes, 272
            setting bytes, 269
      memory management units, 15
      process address space, 243-245
            memory regions, 245
            pages and paging, 243
            sharing and copy-on-write, 244
memory mapped I/O, 95-108
      changing the protection of a mapping, 104
      giving advice, 106-108
      mmap( ) function, 95-99, 100
            advantages, 101
            disadvantages, 102
            page size, 97-98
      munmap( ) function, 99
      resizing a mapping, 102
      SIGBUS and SIGSEGV signals, 99
      synchronizing a file with a mapping, 104
memrchr( ) function, 272
memset( ) function, 269
merging (I/O schedulers), 115
metadata, 196
migration of processes, costs, 173
MIME types, storage, 205
mincore( ) function, 276
mkdir( ) function, 218, 229
mktime( ) function, 320
mlock( ) function, 274
mlockall( ) function, 275
mmap( ) function, 95-99, 258
      advantages, 101
      disadvantages, 102
      example, 100
      page size, 97-98
      return values and erro codes, 99
mode argument, 27, 65
monotonic time, 308
mount points, 14
mounting, 14
mprotect( ) function, 104
mremap( ) function, 102
      return values and error codes, 103
msync( ) function, 105
      return values and error codes, 105
multiplexed I/O, 47-57
multitasking, 163
multithreaded programming, 166
munmap( ) function, 99, 258

N[ Top ]
named pipes, 13
namespaces, 14
      per-process namespaces, 15
nanosleep( ) function, 326
natural alignment, 71, 252
network filesystems, 14
nice( ) function, 170
nice values, 169
noinline keyword, 340
nonblocking I/O, 32
nonblocking writes, 35
Noop I/O Scheduler, 119
noreturn keyword, 342
null device, 231

O[ Top ]
O(1) process scheduler, 163
O_DSYNC flag, 40
offset, 74
offsetof( ) macro, 347
off_t type, 44
on_exit function, 138
OOM (out of memory) conditions, 278
open( ) function, 24-26
      O_DSYNC andO_RSYNC flags, 40
      O_SYNC flag, 39
Open Software Foundation (OSF), 7
opendir( ) function, 220
operational deadlines, 176
      latency and jitter, 177
opportunistic allocation, 277
origin argument, lseek( ), 42
O_RSYNC flag, 40
OSF (Open Software Foundation), 7
O_SYNC flag, 39
out of memory (OOM) conditions, 278
out-of-band communication, 233
overcommitment, 277

P[ Top ]
packed attribute, 343
pages, 97-98, 243
      page cache, 59
      page cache readahead, 60
      page size, 15
      page writeback, 60
PAGE_SIZE macro, 98
parameter passing, 3
parameters, marking as unused, 343
parent directories, 212
parent process, 17
parent processes, 127
      (see also processes)
partial writes, 34
path, 11
pathnames, 11, 212
pause( ) function, 287
pdflush threads, 61
pending signals, 297
permission bits, 18
per-process namespaces, 15
perror( ) function, 21
pgid (process group ID), 154
pid (process ID), 16, 126
      allocation, 127
pid_t type, 128
pointers, 255
poll( ) function, 53-56
      disadvantages, 89
      example, 55
      return values and error codes, 55
      select( ), versus, 57
Portable Operating System Interface (see POSIX)
POSIX, 6
      history, 6
      protection bits and architecture, 96
POSIX clocks, 313-315
      clockid_t type, 313
      time source resolution, 314
POSIX clocks-based timers, 333-338
      arming a timer, 335
      creating a timer, 333-335
      deleting a timer, 338
      obtaining timer expiration, 336
      obtaining timer overrun, 337
_POSIX_SAVED_IDS macro, 153
posix_fadvise( ) function, 108
      return values and error codes, 110
ppoll( ) function, 56
pread( ) function, 44
preemptive multitasking, 163
preemptive scheduling, 165
primary group, 17
process address space, 243-245
      mapped files, 245
      memory regions, 245
      pages and paging, 243
      sharing and copy-on-write, 244
process ID (pid), 16
process time, 308
process tree, 17
processes, 15-17, 126
      accesses, 18
      background process groups, 154
      child and parent processes, 127
      child processes, waiting for, 139-149
            BSD wait3( ) and wait4( ) functions, 145
            status pointer macros, 140
            wait( ) function, 139
            waitid( ) function, 143
            waitpid( ) function, 142
      copy-on-write (COW), 134
      daemons, 159-161
      doctrine of least-privileged rights, 150
      exec family of functions, 129-132
      file descriptors and, 23
      foreground process group, 154
      fork( ) function, 132-136
      hierarchy, 127
      initialization processes, 126
      I/O-bound processes, 164
      launching and waiting for new processes, 147
      migration costs, 173
      multitasking, 163
            yielding, 166-169
      new processes, running, 129
      obsolete process group functions, 158
      ownership, 127
      prioritization (see scheduler, prioritization)
      process group, 128
      process group system calls, 157
      process groups, 154-155
            process group ID (pgid), 154
      process hierarchy, 16
      process ID (pid), 126
            allocation, 127
      process IDs and parent process IDs, obtaining, 128
      processor-bound prccesses, 164
      reparenting, 149
      resource limits, 190-195
            default hard and soft limits, 193
            Linux, resource limits provided by, 191-193
            setting and retrieving limits, 194
            soft and hard limits, 190
      runlist, 162
      runnable processes, 162
      scheduler (see schedulers)
      sessions, 154-157
      terminating, 136-139
            atexit( ) function, 137
            by signal, 137
            classic method, 137
            exit( ) and _exit( ) functions, 136
            kill by kernel, 137
            on_exit( ) function, 138
            SIGCHILD, 139
      threads, 166
      timeslices, 162, 164
      users and groups, 149-154
            changing IDs, BSD methods, 152
            changing IDs, HP-UX methods, 152
            obtaining user and group IDs, 154
            preferred user/group ID manipulations, 153
            real, effective, and saved user and group IDs, 150
            real, effective user or group IDs, changing, 151
            real or saved user and group IDs, changing, 151
            support for saved user IDs, 153
      vfork( ) function, 135
      zombies, 17, 149
            waiting on zombie processes, 139
      (see also child processes; parent processes)
      (see also real-time systems)
processor affinity, 172-176
      sched_getaffinity( ) and sched_setaffinity functions, 173-176
programming
      multithreaded programming, 166
programming concepts, 9-22
      error handling, 19-22
      files, 9-15
            filesystems and namespaces, 14
      headers, 19
      interprocess communication, 19
      permissions, 18
      processes, 15-17
      signals, 19
      users and groups, 17
programs
      critical regions, 297
protection flags and architecture, 96
PROT_READ and PROT_EXEC flags, 96
pselect( ) function, 52
psignal( ) function,, 290
pthreads API, 166
pure functions, 341
pure keyword, 341
pwrite( ) function, 45

R[ Top ]
raise( ) function, 292
      signal for, 303
random number generators, 232
read( ) function, 29-33
      additional error values, 32
      nonblocking reads, 32
      positional reads, 44
            error values, 45
      reading all the bytes, 31
      return values, 30
      size limits, 33
read FIFO queue, 116
read latency, 116
read permissions, 18
readahead, 60, 107
readahead( ) function, 110
      return values and error codes, 110
readdir( ) function, 221, 222
readv( ) function, 84
      implementation, 88
      return values, 85
real gid, 17
real time, 308
real uid, 17
real user ID, 150
realloc( ) function, 249
real-time systems, 176-189
      determinism, 187-189
            CPU affinity and real-time processes, 188
            prefaulting data and locking memory, 187
      latency, jitter, and deadlines, 177
      real-time processes, precautions with, 186
      sched_rr_get_interval, 185
      scheduling parameters, setting, 182-185
            range of valid priorities, determining, 184-185
      scheduling policy and priorities, 178-182
            batch scheduling policy, 180
            FIFO class, 179
            normal policy, 180
            RR (round-robin) class, 179
            setting, 180-182
      soft versus hard real-time systems, 176
      support in Linux, 178
      (see also processes; schedulers)
records, 9
reentrancy, 293
      guaranteed-reentrant functions, 294
regular files, 9
relative pathnames, 11, 212
relative time format, 309
remove( ) function, 228
removexattr( ) function, 211
rename( ) function, 229
reparenting, 17
reparenting of processes, 149
resource limits of processes, 190-195
      default hard and soft limits, 193
      Linux, resource limits provided by, 191-193
      setting and retrieving limits, 194
      soft and hard limits, 190
rewind( ) function, 74
rlimit structure, 190
RLIMIT_CPU, 190
rmdir( ) function, 219
root directory, 11, 212
root filesystem, 14
root (root user), 17
round-robin (RR) class, 179
run list, 162
runnable processes, 162

S[ Top ]
saved group ID (gid), 17
saved user ID (uid), 17, 151
sbrk( ) function, 256
scatter/gather I/O, 84-89
      advantages, 84
      readv( ) and writev( ) functions, 84
            implementation, 88
            return values, 85
SCHED_BATCH, 180
sched_getaffinity( ) and sched_setaffinity functions, 173-176
sched_getparam( ) and sched_setparam( ) functions, 182-185
      error codes, 183
sched_getscheduler( ) and sched_setscheduler( ) functions, 180-182
SCHED_OTHER, 180
SCHED_RR, 179
sched_rr_get_interval, 185
      error codes, 186
schedulers, 162-166
      load balancing, 173
      multitasking, 163
      O(1) process scheduler, 163
      preemptive scheduling, 165
      process prioritization, 169-172
            getpriority( ) and setpriority( ) functions, 171
            I/O priorities, 172
            nice( ) function, 170
      processor affinity, 172-176
            sched_getaffinity( ) and sched_setaffinity functions, 173-176
      sched_rr_get_interval, 185
      scheduling parameters, setting, 182-185
            range of valid priorities, determining, 184-185
      scheduling policy, 178-182
            batch scheduling policy, 180
            FIFO class, 179
            normal policy, 180
            RR (round-robin) class, 179
            setting, 180-182
      (see also processes; real-time systems)
sched_yield( ) function, 166
      legitimate uses, 167
      Linux version 2.6, changes in, 168
sectors, 14
security namespace, 206
segmentation violations, signal for, 284
segments, 245
select( ) function, 48-53
      disadvantages, 89
      poll( ), versus, 57
      use for sleeping, 329
sequential locality, 60
sessions, 154-157
      session system calls, 156
setegid( ) function, 152
seteuid( ) function, 152, 153
setitimer( ) function, 282, 284, 332
setpgid( ) function, 157
setpgrp( ) function, 158
setresuid( ) function, 153
setreuid( ) function, 152
setrlimit( ) function, 190
setsid( ) function, 156
setsize parameter, 174
settimeofday( ) function, 318
setuid( ) function, 151, 153
setxattr( ) function, 208
si_code field, 302
      values valid for SIGBUS, 303
sigaction( ) function, 298-300
sigaddset( ) function, 296
sigandset( ) function, 296
SIGBUS signal, 99
SIGCHILD, 139
SIGCONT signal, 292
sigdelset( ) function, 296
sigemptyset( ) function, 296
sigfillset( ) function, 296
SIGHUP, 154
siginfo_t structure, 300-302
SIGINT, 154
sigisemptyset( ) function, 296
sigismember( ) function, 296
signal( ) and sigaction( ) functions, 139
signal( ) function, 286, 307
signals, 19, 279-286
      blocking signals, 296-298
            retrieving pending signals, 297
            waiting for a set of signals, 298
      concepts, 280
            identifiers, 280
      critical regions and, 297
      human-readable versus integer values, 281
      Linux, supported by, 281-286
      listing with kill -l command, 281
      payloads, sending signals with, 305
            example, 306
      reentrancy, 293
            guaranteed-reentrant functions, 294
      sending, 291-293
            examples, 292
            permissions, 292
            to a process group, 293
            to yourself, 292
      SIGINT and SIGTERM, 280
      SIGKILL and SIGSTOP, 280
      signal management, 286-291, 298-305
            examples, 287
            execution and inheritance, 289
            mapping signal numbers to strings, 290
            si_code field, 302-305
            sigaction( ) function, 298-300
            siginfo_t structure, 300-302
            waiting for signals, 287
      signal masks, 297
      signal sets, 295
      signal-safety, 294
sigorset( ) function, 296
sigpending( ) function, 298
sigprocmask( ) function, 297
sigqueue( ) function, 305
SIGSEGV signal, 99
sigsuspend( ) function, 298
Single Unix Specification (see SUS)
sleep( ) function, 324
sleeping, 324-330
sockets, 13
soft affinity, 173
soft links, 225
soft real-time systems, 176
soft resource limits, 190
software clocks, 309
sorting (I/O schedulers), 115
source compatibility, 5
special files, 13
stack, 245
      duplicating strings on, 266
      stack-based memory allocations, 264-268
            strings, duplicating, 266
            variable-length arrays, 267
standard error (stderr), 21
standard I/O, 64
      file pointers, 65
      limitations, 81
standard I/O library, 64
standards, 6
      as dealt with in this book, 8
stat( ) function, 197
stat family, 196-199
      stat structure, 197
            fields, 197-199
static priority, 178
status pointer, 140
stderr (standard error), 21
stdin, stdout, and stderr file descriptors, 23
stdio, 64
stime( ) function, 318
strdup( ), strdupa( ), and strndupa( ) functions, 266
streams, 65
      associated file descriptors, obtaining for, 77
      closing, 67
      closing all, 67
      file descriptors, opening via, 66
      flushing, 75
      reading from, 67-70
            putting the character back, 68
            reading an entire line, 68
            reading arbitrary strings, 69
            reading binary data, 70
            reading one character at at time, 67
      seeking a stream, 74
            obtaining current stream position, 75
      writing to, 70-72
            data alignment, 71
            writing a single character, 71
            writing a string, 72
            writing binary data, 72
      (see also buffered I/O)
strerror( ) function, 21
strerror_r( ) function, 21
strsignal( ) function, 290
subdirectories, 212
supplemental groups, 17
SUS (Single Unix Specification), 6
      history, 6
      standards UNIX 95, UNIX 98, and UNIX 03, 7
symbolic links (symlinks), 12, 223, 225
symlink( ) function, 226
symmetric multiprocessing, 172
sync( ) function, 39
synchronicity of write operations, 112
synchronization, 39
synchronized operations, 111
synchronous write operations, 111
sysconf( ) function, 98
sys_siglist, 290
system calls (syscalls), 3
      I/O calls and, 77
system clock, tuning, 321-324
system namespace, 205
system programming, xi, 1-4
      C compiler, 4
      C library (libc), 4
      functions
            parameter passing, 3
      programming concepts (see programming concepts)
      standards, 6
      system calls, 3
            invoking, 3
system software, xi, 1
system timer, 309
system timer frequency, 309

T[ Top ]
temporal locality, 59
text files and binary files, 66
text segment, 245
The C Programming Language, xi
The Open Group, 6
thread-based asynchronous I/O, 113
threads, 79, 166
      pthreads API, 166
      thread safety, 79-81
            manual file locking, 80
            unlocked stream operations, 81
thread-safety, 79
tick or jiffy, 309
time, 308-310
      C language conversion functions, 320-321
      current time, getting, 315-318
            microsecond resolution, 316
            nanosecond resolution, 316
      current time, setting, 318
            clock_settime( ) function, 319
      data structures, 310-313
            clock_t type, 313
            timespec (nanosecond precision), 311
            time_t, 310
            time_t and leap years, 315
            timeval (microsecond precision), 311
            tm structure for broken-down time representation, 312
      delta, 322
      epoch measurement, 309
      kernel, measurement by, 308
      measurement formats, 309
      POSIX clocks, 313-315
            clockid_t type, 313
            time source resolution, 314
      process time, getting, 317
      sleeping, 324-330
            alternatives to, 330
            microsecond precision, 325
            nanosecond precision, 326-329
            select( ) function for portability, 329
            timer overruns, 329
      system clock, tuning, 321-324
      timers, 330-338
            alarms, 330
            interval timers, 331-333
            POSIX clocks-based timers, 333-338
time( ) function, 315
timer_create( ) function, 334
timer_delete( ) function, 338
timer_getoverrun( ) function, 337
timer_gettime( ) function, 336
timer_settime( ) function, 335
times( ) function, 317
timeslices, 162, 164
time_t type, 321
toolchain, 6
truncate( ) function, 46
truncation, 10
trusted namespace, 206
typeof( ) keyword, 346

U[ Top ]
uid (user ID), 17
umask, 218
undefined keys, 204
Universal Time, Coordinated (UTC), 309
Unix, 1
Unix text editors, xi
unlikely( ) wrapper, 345
unlink( ) function, 227
unlinking, 12
unmounting, 14
unused attribute, 343
user ID (uid), 17
user namespace, 206
user time, 40, 317
user-buffered I/O, 62-64
user-buffered I/O (input/output)
      file descriptors, usage of, 23
usernames, 17
users, 17
      ownership of processes, 127
user-space applications, communication with kernel, 3
usleep( ) function, 325
UTC (Universal Time, Coordinated), 309

V[ Top ]
valid page, 244
variable-length arrays (VLAs), 267
variadic functions, 129
vectored I/O, 84, 86
vectors, 85
vfork( ) function, 135
VFS (see virtual filesystems)
virtual address space, 243
virtual file switch, 58
virtual filesystems (VFS), 14, 58

W[ Top ]
wait( ) function, 139
waitid( ) function, 143
waiting on zombie processes, 139
waitpid( ) function, 142
wall time, 308
warn_unused_result attribute, 342
watches, 236-242
      adding watches, 236
      advanced options, 240
      inotify events, 238-240
            advanced events, 239
            linking together move events, 240
            reading, 238
      watch masks, 236
whence, 74
word size, 44
-Wpointer-arith option, 349
write( ) function, 33-37
      additional error codes, 35
      append mode, 34
      behavior of write( ), 36
      nonblocking writes, 35
      partial writes, 34
      positional writes, 44
            error values, 45
      size limits on, 36
write FIFO queue, 116
write ordering, 36
write permissions, 18
writebacks, 36
writes-starving-reads problem, 116
writev( ) function, 85
      example, 86
      implementation, 88
      return values, 85

X[ Top ]
X/Open, 7
xattrs (see extended attributes)
xmalloc( ) wrapper, 247

Y[ Top ]
yielding, 163, 166-169
      legitimate uses, 167
      Linux version 2.6, changes in, 168

Z[ Top ]
zero device, 232
zombies, 17, 149
      waiting on zombie processes, 139





Return to Linux System Programming