Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://al.cs.msu.su/books/avst/unix.pdf
Äàòà èçìåíåíèÿ: Thu Sep 28 11:27:38 2006
Äàòà èíäåêñèðîâàíèÿ: Mon Oct 1 20:02:58 2012
Êîäèðîâêà:
. .

. . , . . , . .

Unix


2006


519.6

, . : avst@cs.msu.ru.

c .., .., .., 2006

27 2006 .



Unix. . Unix- . , Unix, , , ; , Unix, Gnu ( gcc, gdb Gnu Make), . . , ; , Unix- . , C C++, Unix .. ; .

3


1



i386 , Unix. FreeBSD Linux, i386, . , Unix . , SunOS/Solaris, HPUX, AIX, Digital Unix (DEC Unix), Minix, FreeBSD, NetBSD, OpenBSD, BSDi, Linux . , Unix , , Unix' (Unix-like). Unix , . Unix , Unix' 1970- . , . , Unix . Unix'. Unix' ; , , , , Windows, MacOS .. , . , ­ . , (GUI) ; , . ; 4


, Unix , , , C Unix. , ´ , Unix, , . , , , Unix . ; , . Unix , . , , , Unix , .

5


2

Unix

Unix: Bourne Shell vim, joe Midnight Commander.

2.1



, , FreeBSD Linux, , , , . . , , (login) (password). , . , Login incorrect, , . , , , , CapsLock. . (, putty) ­ , . , . Unix- , , . , . X Window startx1 ; xterm,
1 ;

6


, . 3. , ( , ). , xterm. . passwd yppasswd. ( ). , () . , . , , , . . , , . - , , ( , , , , , ­ ). , , 1sS,7sL..

2.2

.

Unix MSDOS WinXX, ­ , ( A:, C: ..), , Unix , (/). . ­ . () , pwd: $ pwd /home/stud/s2003324 , , ls: 7


$ ls Desktop

tmp

Unix , .. , a.b..c...d....e . , , , . , , ls -a: $ ls -a . .. .bash_history Desktop tmp

, . , -F: $ ls -aF ./ ../ .bash_history Desktop/ tmp/

, , .bash_history, . , . ­ , .. ­ , ( /home/stud). cd: $ pwd /home/stud/s2003324 $ cd tmp $ pwd /home/stud/s2003324/tmp $ cd .. $ pwd /home/stud/s2003324 $ cd /usr/include $ pwd /usr/include $ cd / $ pwd / $ cd $ pwd /home/stud/s2003324 8


cp mv rm mkdir rmdir touch less

1:

, cd , . 1. , '-'. , rm -r the_dir the_dir .

2.3



Unix . . , , . , -, ; -, (.., , MSWord ); , -, , .. , . , , , m - i. , , : mmmmmmmmmm iiiiiiiiii , ( , , ), 9


^ $ x dw dd d$ J i a o O . u U

( ) ( ) (insert) , (append) , (undo) , 2: vim

: mmmmmmmmmm iiiiiiiiii 2.3.1 vim

vim (Vi Improved) Unix- VI. , .. VI . , Unix, , .. , , . , vim 10


H

J

K

L

. 1: vim

, , . , vim, : vim, Escape, :q!, . vim, vim myfile.c. myfile.c , . , , vim ­ : . . , .., , . , vim j, k, h l , , , , (. . 1).
, UNIX , Esc (0x1b); -, Esc-, , , ­ Esc . (, ) .

2. i, a, o, O . , . , Backspace 11


:w :w :w! :wq :q :q! :r :e :ls :b

, ( ) readonly ( ) , ( ) N

3: vim . , vim, , . . Escape. ( ) /, Enter. , /myfun myfun . , / Enter. (, , ) , , Enter. , , .. (. 3). :b Ctrl-^. . , , V; , 12


, v. h,j,k l. d, - y. , , , . p ( ) P ( ). . , , (x, dd, dw, d$ .) . yy, yw, y$ , , , . vim , - . ctags, : $ ctags *.c *.h tags, . - , . Ctrl-]. , , make (.§4.3), vim , gcc. make vim. , make prog, vim :make prog. , , " " . , , :cc, ­ :cn. 2.3.2 jo e

