448

Дж. Фуско - Linux. Руководство Программиста (2011)

Embed Size (px)

DESCRIPTION

Рук

Citation preview

  • . Linux.

    c .

    . . . . . , . , . . . , . .

    32.973.2-018.2 004.451

    .

    95 Linux. . .: , 2011. 448 .: .

    ISBN 978-5-49807-794-9

    -

    , GNU/Linux. , , -

    , ,

    . , , , -

    ,

    Linux . -

    . , -

    , -

    , .

    Prentice Hall PTR. . - .

    , , , -. , , - , .

    ISBN 978-5-49807-794-9 2007 Pearson Education, Inc.

    ISBN 0132198576 (.) , 2011

    ,

    , 2011

    , 194044, -, . ., 29. 005-93, 2; 95 3005 .

    24.09.10. 70100/16. . . . 36,12. 2000. 0000.

    CtP . . . .

    197110, -, ., 15.

  • , .

  • . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22

    1. . . . . . . . . . . . . . . . . . . . . . . . . . . . .23

    2. . . . . . . . .53

    3. . . . . . . . . . . . . . . . . . . . .96

    4. . . . . . 124

    5. Linux . . . . . 172

    6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

    7. . . . . . . . . . . . . . . . . . 261

    8. IPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308

    9. . . . . . . . . . . . . . . . . . . . . 326

    10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380

  • . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231.2. ? . . . . . . . . . 231.3.

    ? . . . . . . . . . . . . . . . . . . . . . . . . . 241.3.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241.3.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    1.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261.4.1. . . . . . . . . . . . . . . . . . . . . . . . . . . 271.4.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281.4.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    1.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321.5.1. : ? . . . . . . . . . . . . . . . 341.5.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

    1.6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

  • 9

    1.6.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . 361.6.2. . . . . . . . . . . . . . . . . . . . . . . 361.6.3.

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381.6.4. RPM GPG . . . . . . . . 381.6.5. , . . . . . . 41

    1.7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421.7.1. . . . . . . . . . . . . . . . . . . . . . . . . 431.7.2. RPM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451.7.3. Debian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

    1.8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471.8.1. Apt: Advanced Package Tool . . . . . . . . . . . . . . . . . . . . . . 481.8.2. Yum: Yellowdog Updater Modified . . . . . . . . . . . . . . . . . . 491.8.3. Synaptic: GUI- APT . . . . . . . . . . . . . . . . . . 491.8.4. up2date: Red Hat . . . . . . . . . . . . . . 51

    1.9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

    2. . . . . . . . . . . . . 532.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

    2.2.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542.2.2. make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552.2.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712.2.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

    2.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742.3.1. GNU- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742.3.2. : configure . . . . . . . . . . . . . . . . . . 752.3.3. : make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762.3.4. : make install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

    2.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 782.4.1. , Makefile . . . . . . . . . . . . . . . . . 782.4.2. . . . . . . . . . . . . . . . . . . . . . . . . 802.4.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812.4.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832.4.5. . . . . . . . . . . . . . . . . . . . . . . 852.4.6. . . . . . . . . . . . . . . . . . . . . . . . . . . 93

    2.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

    3. . . . . . . . . . . . . . . . . . . . . . . . . . . . 963.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 963.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

  • 10

    3.2.1. man . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973.2.2. man . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973.2.3. man: apropos . . . . . . . . . . . . . . 993.2.4. man:

    whatis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1013.2.5. man . . . . . . . . . . . . . . . . . . 1023.2.6. man . . . . . . . . . . . . . . . . . . 1033.2.7. GNU- info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053.2.8. info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053.2.9. info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083.2.10. info . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083.2.11. . . . . . . . . . . . . . . . . 109

    3.3. . . . . . . . . . . . . . . . . . . . . . . . . . 1103.3.1. /usr/share/doc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1103.3.2. . . . . . . . . . . . . . . . . . . . . . . . . 1103.3.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

    3.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1133.4.1. TeX/LaTeX/DVI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1133.4.2. Texinfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1133.4.3. DocBook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1143.4.4. HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1143.4.5. PostScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153.4.6. Portable Document Format (PDF) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153.4.7. troff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

    3.5. . . . . . . . . . . . . . . . . . . . . . 1163.5.1. www.gnu.org . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1163.5.2. SourceForge.net . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1173.5.3. The Linux Documentation Project . . . . . . . . . . 1173.5.4. Usenet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1183.5.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1193.5.6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

    3.6. Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1193.6.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1193.6.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1213.6.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

    3.7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1223.7.1. , . . . . . . . . . . . . . . . 1223.7.2. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

    4. . . . . . . . . . . 1244.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

  • 11

    4.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1244.2.1.

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1264.2.2. : vi Emacs . . . . . . . . . . . . . . . . . . 1274.2.3. Vim: vi . . . . . . . . . . . . . . . . . . . . . . . 1274.2.4. Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1444.2.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1514.2.6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

    4.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1544.3.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1554.3.2. . . . . . . . . . . . . . . . . . . . . 1564.3.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1574.3.4. diff patch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1584.3.5. . . . . . . . . . . . . . . . . . . . . . . . 159

    4.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

    4.4.1. indent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

    4.4.2. astyle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1654.4.3. cflow . . . . . . . . . . . . . . . . 1654.4.4. ctags . . . . . . . . . . . . . . . . 1654.4.5. cscope . . . . . . . . . . . . . 1664.4.6.

    Doxygen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1664.4.7. . . . . 168

    4.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1694.5.1. , . . . . . . . . . . . . . . . 1694.5.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1704.5.3. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

    5. Linux . . . . . . . . 1725.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1725.2. . . . . . . . . . . . . . . . . . . . . . 1725.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

    5.3.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1755.3.2. , . . . . . . . . . . . . . . . . . . . . . . . . 1755.3.3. . . . . . . . . . . . . . . . . 1765.3.4. nice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1775.3.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1775.3.6. . . . . . . . . . . . . . . . . . . . . 1795.3.7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

  • 12

    5.3.8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1835.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

    5.4.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1905.4.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1915.4.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1925.4.4. / . . . . . . . . . . . . . . . . . . . . . . 197

    5.5. / . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2025.5.1. Linus Elevator ( noop) . . . . . . . . . . . . . 2035.5.2. /

    (Deadline I/O Scheduler) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2045.5.3. /

    (Anticipatory I/O Scheduler) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2045.5.4. /

    (Complete Fair Queuing I/O Scheduler) . . . . . . . . . . . . . . . . . . . . . . . . . 2045.5.5. / . . . . . . . . . . . . . . . . 205

    5.6. . . . . . . . . . . . . . . . . . . . . 2065.6.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2065.6.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

    5.7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2295.7.1. , . . . . . . . . . . . . . . . 2295.7.2. API-, . . . . . . . . . . . . . . . . 2295.7.3. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2305.7.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

    6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2316.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2316.2. ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

    6.2.1. fork vfork . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2316.2.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2326.2.3. clone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233

    6.3. exec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2346.3.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2346.3.2. . . . . . . . . . . . . . . . . . . . . . . . . . . 2366.3.3. . . . . . . . . . . . . . . . . . . . . . . . . . . 236

    6.4. wait . . . . . . . . . . . . . . . . . . . . . . . . . 2386.5. , . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

    6.5.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2426.5.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2446.5.3. . . . . . . . . . . . . . . . . . . . . . . 246

    6.6. . . . . . . . . . . . . . 2466.7. procfs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250

  • 13

    6.8. . . . . . . . . . . . . . . . . . . . . . . . . . . 2526.8.1. ps . . . . . . . . 2526.8.2.

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2546.8.3. ps pgrep . . . . . . . 2566.8.4.

    pmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2566.8.5. . . . . . . . . . . . . . . 258

    6.9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2596.9.1. API-,

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2596.9.2. , . . . . . . . . . . . . . . . 2606.9.3. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260

    7. . . . . . . . . . . . . . . . . . . . . . . . . 2617.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2617.2. IPC . . . . 261

    7.2.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2627.2.2. ,

    IPC . . . . . . . . . . . 2627.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

    7.3.1. API- POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

    7.3.2. API- System V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

    7.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2697.4.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2707.4.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2717.4.3. . . . . . . . . . . . . . . . . . . . . . . 2727.4.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2757.4.5. sigqueue

    sigaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2777.5. () . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2807.6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280

    7.6.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2817.6.2.

    socketpair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2837.6.3. /, . . . 2847.6.4. /, . . . 289

    7.7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2907.7.1. System V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

  • 14

    7.7.2. POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2947.7.3. POSIX

    System V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2967.8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

    7.8.1. API- POSIX . . . 3017.8.2. API- System V . . .304

    7.9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3067.9.1. API-, . . 3067.9.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3077.9.3. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307

    8. IPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3088.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3088.2. . . . . . . . . . . . . . . . . . . . 308

    8.2.1. lsof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3088.2.2. fuser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3108.2.3. ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3108.2.4. file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3108.2.5. stat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311

    8.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3118.3.1. strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3118.3.2. xxd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3128.3.3. hexdump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3138.3.4. od . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313

    8.4. System V IPC . . . . . . . . . . . . . . . 3148.4.1. System V . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3148.4.2. System V . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3168.4.3. System V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317

    8.5. POSIX IPC . . . . . . . . . . . . . . . . . . . . . 3188.5.1. POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3188.5.2. POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3198.5.3. POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

    8.6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3208.7. () . . . . . . . . . . 321

    8.7.1. FIFO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3218.7.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322

    8.8. IPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323

    8.9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3248.9.1. , . . . . . . . . . . . . . . . 3248.9.2. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325

  • 15

    9. . . . . . . . . . . . . . . . . . . . . . . . . . . . 3269.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3269.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326

    9.2.1. , . . . 3269.2.2.

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3359.2.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3389.2.4.

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3439.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349

    9.3.1. : time . . . . . . . . . . . . . . . . . . . 3509.3.2.

    x86info. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3509.3.3. Valgrind . 3539.3.4. ltrace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3579.3.5. strace

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3589.3.6. :

    gcov gprof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3599.3.7. OProfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365

    9.4. . . . . . . . . . . . . . . . . . . . . . . 3709.4.1.

    SMP . . . . . . . . . . . . . . . . . . . . . . . . . . 3709.4.2.

    SMP . . . . . . . . . . . . . . . . . . . . . . . . . . 3759.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378

    9.5.1. , . . . . . . . . . . . . . . . . . 3789.5.2. , . . . . . . . . . . . . . . . . . . . . . . 3799.5.3. , . . . . . . . . . . . . . . . 3799.5.4. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3799.5.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379

    10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38010.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38010.2. : printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380

    10.2.1. , printf . . . . . . . . . . . 38110.2.2. printf . . . . . . . . . . . . . 38510.2.3. printf . . . 393

    10.3. GNU- gdb . . . . . . . . . . . . . . . . . . . . . 39310.3.1. gdb . . . . . . . . . . . . . . . . . . . . 39410.3.2. . . . . . . . . 395

  • 16

    10.3.3. . . . . . . . . . . . . . . . . . . 40210.3.4. gdb . . . . 41110.3.5. . . . . . . . . . . . . . . . . . . . . . . . . . 41210.3.6. gdb . . . . . . . . . . . 41510.3.7. . . . . . . . . . . . . . 417

    10.4. . . . . . . . . . . . . . . . . . . . . . . . . 41810.4.1. . . . 41810.4.2. . . . . . . . . . . . . . . . . 41910.4.3.

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42010.4.4.

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42110.4.5. . . . . . . . . . . . . 42110.4.6.

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42210.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425

    10.5.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42610.5.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42610.5.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42710.5.4. , glibc . . . . . . . . . . . . . . 42910.5.5. Valgrind . . . . . 43210.5.6. Electric Fence . . . . 437

    10.6. . . . . . . . . . . . . . . . . . . . . . . . . . . . 43910.6.1. . . . . . . . . . . . . . . . . . . . 43910.6.2. . . . . . 44310.6.3. . . . . . . . 44310.6.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44410.6.5. procfs . . . . . . . . . . . . . . 445

    10.7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44710.7.1. , . . . . . . . . . . . . . . 44810.7.2. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44810.7.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448

  • , Linux. ls, grep, find sort , ++, Linux. Linux , . , , : ? .

    , Linux .

    , , /proc, Linux .

    , , , , , , . , , Linux ( UNIX!).

    . , . , .

    . (Arnold Robbins),

  • Linux . UNIX, , . , , .

    . . , . , . , grep , . , ( , ). , , grep.

    , , , : Linux , . , . , . , , . . , .

    . , , API, . , Linux, . : . , , , , .

    MAN . GNU Linux , . ,

  • 19

    , .

    GNU/Linux , . 10 000 , , . . , , . , , , , Linux .

    , , . Linux , , URL, .

    , .

    Linux

    , Linux. Windows, Linux , .

    , . , Linux.

    ,

    Linux Journal , Linux. Linux. , . . , , , , . . , , , .

    . , Linux.

  • 20

    . Linux , , , Windows.

    , , , .

    .

    , . , , , .

    , , . , .

    1

    . , , . , , .

    2, , . , . make. , , GNU autoconf. , . , , .

    3 , Linux, . .

    4, , , , . , , , , .

  • 21

    , .

    5 Linux . , Linux. , .

    6 , . . , API, .

    7, , IPC. , 8. IPC API, .

    8 IPC , IPC. 7, , .

    9, , , , . , , . .

    10 . , Valgrind Electric Fence. , gdb , .

  • ,

    . , , . . , , , .

    (Arnold Robbins) . . , .

    (Debra Williams Cauley) , , . , , , .

    , , (Mark Taub) , .

    (John Fusco) GE Healthcare,

    , , Linux. UNIX Linux 2.0. , Embedded Systems Programming Linux Journal.

    ,

    [email protected] ( , ).

    ! http://www.piter.com

    .

  • 1

    1.1. ,

    . , , . , .

    , , , , , . , . , , , .

    .

    1.2. ?

    , Open Source Initiative (OSI) (www.opensource.org). , GNU Project, (Richard Stallman). Open Source Initiative , .

  • 24 1.

    . , . : , . , ( GNU Public License) , , .

    , . . . , .

    1.3. ?

    , . , , . , . : , , .

    . , ( ), . , , , , . , . , . , , , . , . , , .

    1.3.1. ,

    . Linux

  • 251.3.

    DVD, , . , . , . , .

    , . , , . , , .

    , . . www.freshmeat.net. , , , . , , www.freshmeat.net 71 . : 71 !

    www.freshmeat.net , . , , Linux, , , . , Linux, , Open Source Initiative ( www.freshmeat.net ). 12 . , , , , -. , , AbiWord, , . , , , , OpenOffice, . , OpenOffice , , Office/Business :: Office Suites. : , , .

    1.3.2. ,

    . , .

  • 26 1.

    . . : , ; , . , : , , , .

    , Linux TAR. , , tar. gzip, . TAR- .

    1.4.

    . , . Windows, , , PKZip. Linux ( , , PKZip, ). , ( gzip bzip2). UNIX.

    Linux , , , , . , , TAR, .

    . , . , (, //).

    . 1.1 Linux . TAR. tape archive, tape. tar . cpio, . , pax POSIX, TAR, CPIO PAX. PAX, .

  • 271.4.

    1.1.

    tar cpio RPM; -

    ar Debian; -

    . AR

    ar, , , Debian.

    , ZIP, PKZip, , LHA. Linux . ZIP, , , Microsoft.

    1.4.1. ,

    . ; . 1.2 .

    1.2.

    .tar TAR, .tar.gz, .tgz TAR, gzip.tar.bz2 TAR, bzip2.tar.Z, .taz TAR, UNIX compress.ar, .a AR, -

    .cpio CPIO,

    , file. , . , . , TAR c foo.x. . :

    $ file foo.xfoo.x: gzip compressed data, from UNIX, max compression

  • 28 1.

    , gzip, , TAR. gzip file z:

    $ file -z foo.xfoo.x: tar archive (gzip compressed data, from UNIX, max compression)

    . ,

    , .

    1.4.2. ,

    , t . TAR Debian cron:

    $ tar -tzvf data.tar.gzdrwxr-xr-x root/root 0 2001-10-01 07:53:19 ./drwxr-xr-x root/root 0 2001-10-01 07:53:15 ./usr/drwxr-xr-x root/root 0 2001-10-01 07:53:18 ./usr/bin/-rwsr-xr-x root/root 22460 2001-10-01 07:53:18 ./usr/bin/crontabdrwxr-xr-x root/root 0 2001-10-01 07:53:18 ./usr/sbin/-rwxr-xr-x root/root 25116 2001-10-01 07:53:18 ./usr/sbin/cron

    v , ls. , . ( ), 0. .

    . 1.3 , . .

    1.3.

    TAR tar -tvf filename TAR, gzip

    tar -tzvf filename

    TAR, bzip2

    tar -tjvf filename

    CPIO cpio -tv < filename CPIO stdin stdout

    , . ,

  • 291.4.

    //, .

    . . , , .

    . . 1.4 .

    1.4.

    - , , -

    . .d c ,

    . /dev;

    b , . /dev;

    l , . , , -

    , . , r, w x. , . , w , . . 1.5 .

    1.5.

    rwx , rw- , -

    r-x ,

    --x ,

    , setuid, setgid sticky. , .

  • 30 1.

    setuid , , , , . , , . root setuid, , . , ? setuid .

    setgid , , . , , . setgid, , .

    , setuid setgid , , x . x , , , .

    setuid setgid . x s, , setuid . S, setuid, . , , . , root, . Linux root , - . , root, , root.

    setuid, setgid x . s , setgid . S, , setgid, .

    cron , crontab setuid, root. . 1.6 .

    sticky, . , . Linux sticky , . ,

  • 311.4.

    , . , . , , , , . , sticky. , . , root . sticky /tmp.

    1.6.

    -

    -rwxr-xr-x -

    -

    -

    -rw-r-xr-x - ;

    -

    -

    -rwsr-xr-x -

    -

    -rwSr-xr-x

    -

    -rwxr-sr-x -

    -

    -rwsr-sr-x -

    -rwsr-Sr-x , ,

    sticky t T. :

    -rwxrwxrwt , sticky;

    -rwxrwx--T , sticky.

    1.4.3. , ,

    . . 1.7 .

  • 32 1.

    1.7.

    TAR tar -xf filename -

    TAR, - gzip

    tar -xzf filename

    TAR, - bzip2

    tar -xjf filename

    CPIO cpio -i -d < filename

    AR ar x filename

    , , . , , CPIO . , , CPIO, /etc, . , CPIO , /etc/hosts. , /etc/hosts, , . , :

    cpio -t < foo.cpio/etc/hosts

    / , /etc/hosts, . , , , , . GNU --no-absolute-filenames, hosts ./etc/hosts.

    , CPIO RPM, , .

    , TAR, UNIX, . GNU TAR Linux / , TAR. , TAR UNIX, GNU TAR . , / , .

    1.5. ,

    .

  • 331.5.

    , . , . , , KDE GNOME, , , . , , , , , .

    . , , . , . , . . upgrade, .

    . . , , , . , , , .

    : RPM ( RPM Package Manager1) Debian. . 1.8. , RPM Red Hat Fedora, Suse. Debian Debian (Knoppix, Ubuntu .). pkgtool, Slackware, portage, Gentoo.

    1.8. Linux

    Red Hat RPMFedora RPMDebian DebKnoppix DebUbuntu DebGentoo portageXandros DebMandriva ( Mandrake) RPMmepis DebSlackware pkgtool

    1 Red Hat Package Manager.

  • 34 1.

    , . , , .

    1.5.1. : ?

    Linux 32 Intel , . , TAR. , .

    Linux , . , . , , . , , .

    . 1.9 , RPM. , GNU, . , . i386, Pentium Pentium II. , Linux 80386, .

    1.9.

    i386 ; gss -

    80386. , Pentium I

    i486 . , 80486 ( )

    i586 . GNU- i586 Pentium I. Pentium

    i686 GNU- i686 Pentium Pro, Pentium II . Pentium II

    ix86 , Pentium

  • 351.6.

    x86_64 AMD Opteron Intel Pentium 4 EM64T.

    , 32-, 64- . - 64- , 32- , Opteron EM64T 32- Linux

    IA64 64- Itanium. , Intel Hewlett-Packard,

    ppc PowerPC G2, G3 G4, Apple Macintosh Apple iMac

    ppc64 PowerPC G5 Apple iMacsparc SPARC, Sunsparc64 64- SPARC, Sunmipseb MIPS, -

    SGI

    1.5.2. Linux

    , Linux . , , , . . , , :

    ; ( ) ; , ;

    ; (, ?);

    .

    1.6.

    . Linux, , Windows, , .

    : ,

  • 36 1.

    . , , .

    : . , .

    Linux . root, sudo. , . , , . .

    1.6.1. ,

    , . Linux , . , , . , root, . , , , .

    , , , . , root. . , rpm . Debian, .

    1.6.2.

    . , . , . , ,

  • 371.6.

    . , .

    , , . , . , , . (, 128), , . , , :

    ;

    , , , .

    md5sum MD51, 128 . md5sum . , . , :

    $ md5sum foo.tar bar.taraf8e7b3117b93df1ef2ad8336976574f *foo.tar2b1999f965e4abba2811d4e99e879f04 *bar.tar

    md5sum, :

    $ md5sum foo.tar bar.tar > md5.sums$ md5sum --check md5.sumsfoo.tar: OKbar.tar: OK

    , 32 ( 4 ). , , . MD5 , , MD5. , , MD5, . MD5 , . , , MD5 .

    1 MD5 Message Digest 5.

  • 38 1.

    1.6.3.

    MD5, , , . , , , , . , , . , , .

    , , : . , . , . . , . .

    GNU Privacy Guard (GPG). GPG . 1.1.

    . 1.1. GPG

    1.6.4. RPM GPG

    RPM GPG . RPM ,

  • 391.6.

    MD5, , RPM. RPM, , . GPG RPM. , MD5 , .

    rpm checksig, , , . , GPG, rpm MD5. GPG, gpg ok. :

    $ rpm checksig *.rpmabiword-2.2.7-1.fc3.i386.rpm: sha1 md5 OKabiword-plugins-impexp-2.2.7-1.fc3.i386.rpm: sha1 md5 OK

    abiword-plugins-tools-2.2.7-1.fc2.i386.rpm: sha1 md5 OKfirefox-1.0-2.fc3.i386.rpm: (sha1) dsa sha1 md5 gpg OKdpkg-1.10.21-1mdk.i586.rpm: (SHA1) DSA sha1 md5 (GPG) NOT OK (MISSING KEYS: GPG#26752624)

    , RPM, GPG firefox dpkg. firefox, dpkg. , firefox , rpm . . dpkg GPG, . , , . rpm .

    firefox , Red Hat Fedora. Fedora , Red Hat . . RPM , , Red Hat . dpkg , Mandrake, Fedora. .

    , , dpkg , rpm , . , , rpm 4.3.2 . , , root. GPG . . ,

  • 40 1.

    , , . , . , GPG , , .

    , GPG, - . Mandrake. :

    $ rpm -qip dpkg-1.10.21-1mdk.i586.rpmName : dpkgVersion : 1.10.21 Vendor: MandrakesoftRelease : 1mdk Build Date: Thu May 20 07:03:20 2004

    Host: n1.mandrakesoft.comPackager : Michael Scherer URL : http://packages.debian.org/unstable/base/dpkg.htmlSummary : Package maintenance system for Debian

    . URL- mandrakesoft.com mandrake.org. - , 2004 , , , . Mandrake Mandriva, . , , . , , : - .

    $ rpm --checksig dpkg-1.10.21-1mdk.i586.rpmdpkg-1.10.21-1mdk.i586.rpm: ...... (GPG) NOT OK (MISSING KEYS: GPG 78d019f5)

    .

    Mandriva. Google http://mandriva.com. , , , . - . , Mandriva .

    Google, , . www.keys.pgp.net, 0x78d019f5.

    Search results for '0x78d019f5'

    Type bits/keyID cr. time exp time key expirpub 1024D/78D019F5 2003-12-10

    uid MandrakeContrib sig sig3 78D019F5 2003-12-10 __________ __________ [selfsig]sig sig3 70771FF3 2003-12-10 __________ __________ Mandrake Linux

  • 411.6.

    sig sig3 26752624 2003-12-10 __________ __________ MandrakeCooker sig sig3 45D5857E 2004-09-22 __________ __________ Fabio Pasquarelli (Lavorro) sig sig3 17A0F9A0 2004-09-22 __________ __________ Fafo (Personale)[email protected]

    sub 1024g/4EE127FA 2003-12-10sig sbind 78D019F5 2003-12-10 __________ __________ []

    Mandrake, , - Mandrake. 78D019F5, PGP . , 78D019F5.txt :

    rpm --import 78D019F5.txt

    , . :

    rpm --checksig dpkg-1.10.21-1mdk.i586.rpmdpkg-1.10.21-1mdk.i586.rpm: (sha1) dsa sha1 md5 gpg OK

    gpg OK , .

    , . pgp.net. , - , . , .

    1.6.5. ,

    , , , , , . , . , , , .

    , . Linux , . , , .

    . , , , OpenSSH. ,

  • 42 1.

    , . , . , . , , . 2.

    , . , root, . , .

    . , . /usr/sbin /sbin, . setuid setgid, root. , . ; .

    , . , .

    1.7.

    . :

    , ; TAR, CPIO ;

    , ; , , ;

    . , ,

    , . , .

  • 431.7.

    , , .

    , . Slackware, , . , . RPM . RPM , . , , ( Slackware).

    . . , , . , , .

    .

    . . , .

    , , , .

    .

    , , . , , , , SourceForge.net. , , . , .

    1.7.1. , .

    , Linux . , , . . , , .

  • 44 1.

    , , , . , gcc, foo.rpm. RPM :

    $ rpm -qip foo.rpm

    :

    $ rpm -qi gcc

    rpm RPM, , p. , .

    , , , , , , . , , . . . 1.10 RPM Debian.

    1.10.

    RPM Debian rpm -qpi _ dpkg -s _ rpm -qpl _ dpkg -L _ / rpm -qp -scripts _ dpkg -e rpm --checksig _ ,

    rpm -qp --requires _ dpkg -I

    , (, , )

    rpm -qp --provides _ dpkg -I

    . , . , , . . . 1.11.

    1.11.

    RPM Debian - rpm -qi dpkg -s

    rpm qa dpkg list

  • 451.7.

    RPM Debian , - -

    rpm -ql dpkg -L

    , --

    rpm -V cd /;md5sum -c $@

    # 3object.o: source.c gcc -c source.c -o $@

    # 4program2: program2.c gcc -o program2 program2.c

    , make , :

    $ makeecho 'main() {}' > source.cgcc -c source.c -o object.ogcc -o program object.o

    make Makefile , . , , 1. :

    1 : program object.o:object.o y 3; 3 ; y object.o , program, program gcc;

  • 572.2.

    3 : object.o source.c:source.c y 2; 2 ; y source.c , object.o, object.o gcc;

    2 : source.c : y source.c , echo.

    , . , Makefile . , , 2 3 Makefile, .

    , 4 . , make . 4 , program2 , program2.c . , 4 . make program2, 4. Makefile , .

    make Makefile, . , , . , program2.c , . :

    $ make program2.o

    program2.o , program2.c.

    make , , . , . all Makefile. , , , Makefile:

    program1: a.o b.o gcc -o program1 a.o b.o

    program2: c.o d.o gcc -o program2 c.o d.o

    make , program1 . , , :

    $ make program1 program2

    , make .

  • 58 2.

    all Makefile, program1 program2 :

    all: program1 program2

    program1: a.o b.o gcc -o program1 a.o b.o

    program2: c.o d.o gcc -o program2 c.o d.o

    make make all, program1, program2. all , fred . , make . , .

    , , , , . : GNU make , :

    .PHONY: all

    make all .

    Makefile: make

    . :

    VAR = valueVAR := value

    , , := . , :

    VAR = value

    # ! VAR = $(VAR) more

    # , := VAR := $(VAR) more

    # GNU-, VAR = valueVAR += more

    GNU make : define endef. GNU :

  • 592.2.

    define VARvalueendef

    , .

    , . ASCII, , .

    make , . , = , .

    :

    , - ; ; - , $(); define , , - .

    Makefile: ,

    , , , :

    $(MACRO) # ${MACRO} # ,

    , , , . .

    , , Makefile 1. , Makefile ,

    1 , .

  • 60 2.

    , Makefile, . Makefile , . Makefile , Makefile . Makefile:

    FLAGS = first

    all: @echo FLAGS=$(FLAGS)

    FLAGS = second

    other: @echo FLAGS=$(FLAGS)

    , FLAGS all, other, . FLAGS , . FLAGS , make , , , , .

    Makefiles

    Makefile , . Makefile , , . , , , .

    , make , , . make , , Makefile. . make Makefile! :

    $ echo "main() {}" > foo.c$ make foocc foo.c -o foo

    , make , foo.c. foo.

    Makefile . GNU make ,

  • 612.2.

    , . .

    . , , GNU make , :

    .c.o: $(COMPILE.c) $(OUTPUT_OPTION) $ foo.c$ gcc -c -Wall foo.cfoo.c:1: warning: type defaults to 'int' in declaration of 'x'foo.c:1: warning: data definition has no type or storage class

    ansi. pedantic, , . .

    , . , , int, , . :

    int foo(); //

    , . , ANSI. , . , . , . .

    , Wall , . , , -Wstrict-prototypes. , gcc (3.4.4) :

  • 872.4.

    foo.c:2: warning: function declaration isn't a prototype

    , , , , .

    , Wall, , . GNU

    printf, , . , . 2.9.

    2.9. ,

    printf scanfprintf vprintf scanf vscanffprintf vfprintf fscanf vfscanfsprintf vsprintf sscanf vsscanfsnprintf vsnprintf

    , . %s printf, , , . , , , %s , char *. , . , :

    1 #include 2 void foo(int x)3 {4 printf("%s", x);5 }

    Wall, :

    $ gcc -c -Wall foo.cfoo.c: In function 'foo':foo.c:4: warning: format argument is not a pointer (arg 2)

    , ( printf) . %s , , char *, , int *, . .

    , . , IA32 . IA32 ;

  • 88 2.

    , , . , printf .

    , , , . IA32 , . , long int int . , long %d ( long %ld). IA32 , long , int. 64 . x86_64 (Opteron, Xeon/EM64T) int 32, long 64. , 64 .

    printf , scanf . , scanf . , . , scanf, .

    , Wall, .

    -Wformat-nonliteral , , , . , . , , , .

    -Wformat-y2k strftime strptime, , printf. , .

    , GNU- , , GNU

    . , , .

    Null pointer arguments ( NULL) NULL . , NULL . glibc 3.4.4, /++ .

    Missing parentheses ( ) , ,

  • 892.4.

    , if. . :

    if ( x = y ) //versus... if ( x == y )

    1 , . , 2. , . , :

    if ( (x = y) )

    Missing braces ( ) , if/else . :

    1 void foo(int x, int y, int *z) 2 { 3 if ( x == y ) 4 if ( y == *z ) *z = 0.0; 5 else 6 *z = 1.0; 7 }

    , else 5 if 3, , else if 4. :

    $gcc -c -Wall foo.c paren.c: In function 'foo': paren.c:3: warning: suggest explicit braces to avoid ambiguous 'else'

    , if else:

    1 if (x == y) { 2 if (y == *z) { 3 *z = 0.0; 4 } 5 } 6 else 7 { 8 *z = 1.0; 9 }

    Uninitialized variables ( ) , . ,

  • 90 2.

    . , . :

    1 int foo(int y) 2 { 3 int x; 4 if ( y > 0 ) { 5 x = 1; 6 } 7 return x; 8 }

    x , y

  • 912.4.

    5 virtual char *ptr() { return m_ptr; }; 6 ~Base() { delete [] m_ptr; } ; 7 }; 8 9 class Foo : public Base { 10 char *foo_ptr; 11 public: 12 Foo() { foo_ptr = new char[1024]; }; 13 virtual char *ptr() { return foo_ptr; }; 14 virtual ~Foo() { delete [] foo_ptr; } ; 15 };

    $ gcc -Wall -c polymorph.cpppolymorph.cpp:1: warning: 'class Base' has virtual functions but nonvirtual destructor

    Base , , Foo *. , ~Foo . Base .

    Reordered initializers ( ) , , , . , . , , . , :

    1 struct Foo { 2 int m_two; // declaration 3 int m_one; 4 Foo( int one ) 5 : m_one(one), // initializer 6 m_two(m_one+1) {}; 7 }; 8 9 #include 10 11 int main(int argc, char **argv[]) 12 { 13 Foo f(1); 14 std::cout

  • 92 2.

    5 6. , . , , m_two , , . , m_two m_one, , m_two. , m_two m_one.

    Deprecated features ( ) , STL (Standard Template Library) (, iostream.h ). :

    warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wnodeprecated1.

    , , . , , #include . . . , std , using. , ++ ++. .

    / y -Wno-deprecated.

    y ( )2.

    y .

    1 : . 32 17.4.1.2 ++. , . , Wnodeprecated.

    2 using namespace std . , , .

  • 932.4.

    Incompatible ABI ( ABI) -Wall, Wabi. ABI (Application Binary Interface), . ++, , Fortran, Fortran, . , Fortran ABI. ABI , .

    ABI , . ABI, ABI . ++ ABI. , ABI , ++. , , GNU ++, , , ABI . ++, GNU 3., c , 2., , ABI.

    2.4.6.

    , . , . , , , . :

    $ g++ -Wall -o main main.o -lfoomain.o(.text+0x11): In function 'main':: undefined reference to 'bar()'

    , , , , .

    , ++, , . , ++ .

  • 94 2.

    ++, , , . .

    , , , , . , . nm. bar() , , :

    $ nm -u main.o | grep bar U _Z3barv

    _Z3barv , g++ 3.3.5 void bar(void). libfoo , , . , ++ . , , . , .

    , , . , :

    main.c1 extern void two();2 int main(int argc, char *argv[]) { two(); }

    one.c1 void one(void) { }

    two.c1 extern void one(void);2 void two(void) { one(); }

    :

    $ ar -clq libone.a one.o$ ar -clq libtwo.a two.o$ gcc -o main main.c -L. -lone -ltwo./libtwo.a(two.o)(.text+0x7): In function 'two':/home/john/src/linker/two.c:5: undefined reference to 'one'collect2: ld returned 1 exit status

    two() one(), libtwo.a libone.a . libone.a, l . two() main(). one() , , one().

  • 952.5.

    libtwo.a two() main(). one(). , one().

    . :

    $ gcc -o main main.c -L. -ltwo -lone

    . , , , , .

    2.5.

    . make , ++. .

    :

    configure , GNU Makefile, make;

    cons Perl, make;

    make UNIX ++; scons cons Python, cons.

    :

    www.gnu.org/software/autoconf GNU autoconf, GNU;

    www.gnu.org/software/make GNU make;www.python.org Python;www.scons.org scons.

  • 3

    3.1. : .

    , . , .

    , , . , .

    3.2.

    UNIX 1. , . , , man . GNU Texinfo, , info. man info, , .

    man info , .

    1 , , .

  • 973.2.

    3.2.1. man

    HTML PDF, . , , Linux, . man , PDF. , man , .

    man troff. , . , troff, HTML, , . HTML PDF. , , man PostScript, t:

    $ man -t man | lp -Pps

    , PostScript, .

    man. Red Hat , RPM, man, Debian mandb. , man. mandb man, .

    3.2.2. man Linux .

    Filesystem Hierarchy Standard (www.pathname.com/fhs), , , man. . 3.1.

    3.1. Linux

    1 2 3 4 /dev5 (, /etc)6 7 8

  • 98 3.

    man . sync, , 1, sync 2. man sync. , . , man, . man sync, :

    $ man sync

    man sync, , sync , 2. man , :

    $ man 2 sync

    , . Perl. 3 Fedora. POSIX ( ). man sync, 2. man, , :

    $ man -a sync

    man , Q man .

    , , . , sync 2 sync(2), sync 3 sync(3). man, .

    , , , . , . , man 8 (System Administration Commands ( )), 3 (Programming Libraries ( )). , ( ?). , man accept, 3, man accept man accept Common UNIX Printer System, 8. , , , , . whatis:

  • 993.2.

    $ whatis acceptaccept (8) - accept/reject jobs sent to a destinationaccept (2) - accept a connection on a socket

    man , . , 8, 2. , man 2.

    man , . Fedora Ubuntu ( Debian) /etc/man.config, Knoppix ( Debian) /etc/manpath.config. mandb ~/.manpath. (. 3.1).

    . 3.1. khelpcenter man

    3.2.3. man: apropos

    , . : apropos whatis.

  • 100 3.

    propos UNIX , , , . apropos , . , ( ).

    , apropos NAME , . NAME, apropos . . , , , . , man manual ( ), command () . . . .

    , . , compression () , apropos compression, : bzip2 gzip. , Fedora Core 4:

    $ apropos compressionCompress::Zlib (3pm) - Interface to zlib ...pbmtopsg3 (1) - convert PBM ...SSL_COMP_add_compression_method (3ssl) - handle ...zlib (3) - compression/decompression ...

    , compression () compress () compressor (), , , gzip bzip2 . . whatis, :

    $ whatis gzip bzip2gzip (1) - compress or expand filesbzip2 (1) - a block-sorting file compressor, v1.0.2

    apropos Red Hat . , mandb apropos Debian , , . 1. :

    $ apropos 'mag[tn]'mt (1) - control magnetic tape drive operationmt-gnu (1) - control magnetic tape drive operation

    1 regex(7).

  • 1013.2.

    rmt (8) - remote magtape protocol modulermt-tar (8) - remote magtape protocol modulexmag (1x) - magnify parts of the screen

    mag[tn] magtape ( ) magnify (), , . mandb apropos Debian e. , , compress (), compressor (). . 3.2 .

    3.2.

    mandb-

    man , . man ( ), . , , .

    3.2.4. man: whatis

    , man , , , . , , , readdir, man readdir, 2 , :

    This is not the function you are interested in. Look at readdir(3) for the POSIX conforming C library interface. This page documents the bare kernel system call interface, which can change, and which is superseded by getdents(2)1.

    , man , , , POSIX. , . , man , whatis:

    1 , . POSIX readdir(3), . , getdents(2).

  • 102 3.

    $ whatis readdirreaddir (2) - read directory entryreaddir (3) - read a directory

    man 3, :

    $ man 3 readdir

    whatis , , mandb . , , zip, :

    $ whatis -w "*zip"funzip (1) - filter for extracting from a ZIP ..gunzip (1) - compress or expand filesgzip (1) - compress or expand filesunzip (1) - list, test and extract compressed ...zip (1) - package and compress (archive) files

    man . man a, man, . , . , man -a read Fedora Core 4 man. man , .

    3.2.5. man man Linux ,

    7 1. man NAME, , . apropos.

    , man NAME. , .

    SEE ALSO man . , man, ( ). , , . , man , .

    1 . man(7).

  • 1033.2.

    SEE ALSO . , man.

    ENVIRONMENT , . , . , , . ENVIRONMENT .

    , , CONFORMING TO, , . , . , Linux . , . , bcopy , memcpy, CONFORMING TO bcopy, , 4.3BSD. memcpy 4.3BSD, , ISO C (ISO 9899), .

    man BUGS. , , , . BUGS , , . , . , , , .

    3.2.6. man ,

    , . 1, :

    $ whatis introintro (1) - Introduction to user commandsintro (2) - Introduction to system callsintro (3) - Introduction to library functionsintro (4) - Introduction to special filesintro (5) - Introduction to file formatsintro (6) - Introduction to gamesintro (7) - Introduction to conventions and miscellany sectionintro (8) - Introduction to administration and privileged commands

    1 intro(2). .

  • 104 3.

    , , , , . , , , . 7, , , . . 3.3 7, .

    3.3. 7 ,

    ascii(7) ASCII . ,

    , , Ctrl+G

    boot(7) . , Linux

    bootparam(7) , . , , ,

    charsets(7) , Linux, . , - (i18n)

    hier(7) Filesystem Hierarchy Standard, Linux. , : /bin /usr/bin? , , ,

    man(7) man? , - troff, , man Linux

    operator(7) . - , . :if ( 1 & 2 == 2 ) printf(bit one is set\n);

    regex(7) , -

    suffixes(7) Linux . - . . ,

    units(7) , SI6 (SI Systme International dunits ). , , SI, 1 1 000 000, 1 048 576 ? , . , .

  • 1053.2.

    units(7) SI ,

    . , , . , 1 048 576 ( M). , , , . , . -

    uri(7), url(7), urn(7) man, URL- . , URL, , , , -

    , man, . 3.3, 7, , . , man.

    3.2.7. GNU- info GNU

    info. GNU man info.

    GNU info Texinfo. troff, Texinfo HTML XML, . TeX ( ) Scribe, . Texinfo , . troff, Texinfo HTML .

    3.2.8. infoGNU info GNU

    Emacs. . 3.2 , info Emacs. Emacs, . info. , man, info , , less, man. man info . , vi, less,

  • 106 3.

    , vi. , info Emacs . info --vi-keys, vi , info , vi less.

    . 3.2. Emacs info

    , info. man, . , info, . info info, info, info. info info-stnd. man , .

    , info . man, info. info info, man.

    , Emacs info, pinfo (http://pinfo.alioth.debian.org). , man, . info, ,

  • 1073.2.

    , . , , vi.

    GUI, info. URL info:topic. GNOME gnomehelp, man info. !

    KDE khelpcenter, info (. 3.3).

    . 3.3. khelpcenter info

    info , , . , , :

    $ info "(make)Quick Reference"

    , , , . pinfo info , khelpcenter, . , man, info :

    $ info --subnodes some-topic | less

  • 108 3.

    --subnodes info stdout. less man.

    3.2.9. info man, info

    -apropos. info , -apropos, , info , apropos, man. man, . man, . , , .

    info w, , whereis, , info , , man.

    3.2.10. info GNU

    man info, GNU man , gcc. Texinfo. man gcc 3.4.4, , 54 000 , info 158 000 . info , man .

    , info. . 3.4 .

    3.4. info,

    info coreutils ,

    . UNIX - , . (Arnold Robbins) Linux Journal, - Opening the software toolbox ( )

    cpp , - , . man . , - info

  • 1093.2.

    info gcc ,

    man gcc, . -

    ld , , , . , info

    libc -

    man info , .

    3.2.11.

    Linux : GNOME KDE. , . GNOME gnomehelp ( yelp), 2.10.0 GNOME. . , . HTML, README HTML. Mozilla Firefox . , ? Mozilla Firefox URL:

    $ firefox file:///usr/share/doc/someproject/README.html

    , file: ( ). yelp , Mozilla Firefox. , , , :

    $ yelp README.html

    , yelp HTML , man man.

    yelp, khelpcenter HTML. khelpcenter

  • 110 3.

    yelp. khelpcenter KDE, man info GNU. info, , , , man . SEE ALSO man man, . . khelpcenter . , , .

    3.3.

    , , , man info. , . README . , , .

    3.3.1. /usr/share/doc Filesystem

    Hierarchy Standard, man info. , README.

    , , . , , README.

    HTML man. . , Texinfo, , DocBook.

    Debian doclinux, /usr/share/doc HOWTO The Linux Documentation Project (www.tldp.org) ( ). .

    3.3.2.

    . ,

  • 1113.3.

    , . Linux , , , . Linux , .

    man, SEE ALSO. , DHCP dhcpd man. , dhcpd DHCP. , dhcpd.conf, . man, SEE ALSO. man :

    SEE ALSO dhclient(8), dhcrelay(8), dhcpd.conf(5), dhcpd.leases(5)

    , man, . , man .

    man apropos, . , , . , , man, . apropos , . , man. man makewhatis, cron. , man . , , . , , , .

    mandb man , ( ) mandb. , mandb , makewhatis. cron. info . info apropos --apropos. apropos, .

  • 112 3.

    3.3.3. 1 .

    . . , . , /usr/bin diffstat , . , man diffstat, . :

    $ rpm -qf /usr/bin/diffstatdiffstat-1.38-2

    , , /usr/bin/diffstat. diffstat1.382. , :

    $ rpm -qi diffstat...Summary : A utility which provides statistics based on the output of diff.Description : ...

    , , , , , , . README HTML, . man. , . diffstat1.382 , man :

    $ rpm -ql diffstat/usr/bin/diffstat/usr/share/man/man1/man1/usr/share/man/man1/man1/diffstat.1.gz

    man1 man1, man . diffstat, , . . , , man, :

    $ man /usr/share/man/man1/man1/diffstat.1.gz

    , man , . Debian undocumented(7), man, .

  • 1133.4.

    3.4. Linux .

    , , , . troff, man. , . , LaTeX, , . GNU Texinfo, . , HTML, . ? : .

    3.4.1. TeX/LaTeX/DVI TeX LaTeX UNIX. LaTeX

    TeX. TeX LaTeX, . TeX, , , , . TeX , , . , TeX .

    TeX DVI ( Device Independent ). xdvi, kdvi evince, DVI .

    TeX LaTeX .tex , . TeX latex; tex. LaTeX , , LaTeX, , . , Makefile.

    3.4.2. TexinfoTexinfo GNU.

    GNU

  • 114 3.

    info Emacs . , info, /usr/share/info, Texinfo. Texinfo makeinfo. Texinfo , info. .info, Texinfo .texi .texinfo.

    , Texinfo, . Texinfo, , , /usr/share/doc. , , info.

    Texinfo makeinfo. info, HTML, DocBook, XML .

    3.4.3. DocBookDocBook SGML ( Standard Generalized

    Markup Language), . , DocBook , SGML Document Type Definition (DTD). SGML XML. DocBook , SGML: , . , .

    DocBook DTD SGML, XML, DocBook .sgml. DocBook , .

    3.4.4. HTML HTML

    , Texinfo, DocBook troff. , , , vi Emacs. , , JavaScript . yelp khelpcenter . HTML /usr/share/doc.

    HTML, man . ,

  • 1153.4.

    NTP (Network Time Protocol) HTML, . 3.4.

    . 3.4. HTML- NTP

    3.4.5. PostScript PostScript, Adobe,

    Portable Document Format (PDF). PostScript UNIX. ( , ) PostScript, , PDF.

    GNU Ghostscript PostScript UNIX. Ghostscript , PostScript, PostScript ( ) . Ghostscript PostScript , .

    3.4.6. Portable Document Format (PDF) PDF

    , , . ,

  • 116 3.

    , . , , .

    Ghostscript PDF, Adobe Acrobat Reader. , . xpdf1 , . GNOME evince , , xpdf. GNOME evince PostScript, PDF DVI.

    3.4.7. trofftroff man.

    , UNIX2. groff GNU troff, , man. , :

    $ man intro$ gzip -dc /usr/share/man/man1/intro.1.gz | groff -man -Tascii | less

    man man gzip.

    groff DVI troff, . HP PCL PostScript. , UNIX. DVI, , .

    3.5.

    , . , . , .

    3.5.1. www.gnu.org Linux,

    .

    1 . www.foolabs.com/xpdf.2 , , roff(7) .

    , .

  • 1173.5.

    , , . GNU C (glibc), , , 1300 . 60 Texinfo GNU.

    3.5.2. SourceForge.net ,

    GNU, SourceForge.net, , . , , . , strace, Ubuntu, SourceForge.net.

    $ dpkg -s stracePackage: straceMaintainer: Roland McGrath Description: A system call tracer strace is a system call tracer, i.e. a debugging tool ...

    SourceForge.net, , man. , SourceForge.net , . RPM, , URL RPM:

    $ rpm -qi straceName : stracePackager : Red Hat, Inc. URL : http://sourceforge.net/projects/strace/Summary : Tracks and displays system calls ...

    RPM, , . Debian SourceForge.net .

    3.5.3. The Linux Documentation Project

    www.tldp.org, . man, Linux. , , , . .

  • 118 3.

    , HOWTO, Guides (), FAQ ( ) , , man.

    , . Linux , . , , .

    HOWTO , , . HOWTO , . HOWTO , , .

    FAQ Usenet, 1. , . , FAQ , , , , . FAQ, , FAQ TLDP , ( ). , FAQ.

    FAQ The Linux Documentation Project www.tldp.org/FAQ/LDP-FAQ/index.html.

    3.5.4. UsenetUsenet , .

    Usenet , . , , . , .

    , Usenet Google . , . , , , , .

    , Usenet, . , . , .

    1 , , FAQ Frequently Asked Questions.

  • 1193.6. Linux

    , Usenet . Usenet .

    3.5.5. , .

    , , , ( ). , , . , , .

    (MARC) http://marc.theaimsgroup.com. Linux, , .

    3.5.6. Linux Usenet ,

    , . , , , . .

    3.6. Linux

    Linux . , . , Linux, . Linux. , http://kernel.org, . , , .

    3.6.1. .

    2.6 , ,

  • 120 3.

    . , , README, . What Is Linux ( Linux), . , , Makefile. , , :

    $ make help

    Cleaning targets: clean - remove most generated files but keep the config mrproper - remove all generated files + config + various backup files

    Configuration targets: config - Update current config utilising a line-oriented program menuconfig - Update current config utilising a menu based program xconfig - Update current config utilising a QT based frontend gconfig - Update current config utilising a GTK based frontend oldconfig - Update current config utilising a provided .config as base randconfig - New config with random answer to all options defconfig - New config with default answer to all options allmodconfig - New config selecting modules when possible allyesconfig - New config where all options are accepted with yes allnoconfig - New minimal config

    Other generic targets: all - Build all targets marked with [*]* vmlinux - Build the bare kernel* modules - Build all modules modules_install - Install all modules dir/ - Build all files in dir and below dir/file.[ois] - Build specified target only rpm - Build a kernel as an RPM package tags/TAGS - Generate tags file for editors cscope - Generate cscope index

    Static analysers buildcheck - List dangling references to vmlinux discarded sections and init sections from non-init sections checkstack - Generate a list of stack hogs namespacecheck - Name space analysis on compiled kernel

  • 1213.6. Linux

    Kernel packaging: rpm-pkg - Build the kernel as an RPM package binrpm-pkg - Build an rpm package containing the compiled kernel & modules deb-pkg - Build the kernel as an deb package

    Documentation targets: Linux kernel internal documentation in different formats: xmldocs (XML DocBook), psdocs (PostScript), pdfdocs (PDF) htmldocs (HTML), mandocs (man pages, use installmandocs to install)

    Architecture specific targets (i386):* bzImage - Compressed kernel image (arch/i386/boot/bzImage) install - Install kernel using (your) ~/bin/installkernel or (distribution) /sbin/installkernel or install to $(INSTALL_PATH) and run lilo bzdisk - Create a boot floppy in /dev/fd0 fdimage - Create a boot floppy image

    make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build make O=dir [targets] Locate all output files in "dir", including .config make C=1 [targets] Check all c source with $CHECK (sparse) make C=2 [targets] Force check of all c source with $CHECK (sparse)

    Execute "make" or "make all" to build all targets marked with [*]For further info see the ./README file

    , Kconfig, . , make config, make menuconfig . . Kconfig , .

    3.6.2. Linux

    , . modinfo , . . modinfo , . , . , ,

  • 122 3.

    modinfo, , . , .

    3.6.3. ,

    Documentation. 700 , , DocBook. DocBook . , , , :

    $ make pdfdocs # C PDF-$ make mandocs # C man$ make psdocs # C PostScript-

    , , .

    3.7.

    Linux , . . , Linux. .

    3.7.1. ,

    man UNIX. apropos man.

    whatis whatis ( makewhatis) man.

    info GNU, .

    yelp GNOME, .

    khelpcenter KDE. evince GNU DVI, PDF, PostScript .

  • 1233.7.

    makeinfo Texinfo (HTML, DocBook .).

    gs Ghostscript; GNU PostScript.

    xpdf PDF X Window.

    3.7.2. -www.troff.org , troff.www.pathname.com/fhs Filesystem Hierarchy Standard.

    http://marc.theaimsgroup.co m , .

    www.foolabs.com/xpd f xpdf.www.gnome.org/projects/evince evince.pinfo.alioth.debian.org pinfo.

  • 4

    4.1. ,

    . , , , , . , , .

    . . , , . , .

    , . , .

    4.2. ,

    , . . . , .

  • 1254.2.

    , IDE (Integrated Development Environment), . , . , , .

    , . . , , , . Linux , . 4.1.

    4.1.

    vi/Vim Vi UNIX, -

    POSIX. - , , , . Vim vi - , Linux

    Emacs Emacs GNU- . - , - . Emacs GNU/Linux

    , . , -, WordStar

    GUI--

    - GUI- , . : - . ,

    vi Emacs. vi POSIX, , Linux UNIX. Emacs Linux. Emacs UNIX, .

  • 126 4.

    4.2.1.

    , , , , . .

    , , . . 4.2.

    4.2.

    , -

    {}, () [], - . - , . , ,

    - . , , , -

    , - , . - , , . -

    , . , - , .

    . , , , . , -

  • 1274.2.

    ctags etags

    . - . Emacs vi , , ,

    - , - . , -

    4.2.2. : vi Emacs

    vi Emacs UNIX ( Linux). X, . ( ), . . vi Emacs , , , GUI. : , GUI 1.

    4.2.3. Vim: vi vi POSIX

    UNIX. . , . Vim , Linux. Vim ( vi Improved vi) vi, , vi.

    Vim

    , Vim , . 4.2,

    1 , .

  • 128 4.

    vi Linux. , . , . . , , , .

    . 4.3 vi Vim. Vim ' , . , vi, Vim, vi, , Vim, Vim.

    4.3. vi Vim

    vi Vim -

    GUI-

    vi , . , , , GUI Emacs, , . vi : , Ex. , ( ) . , , vi.

    , , vi ,

    !. . , () . , , , . , vi . ,

  • 1294.2.

    . , vi, .

    . 4.1 vi, .

    . 4.1. vi

    , , Esc. , . , , Ex.

    vi. ?... , . , j, . . . , , , , .

    . . i a . , , , . , jkhl , , .

    , . . , 40j, 40 . , . , vi. , Vim .

  • 130 4.

    . 4.4

    . , , . . jkhl, .

    4.4. ,

    j k h l Enter G . ,

    . , - . , 50G 50-

    + -

    -

    % . - , (), {} [], -

    [[ , - { .

    ]] [[, , -

    {mark} , m. - m

    () , - . , , , -

    /{expr} . /, - . Enter. . ( ). . - ws . 4.18

  • 1314.2.

    ?{expr} .

    /, , - . -

    n , -

    N -,

    w b

    . , , . 4.4, , . , . . 4.5.

    4.5.

    Ctrl+F Ctrl+B Ctrl+] , . -

    ctags, Ex :ta

    Ctrl+T ( Back -)

    ,

    , . . , . , , i. . 4.6 , .

    4.6.

    i , a ,

  • 132 4.

    I ,

    A , -

    o , -

    O , -

    , . 4.8, (d) . 4.12. Vim ( . 4.7) , . vi Vim. , 4s vi , . Vim .

    4.7.

    C , ,

    . D (. . 4.10) A

    c{motion} , - motion, . , . 4.4

    {N}s () N , . c, , - . 5s c51

    S () . - ( - )

    4.8.

    2cw ; -

    cta

    . - ta

    5cta -

    5S -

    4.6 ()

  • 1334.2.

    , ,

    . , (u), vi . Vim . vi , , Vim , . vi , . Vim , Ctrl+R. . 4.9 , .

    4.9.

    u ,

    .

    Ctrl+R ( - Vim)

    m{letter} . , -

    . Ctrl+L . ,

    zt

    zz

    zb

    , , vi

    (register) , (clipboard). , . (cut) (paste) vi (-) (yank) (put). , (delete) , .

    , . , . 4.10,

  • 134 4.

    . vi, , , , 5, 5 .

    4.10. ,

    D ,

    . ()

    d{motion} , . motion. dd. (). , . 4.4

    y{motion} ( ). - motion. yy. , - . 4.4

    p () , ,

    P () , ,

    motion, , . motion , . 4.4, . 4.11.

    , . 4.11, , . , . . 4.12 d y, , .

    4.11.

    f{char} ,

    t{char} f, ,

    F{char} ,

    T{char} F, ,

  • 1354.2.

    4.12.

    dfa ,

    , , . : , a

    dta , -, , . : a

    5yta ,

    yy4p - . : 1) yy ( ) 2) 4 ( )

    dn , . d n

    da , a. d - a

    yG , . y G. , G

    y50G , 50- , 50- . y 50G

    d5l , - ( l , ). d 5l

    5dd . - dd ,

    , . 4.12, y d . , .

    Ex vi

    . Ex , vi, , Ex, . , Ex , , . Ex , . , Ex . Ex

  • 136 4.

    , , , . , , . , Ex .

    . 4.1 , Ex , (:). Enter, Ex. Enter , vi .

    Ex : , :

    :[firstline][,lastline]command

    , . . , . , . , , . , , , 25 30 , d :

    :25,30d

    . . 4.13.

    4.13. Ex

    . $ %

    , 1,$a a. , -

    m/{expr}/ , ?{expr}? , \/ \? \&

    . 4.14 Ex, , , vi. , , , . , :w . , :

    10,20w foo.dat

  • 1374.2.

    10 20 foo.dat. , . , .

    4.14. Ex

    write :w {filename}

    . . vi . - :w! , , . :w!

    quit :q vi ( , ). :q! , - vi . . :e

    xit :x vi - . , . :x! , - , . :wq

    edit :e {filename} . . , vi - , - , - . , :e!

    delete :d map :map {a} {b} ,

    .

    set :set {argument} Vim (. . 4.18). .vimrc

    help :help Vim. . vi, , vi, - Vim

  • 138 4.

    , , Ex, sed ( ). , , .

    Vim

    . , . , . Vim vi. Vim , , vi. , , . 4.15 .

    4.15. , Vim

    Ctrl+N/Ctrl+P , -

    . , Vim - , -, , . , Ctrl+N, - Ctrl+P

    Ctrl+T/Ctrl+D ( vi). - shiftwidth. 8 , set shiftwidth

    Ctrl+R , Vim. :help registers. - . , , : % , . ()

    Ctrl+V ( vi). , -, vi. -

    ,

    Ex. , , , .

  • 1394.2.

    Ex substitute, subst , , s. Ex, , . 4.13. substitute :

    :s/search/replacement/flags

    . replacement flags . replacement , . (/), , . , vi , , . vi :

    :s/\/usr\/bin\/file1/\/usr\/bin\/file2\//

    Vim ctags,

    , Vim. ctags :

    $ ctags -R

    , , tags. Vim . POSIX , ctags vi , Fortran, ctags Exuberant, Linux, , , C++, Java Python.

    vi Ex. . 4.16 , . Vim, , , vi. vi , ++, . , Vim , , Back .

    4.16.

    Ctrl+]

  • 140 4.

    :tag name :ta . ,

    Ctrl+T

    :pop :po ( Vim). -

    Ctrl+T, ,

    :tnext :tn ( Vim). , , - ++.

    :tprevious :tp ( Vim). :tnext, ,

    :tselect name :ts ( Vim). - , ,

    :tags ( Vim). ,

    Vim GUI , . 4.16, .

    IDE. . Vim IDE, , , . , IDE, Vim Makefile. Vim make :make, . , Vim , . :make Ex:

    :make arguments

    :make make . , . Vim , . , ,

    4.16 ()

  • 1414.2.

    . 4.17. , Vim. POSIX vi make, . 4.17.

    4.17. , Vim

    :make arguments :mak make

    :cnext :cn , -

    :cprev :cp ,

    :cfile filename :cf - :cnext :cprev. make

    vi , vi,

    Ex :set. , vi .exrc, , Vim .vimrc. , Vim .exrc .vimrc. , vi. , .exrc , , , Vim, .vimrc. vi .exrc source .vimrc , .exrc:

    :so ${HOME}/.exrc

    .vimrc , Vim. . 4.18 , .vimrc .exrc.

    4.18. ,

    tabstop ts set ts=4 - ( 8). , ,

  • 142 4.

    shiftwidth sw set sw=4 , - ( 8). , tabstop

    autoindent ai set ai - : ai , noai ( )

    expandtabs et set et , - , tabstop. - (ASCII- \011)

    wrapscan ws set ws : ( ), , . , Ex. , - .

    syntax sy sy on ( Vim). . - , set

    makeprg mp set mp=ant ( Vim). , make,

    errorformat efm set efm=%f\ %d ( Vim). Vim scanf- , - , . Vim, :help efm

    , :set, (, :syntax).

    GUI

    Vim GUI, , GNOME gvim, KDE kvim1.

    1 , KDE GNOME , kvim gvim .

    4.18 ()

  • 1434.2.

    GUI vi. , Vim, gvim (-y). Vim GUI, .

    , GUI, vi. , . , , GUI, . , GUI, . . 4.19 , KDE GNOME.

    4.19. , GUI- Vim

    Knoppix (KDE) vim-gtkUbuntu (KDE) kvimUbuntu (GNOME) vim-gnomeFedora