Unix JOE ( Jonathan's Own Editor). joe, 13


Ctrl-K D Ctrl-K X Ctrl-C Ctrl-Y Ctrl-K B Ctrl-K K Ctrl-K C Ctrl-K M Ctrl-K Y Ctrl-K L Ctrl-Shift-'-' Ctrl-^ Ctrl-K F Ctrl-L

(undo) (redo)

4: joe joe myfile.c. myfile.c , . vim, joe . , Enter, Backspace .. , Delete. , Ctrl-K. , Ctrl-K h (. 4). 2.3.3 Midnight Commander

( ) Midnight Commander MSDOS, Norton Commander. mc. F4; , Shift-F4. , . . , 14


, . ­ Fill tabs with spaces . , F9, Options , ­ General . Midnight Commander, . , , F9, Options , - Save Setup .

2.4



Unix 12- , 2 . 9 ; , . , . , ls -l, : $ ls -l /bin/cat -rwxr-xr-x 1 root root 14232 Feb 4 2003 /bin/cat

-rwxr-xr-x ( ; , , d ..) , , ( rwx, .. , ), ( r-x, .. ). , /bin/cat , root (.. ). , , . ( ) , - ( ) . 1, - 2, - 4; , .., ,
2

- permissions

15


6 (4 + 2), - 5 (4 + 1). , /bin/cat 07553 . . . , .. ( , , , .. ). , , , , , . , , , , . , , , , . , .. .
() SetUid Bit (04000), SetGid Bit (02000) Sticky Bit (01000). SetUid Bit, ( - root) , . SetGid Bit , ( ). suid- passwd. Sticky Bit, , Unix , , ; , . SetGid Bit , , , , . Sticky Bit , , , ( ) .

chmod4 . 3 , ; C , 4 Change Mo de

16


, : chmod 644 myfile.c myfile.c , - . [ugoa][+-=][rwxsXtugo] u, g, o a , , (user), (group), (others) (all). + , - ­ , = ­ . r, w, x , , , , s ­ / Set- ( ), t Sticky Bit. X () / , , - . chmod -R, . , chmod a+x myscript myscript ; chmod go-rwx * , . chmod -R u+rwX,go=rX ~ , ; , , .

2.5

- Bourne Shell

, Unix , - 0 , 1 2 . , , . 17


cmd1 > file1

cmd1

cmd2

cmd3 cmd1

cmd4 cmd5

cmd1, file1. , , ­ . >> file1 cmd1, file1. , . < file2 cmd2, file2 . , . > file1 < file2 cmd3, , . | cmd2 cmd1 cmd2, . 2> errfile errfile. 2>&1 | cmd6 cmd5 cmd6 5: -

, / . , Bourne Shell, - . <, >, >>, >& | (. 5). Unix less, , " ", " ", PgUp, PgDn . . , . less , , - , . , ls -lR | less 18


, . , gcc . , , , , , : gcc -Wall -g myprog.c -o myprog 2>&1 | less

2.6



, , ps: $ ps PID TTY 2199 pts/5 2241 pts/5

TIME CMD 00:00:00 bash 00:00:00 ps

, , . , ps ( , FreeBSD Linux). ; , ps ax , ps axu 5 . top, . , . top, q. . SIGTERM (15), ­ SIGKILL (9). SIGTERM , , ; SIGKILL , - .
5 Linux FreeBSD. , SunOS/Solaris, ps

19


kill. SIGTERM, .., , kill 2763 , 2763 SIGTERM. , (TERM, KILL ..). ; 2763 SIGKILL: kill -9 2763 kill -KILL 2763

2.7



, /. , . , . ls -lR /. , . , , , , . , &, : $ ls -lR / >list.txt 2>/dev/null & [1] 2437 /dev/null6 , . , 1, ­ 2437. jobs: $ jobs [1]+ Running ls -lR / >list.txt 2>/dev/null &

6 /dev/null , ; ,

20


. : [1]+ Done ls -lR / >list.txt 2>/dev/null &

, , , : [1]+ Exit 1 ls -lR / >list.txt 2>/dev/null &

, , ( SIGTERM): [1]+ Terminated ls -lR / >list.txt 2>/dev/null &

, , , %. , kill %2 SIGTERM . % . , . Ctrl-Z, . bg7 , . (.. , ) . fg8 .

2.8



Unix , . , man, info.
7 8

background ­ foreground

21


2.8.1

man

man . Unix, , C ( ), , .. , ls, $ man ls , , , waitpid(), $ man waitpid man . , , . q ( quit). , , . /, Enter. / Enter ( ). , ? /. . , write write. write , , man write, , ; , , . . , $ man 2 write , write, 2 . : 22


· 1 ­ Unix ( , ls, rm, mv .. ) · 2 ­ Unix · 3 ­ C ( , , sprintf) · 4 ­ · 5 ­ · 6 ­ · 7 ­ (, man 7 ip TCP/IP) · 8 ­ Unix (, mount, ). , ; , Tcl , "n", "3n" .. 2.8.2 info

man , info , ; , info , ­ () , . info , man. , man make make, info make make (. §4.3), .. info . n p , , . * ::, : * Reading Makefiles:: How makefiles are parsed Reading Makefiles Enter, . , l ( last). info q ( quit) Ctrl-C. 23


2.9
2.9.1


Bourne Shell

Bourne Shell , , (). , Bourne Shell, #!/bin/sh Bourne Shell , , , . . , , : I=10 MYFILE=/tmp/the_file_name MYSTRING="Here are several words" , , ( ) , , , ­ . $, : echo $I $MYFILE $MYSTRING : 10 /tmp/the_file_name Here are several words , : echo ${I}abc : 10abc $(( )). , 24


I=$(( $I + 7 )) I . Bourne Shell test . , () , ­ (). test , ( ), , . . [ -f "file.txt" ] # [ "$I" -lt 25 ] # [ "$A" = "abc" ] # [ "$A" != "abc" ] #

file.txt I 25 A abc A abc

, , : if [ -f "file.txt" ]; then cat "file.txt" else echo " file.txt " fi , , , : if test -f "file.txt" ; then cat "file.txt" else echo " file.txt " fi , , test, . : 25


if gcc -Wall -g myprog.c -o myprog; then echo " " else echo " " fi , Bourne Shell , . , 1 100: I=0 while [ $I -le 101 ]; do echo $I I=$(( $I + 1 )) done && ||, , , "" "". "" , "" ­ . $ cmd1 && cmd2 cmd1, ­ cmd2; . , $ cmd1 || cmd2 cmd2 cmd1.
­ ( "" , "". , "" - , ; , $ cmd1 && cmd2 | cmd3 cmd1 cmd2 | cmd3 . . , , , :

26


$ (cmd1 && cmd2) | cmd3 cmd1 cmd2 (, , ), cmd3.

Bourne Shell [1]. 2.9.2 ( script)

, .. , , , , . script. , script , . Ctrl-D (" "). : $ script my_protocol.txt Script started, file is my_protocol.txt $ ls a1.c Documents my_protocol.txt tmp $ echo "abc" abc $ [Ctrl-D] Script done, file is my_protocol.txt my_protocol.txt : Script $ ls a1.c $ echo abc $ Script 2.9.3 started on Wed Nov 17 16:31:54 2005 Documents "abc" my_protocol.txt tmp

done on Wed Nov 17 16:32:14 2005

head tail

Unix, , head tail. , ( 10 ). , 27


$ head prog.c 10 prog.c, , , , . head tail . , C , $ head *.c *.h (, ) 9 .c . , , . , $ head -25 prog.c $ tail -25 prog.c , , 25 25 prog.c. tail , (, ). , $ tail -f mylog.txt 10 mylog.txt, , . ­ Ctrl-C. ( ) , 10 . , $ gcc -c sh.c 2>&1 | head -20 20 gcc ( , , ). , (2) (1) 2>&1 (. § 2.5, . 5), .
, 10 , , , ; .
10 9

10 .h. -

28


2.9.4

cat

, , . , , : $ cat sh.c | less
, less .

cat . , $ cat -n sh.c sh.c, , . $ cat -v fl.txt fl.txt, (.. 0­31), LF ( ) TAB (), 127, . ^, 64 (0x40). , 0 ^@, 1 ­ ^A, 2 ­ ^B, 13 ­ ^M .. ( @ 64, A ­ 65 ..) 127 ( .. ) M-, 129 (0x80). , (, , ), ^, . , binary_file ( 16- ): 80 FF D0 0A $ cat -v binary_file 29


M-^@M-^?M-P @ ­ 0x40, ? ­ 0x3F, P ­ 0x50. , cat , .. . , ; . . cat ( ) ; , $ ./prog1 | (head -5 ; cat > /dev/null ) prog1, ( cat prog1 SIGPIPE head , , ). 2.9.5 wc yes

, , . wc , , : $ wc /etc/resolv.conf 8 15 131 /etc/resolv.conf , 131 . ( /etc/resolv.conf 8 , 15 , wc , ):

$ cat /etc/resolv.conf | wc 8 15 131 wc: · -c ­ · -m ­ (, , , UNICODE UTF-8) 30


· -w ­ · -l ­ · -L ­ , , (.. , , ..) yes, , : , , .. , ( kill, ­ Ctrl-C, ..). , $ yes Hello, world ( ) Hello, Hello, Hello, Hello, ... world! world! world! world!

yes , "yes" "no". 2.9.6 grep

grep , . , ( ) . , $ grep include *.c , include .c . , : hel.c:#include hel.c:#include kr.c:#include kr.c:#include "mod1.h" 31


, grep (.. ), , : $ cat *.c #include #include #include #include | grep include "mod1.h"

grep ( , , ) , . , . ; . ( ). , , : $ grep 'include <' *.c hel.c:#include hel.c:#include kr.c:#include , grep . : ^ , $ ­ . , $ grep ' $' *.c , (, ). grep , : -v , ; -r , . , 32


$ grep -v '^ ' myfile myfile , , ; $ grep -r '^void very_strange_function(' * , , void very_strange_function( ; , , , , very_strange_function, void. , grep , , , . grep , , find (. ), Bourne Shell (. § 2.9.1). 2.9.7 find

. grep, , find , , - Windows. ( , man info; . §2.8). $ find . . $ find . -print 33


$ find -print $ find /home/igor /home/igor . $ find . -name "*.c" .c , : ./hel.c ./kr.c ./SQLTest/sqlcl.c ./SQLTest/sqlsrv.c $ find ~ -name core core (, ~ ). $ find . -name "*.c" -exec grep include {} \; , include, .c, . . , find . -name "*.c" , , , .. .c. -exec include {} \; , grep include , .. {}. , -exec, " ;", , . 34


grep ( grep , .. ). , , : $ find . -name "*.c" -exec grep include {} #include #include ./hel.c #include "stdio.h" ./kr.c .. grep ( !) -print . , find : , . ­ ( ). , , , () . (.). : $ find /home/igor/*.h /usr/include/*.h /usr/local/include/*.h .h /home/igor, /usr/include /usr/local/include. , , h. , . find . , - ( grep ). -print, . ( ). ( ). : 35 \; -print


· -print ­ . . · -name NAME ­ , ( ) NAME. , -name core core; -name "*.c" .c. · -perm MODE ­ , MODE. , -perm 666 , . · -exec COMMAND ;. ­ COMMAND. {} ("") ("") COMMAND. ";", , ( \), . -exec . find, , , (, ..), , , , , ( , , , ) .. .. () . , , .. expr1 expr2 , expr2 , expr1 . $ find . -exec grep main {} \; -print -print () , grep ( ) main. , . , -print -exec, , , main. , , , , , -o. , $ find /usr/include \! -name "*.h" /usr/include, .h ( " \!"). 36


$ find . -name "*.cpp" -o -name "*.c" .c .cpp. -o, , -name ( ) . , ,
$ find . -name "*.cpp" -o -name "*.c" -exec grep main {} \; -print

, main, .c (.. ): int main() ./kr.c int main() ./hel.c grep , -o , , . , , ( ­ !):
$ find . \( -name "*.cpp" -o -name "*.c" \) -exec grep main {} \; -print int main() ./kr.c int main() ./hel.c int main() ./kr.cpp

, find, , , , Unix.

37


3
3.1

X Window
X Window

Unix : , . ­ . () ­ . ( , , , ..), ( , ) . Unix , . , (, ) Unix . , . () ­ - . , , ( , , ­ .. ), , , , , (, , .), ( , / ) . , ()11 . Unix (, - , curses12 ), ( ­ Graphical user interface, GUI curses ( ncurses) - , ; curses escape, , 12 11

38


, ). , , . , Unix. Unix X Window System ( ­ X Window). X Window X-, X- X-. X- ­ , . X- , (, , , , ..), () .. X- , . X- ( , X- ). X- ­ . , X- ; X-, . "" X Window ( 80- ) , X- X- : , TCP/IP, ­ X-, (X-) X-. , X-, X- , ( X Window System). ­ X Unix, MS Windows, Mac OS, VMS ( X- ) (X-), (, Unix). , X- , ,


39


, X- . X- Unix ­ , , , (, ). X Window Unix. XFree86 X.org. X Window (). , , , , ( ), .. . , ­ (X-); , X- ; , ­ . Unix ; . , , . . X X- , , Xlib, X- . Xlib ­ , X Window, , . . , Xlib . , C C++, GTK+ ( GNOME) Qt ( GNOME). X Window , /C++, , Lisp, Ada, Tcl/Tk, Python . X- xterm ­ - X Window. xterm, , 40


. vim, ­ , ­ .. , Unix ( ) ; X Window xterm . , Unix , ( , , ..), Windows MacOS. , , , , Unix, ( ) , . , Unix, , , .. ( ) . , (- ) Unix; . . X Window - , xterm' . , ; , , , , , ..

3.2

X Window
, X xinit.

Window , . startx, , , 41


, , xdm; X Window , () , , .. X-. , xdm-, $ X -broadcast xdm- , . xdm- , , . 15­20 ­ , xdm- .

startx X- . , X Window, . , .xinitrc ( , ). , . .xinitrc , , . xinit X-, , , .xinitrc. xinitrc X Window, X- . .xinitrc : xterm & twm xterm ( , , ), ­ twm. , xterm 42


( &). , twm. twm . Unix 13 , , , . , twm, , fvwm, icewm, wmaker ; , , KDE GNOME14 . icewm, .xinitrc: xterm & icewm KDE, : xterm & startkde . , twm , KDE , , Windows. KDE , twm, fvwm icewm Pentium-1 (KDE ). , KDE , . .

3.3



twm, fvwm .
13 , twm , 14 ,

43


, , , - - . , , . ; . , , ­ , . , ( , ). , , , , , xterm . xterm - , , terminals , shells .. , xterm, $ xterm & &. xterm , xterm ( ) : xterm , . xterm . , $ xterm -bg black -fg gray & ( ). X Window , , 15 . , 15 Windows, , ,

44


, , , . ( FocusFollowsMouse), , ; , ClickToFocus, . , . ( ) , , , ( ). ( , , ) ­ . : , ( ) , . (, ), , ; , , , . , , . , . (virtual desktop), , . , . , , ; , . , , . ; , X Window, copy : , . () . , 45


. , , , ; () , , , .

3.4

KDE

, KDE (K Desktop Environment), , MS Windows, Mac OS ..; KDE , , .. KDE . , Windows. . , Konsole , . Unix. (desktop panel), , KDE, . , , . KDE , KDE ( Configure Desktop... ). , - , ( Apply ). ­ , . . , . ( Start ) Windows. 46


. KDE , , . , . KDE , ( 4). , . , () . KDE . . . KDE Konqueror, Windows. : , - . ( ) . , , , , , , , , . , , . . , Unix.

47


4
4.1


gcc/g++

GCC (Gnu Compiler Collection) , .. . , , (). gcc C, g++ ­ C++16 . , , . , . : · -o , ( , a.out.). · -Wall (warnings). , . · -ggdb -g (, , , ..). -ggdb , gdb. , - , -g. · -c , , . , .o.
16 , ; . , ; , , .

48


· -On . n=0 ( ). -O2. , . · -ansi ANSI C. · -pedantic . · -E . . , , , , . · -D (.. ) . , , , . , -DDEBUG=2 , #define DEBUG 2 . · -l . , (sin, exp ), -lmath; Unix (, SunOS/Solaris) -lnsl. · -MM . , , §4.3. , , C prog.c, gcc -g -Wall prog.c -o prog prog . 49


, mod1.c, mod2.c, mod3.c prog.c, : $ gcc -g -Wall -c mod1.c $ gcc -g -Wall -c mod2.c $ gcc -g -Wall -c mod3.c mod1.o, mod2.o, mod3.o. $ gcc -g -Wall mod1.o mod2.o mod3.o prog.c -o prog

4.2

gdb

gdb (Gnu DeBugger) , , "" core-. , , -ggdb -g (. §4.1). , . 4.2.1

, prog, $ gdb prog , , : (gdb). : · run . (. ). , , main(). 50


· list , . · break (breakpoint). , , <>:<->, file1.c:73. · inspect ( *(a[i+1].p)). · backtrace bt , , . · frame , backtrace, .. · step . , (.. ). · next step, , . · until <-> , . · call . · cont . · help . · quit ( Ctrl-D). 51


4.2.2

core-

, core-. Segmentation fault (core dumped) , core ( prog.core, prog ­ ), . gdb , , , , , , .. core-, : gdb prog prog.core prog ­ , prog.core ­ core-17 . , , core-. , core- , core-, , . core- backtrace ( bt). 4.2.3

, . , , . . ps. , ­ prog, 12345. :
17 core- FreeBSD. Linux , , core.

52


gdb prog 12345 , cont. Ctrl-C.

4.3

make

, make. , (, ) . make , . make. Gnu Make; Linux. FreeBSD Gnu Make gmake make. , , . make Makefile, . 4.3.1 Makefile

, main.c, main(), mod1.c mod2.c, mod1.h mod2.h. , ( prog) : $ gcc -g -Wall -c mod1.c -o mod1.o $ gcc -g -Wall -c mod2.c -o mod2.o $ gcc -g -Wall main.c mod1.o mod2.o -o prog . mod1.o mod2.o . 53


, , mod1.c . ( ), mod2 . , make. Makefile: mod1.o: mod1.c mod1.h gcc -g -Wall -c mod1.c -o mod1.o mod2.o: mod2.c mod2.h gcc -g -Wall -c mod2.c -o mod2.o prog: main.c mod1.o mod2.o gcc -g -Wall main.c mod1.o mod2.o -o prog , ( - mod1.o, mod2.o prog). . ­ , (.. ..). ( , ). . , (, , ) . , , ­ . ( ). , . make , , . Makefile, make prog. 4.3.2

Makefile, . , 54


" -g -Wall" . , . , ( -O2). . . , , . make-. C CC, ­ CFLAGS18 . Makefile : CC = gcc CFLAGS = -g -Wall -ansi -pedantic mod1.o: mod1.c mod1.h $(CC) $(CFLAGS) -c mod1.c -o mod1.o mod2.o: mod2.c mod2.h $(CC) $(CFLAGS) -c mod2.c -o mod2.o prog: main.c mod1.o mod2.o $(CC) $(CFLAGS) main.c mod1.o mod2.o -o prog 4.3.3

, make , . : · CC ­ C; · CFLAGS ­ C; · CXX ­ C++; · CXXFLAGS ­ C++;
18 .

55


· CPPFLAGS ­ ( ); · LD ­ ( ); · MAKE ­ make . CC, CXX, LD MAKE , . . , Makefile , CC, , . , . : · $@ ­ ; · $< ­ ; · $^ ­ . Makefile : CFLAGS = -g -Wall mod1.o: mod1.c mod1.h $(CC) $(CFLAGS) -c $< -o $@ mod2.o: mod2.c mod2.h $(CC) $(CFLAGS) -c $< -o $@ prog: main.c mod1.o mod2.o $(CC) $(CFLAGS) $^ -o $@ 4.3.4

, Makefile, , . 56


, C, .c, ­ .h: %.o: %.c %.h $(CC) $(CFLAGS) -c $< -o $@ , Makefile: OBJMODULES = mod1.o mod2.o CFLAGS = -g -Wall -ansi -pedantic %.o: %.c %.h $(CC) $(CFLAGS) -c $< -o $@ prog: main.c $(OBJMODULES) $(CC) $(CFLAGS) $^ -o $@ OBJMODULES. , Makefile : SRCMODULES = mod1.c mod2.c OBJMODULES = $(SRCMODULES:.c=.o) $(SRCMODULES:.c=.o) , SRCMODULES .c .o. 4.3.5

make , , , . : run: prog ./prog clean: rm -f *.o prog 57


make run make , , . make clean (, ). , . 4.3.6

, , . , , , , Makefile. . make . : %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ mod1.o: mod1.c mod1.h mod2.h mod3.h mod1.o ( mod1.o ), mod1.o. . , , gcc -MM mod1.c , Makefile include. -, make , . deps.mk, : 58


-include deps.mk , , , : deps.mk: $(SRCMODULES) $(CC) -MM $^ > $@ make, , . , clean, . , -include , , , , clean. ifneq MAKECMDGOALS: ifneq (clean, $(MAKECMDGOALS)) -include deps.mk endif Makefile : SRCMODULES = mod1.c mod2.c OBJMODULES = $(SRCMODULES:.c=.o) CFLAGS = -g -Wall -ansi -pedantic %.o: %.c %.h $(CC) $(CFLAGS) -c $< -o $@ prog: main.c $(OBJMODULES) $(CC) $(CFLAGS) $^ -o $@ ifneq (clean, $(MAKECMDGOALS)) -include deps.mk endif deps.mk: $(SRCMODULES) $(CC) -MM $^ > $@ clean: rm -f *.o prog 59



[1] . . UNIX. .:, 1986. [2] . . . UNIX. - BHV­ - , -, 1997.

60



. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 Unix 2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 . . . . . . . . . . . . . . 2.3 . . . . . . . . . . . . . . . . . . . . . . . 2.3.1 vim . . . . . . . . . . . . . . . . . . . . . . 2.3.2 joe . . . . . . . . . . . . . . . . . . . . . . . 2.3.3 Midnight Commander 2.4 . . . . . . . . . . . . . . . . . . . . 2.5 - Bourne Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.7 . . . . . . . . . . . . . . . . 2.8 . . . . . . . . . . . . . . . . . . 2.8.1 man . . . . . . . . . . . . . . . . . . . . . . . 2.8.2 info . . . . . . . . . . . . . . . . . . . . . . 2.9 . . . . . . . . . . . . . . . . . 2.9.1 Bourne Shell . . . . . . . . . . . 2.9.2 ( script) . 2.9.3 head tail . . . . . . . . . . . . . . . . . . . 2.9.4 cat . . . . . . . . . . . . . . . . . . . . . . . 2.9.5 wc yes . . . . . . . . . . . . . . . . . . . . 2.9.6 grep . . . . . . . . . . . . . . . . . . . . . . 2.9.7 find . . . . . . . . . . . . . . . . . . . . . . . 3 X Window 3.1 X Window . . . . . . . . . . 3.2 X Window 3.3 3.4 KDE . . . . . . . . . . . . . . . . 3 4 6 6 7 9 10 13 14 15 17 19 20 21 22 23 24 24 27 27 29 30 31 33 38 38 41 43 46 48 48 50 50

.. . . ..

. . . .

. . . .

. . . .

. . . .

. . . .

4 4.1 gcc/g++ . . . . . . . . . . . . . . . . . . . . . . 4.2 gdb . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2.1 . . . . . . . . . . 61


4.2.2 4.2.3 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6

4.3

core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . make . . . . . . . . . . . . . . . . . . . . . . . . . . Makefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

52 52 53 53 54 55 56 57 58 59