Вы находитесь на странице: 1из 526

%

www.books-shop.com


!
, , !
.
: UNIX ( /,
, ), UNIX
( ),
(!

) U N I X (!
TCP/IP, ,
TLI).

%
.
:
.
" !

. .
.
" " !

. .

. .
UNIX. % .:

2002. % 528

ISBN 5!8206!0030!4

UNIX
The Open Group
. , 1997
. , 1997
, "%",
02429 24.07.00.

. . . . 42,8.
. 5000 . 1383
"%", 198005, %, ., 29.
, ,

. .

"" .
199034, %, 9 , 12.

www.books-shop.com

" UNIX"

?


UNIX
UNIX
System UNIX
System V Release 4 (SVR4)
UNIX Berkeley Software Distribution
UNIX,
UNIX

/
SVID
ANSI
UNIX
AIX
HP%UX
IRIX
Digital UNIX
UNIX
Solaris
UNIX
UNIX


1. UNIX


UNIX

1
1
2
2

3
.....3
4
6
6
7
7
8
8
9
9
10
10
11
11

13
13
13
13
13
14
15
17

19
20
21
25
26
26

www.books-shop.com

/bin

27
27
/etc
27
/lib
27
27
28
/home
28
28
/var
28
28

28

30

35

38

38

39

39

40

40

41
Process ID
41
Parent Process ID
41
(Nice Number)
41
(TTY)
41
(RID) (EUID) .41
(RGID)

42

42

44

47

47

47


UNIX
49

50

51

54

55
UNIX
56
shell
56
Bourne shell
59

59

60

64

66
,
68
,
71

www.books-shop.com




test


UNIX


UNIX
1.
2.
3.
4.
5.
6. ""
7.
8.

2. UNIX
UNIX




ELF
COFF
UNIX

%


(2)
creat(2)
close(2)

dup2(2)
lseek(2)
read(2) readv(2)
write(2) writev(2)

73
74
75
77
78
79
80
82
82
86
88
89
89
90
90
91
91
91
92
92
93
93
93
95

105

122

www.books-shop.com

pipe(2)
fcntl(2)

3.




129
130
133
137
140
142
146
150
154

173

184
186
187

191
195
197
199
202
204
207
210
216
219
221
222
226
230
233
234

www.books-shop.com

FIFO
IPC


BSD


4.
SYSTEM V




BSD UNIX

SVR4

5.

235
236
236
237
237
238
240
242
243
245
248
253
258
264
265
274
277
278
279
280
281
282
285
287
288
291
292
293
296
303
304
306
307
309
313
314
317
317
321
322
323

www.books-shop.com

STREAMS
STREAMS

323
325
333
335
338
340
342
343
344
346
348
350
352
356
357
361
362
364
368
369
371
372
375
377
380

6. UNIX
TCP/IP
TCP/IP
TCP/IP
OSI
IP


User Datagram Protocol (UDP)
Transmisson Control Protocol (TCP)
TCP%

TCP
" "




382
383
384
386
391
393
398
400
402
404
406
413
414
416
417
419
420
420

www.books-shop.com

TLI
.


(binding)
(exception)

426


DLPI

LLC
IP

DLPI

440
442
443
444
444
445
445
446
447
448
448
449
452
453
458
464
466
468
469
470
472
481
487
490
492
493
493
497
501

503

.
UNIX

504

client.c
BSD UNIX

TCP/IP
IP
UDP
TCP

UNIX SYSTEM V

INTERNET

%RRNVVKRS

piracy@books-shop.com

504
505
509



!
, ,
.

, !
" Internet. "
, !
.
!
.

.
!
, . !
,
.
UNIX
.
.
OLLY,
,
.

!
. " " ! !
. . . . . !
. " " !
. . . !
. . .
.
" , !
,
. !
. , !
,
, , , .

, , ,
!
.
, ,
.
, , !
.

www.books-shop.com


"

!
UNIX. , , , !
, . !
,
, . . !
, ,
. "" !
,
. ,
UNIX, !
. !
UNIX.
, UNIX !
, .
, "" UNIX, a
: , !
, ,
. , ,
UNIX.
: Solaris 2.5 Sun Microsystems, SCO ODT
5.0 Santa Cruz Operation, BSDi/386 Berkeley Software Design.

UNIX !
( ), !
UNIX . !
.
!
UNIX .
1 UNIX.
.

shell.
2 . !
!
!
.
.

UNIX:
, ,
/. UNIX,
. 6
.

" ", "

www.books-shop.com

"
" ( )
" , " ( )
, !
, .
!
UNIX. ,
!
.
, , !
.
?
, . ,
, !
, .. , . !
, !
.
!
, .
.
, ,
. ,
.
, , !
.
, , !
, .
, , ,
. ?

, , shell !
, open(2), cat(l)

( ).
, ,
!
. , d_open
sleep :
int
{

exit ()


, :
$
Enter old password:

, /etc/passwd
<sys/user.h>.
,
<Ctrl>+<C> ( ).

www.books-shop.com

30
UNIX. PDP!7 4
, UNIX

, PC !
.
UNIX ,
, !
,
.
UNIX
, , . !
, . !
"" , !
UNIX. !
UNIX,
.


1965 Bell Telephone Laboratories ( AT&T)
General Electric Company
(MIT)
, MULTICS
(MULTiplexed Information and Computing Service). !
!
,
. Bell Labs !
(Ken Tompson) (Dennis Ritchie). !
MULTICS ( 1969 Bell Labs !
), , !
UNIX.
,
. !

www.books-shop.com

, MULTICS, 1969
, ,
.
PDP!7.
UNIX, MULTICS
, !
(Brian Kernighan).
UNIX ,
! .
. 1971 Bell Labs
,
UNIX. UNIX
PDP!11, : 16 !
, 8 ,
64
!
.
!
FORTRAN,
.
, , , !
. 1973
,
, UNIX.
, UNIX !
, , !
!
. Bell Labs 25, !
UNIX UNIX System Group (USG).
UNIX
AT&T
UNIX
, 1974
.
, !
, !
(Edition). !
10 !, 1971, !
1989 . Bell Labs

UNIX 1 1970 .
UNIX .

www.books-shop.com

(Computer Research Group, CRG)


PDP!11, VAX.
, UNIX System Group, .
(Programmer's
PWB)
, SCCS, !
. !
USG.
:

1971

UNIX,
PDP%11.
, cat(1),
mail(1),
mount(1M),
rmdir(1), wc(1),
%

.

1973

(1), %
.

1973

,
.

1975

, %
Bell Labs.
.
, Bell
Labs, UNIX. ,
%
,

BSD (Berkeley Software Distribution) UNIX.

1979


Bourne Shell
.
.

Microsoft, %
XENIX.

UNIX , 1977
500. 1977 Interactive Systems Corporation
VAR (Value Added Reseller) UNIX, !
.
UNIX , !
PDP.

www.books-shop.com

UNIX
UNIX, !
, .
"" UNIX,
,
.
, !
UNIX. !
.
UNIX.
System V UNIX
1975 AT&T !
! !
, .
, , !
, !
UNIX.
UNIX ,

,
.
, AT&T 1982 !
UNIX System III. !
, , ,
, System III
Bell Labs AT&T
UNIX, .
1983 Bell Labs System V. 1984
USG (UNIX System
Development Laboratory,
!
System V Release 2 (SVR2). !
,
(copy on write), !
(InterProcess Communication, IPC)
, .
1987 System V Release 3 (SVR3).
AT&T
AT&T (AT&T Information Systems,

, :
/, STREAMS.
(File System Switch), !
.

www.books-shop.com

UNIX

.

Interface ().

Transport

Layer

System V Release 4 (SVR4)


1989 System V Release 4.

UNIX: SunOS Sun Microsystems, BSD UNIX Berkeley
Software Distribution System V.
:

(BSD)

/, STREAMS
(System V)
(SunOS)
NFS !

(SunOS)
FFS (BSD)
(BSD)


POSIX,
SVID.

ANSI,

UNIX Berkeley Software Distribution


UNIX !
1974 .

UNIX, BSD UNIX.


1978 . 1979
UNIX
3BSD. BSD, VAX.
, , (virtual
memory) (demand paging).
1980 , Bolt, Beranek
and Newman (BBN) !
(DARPA) !
TCP/IP BSD UNIX.
1981 ,
4.2BSD UNIX.

www.books-shop.com

4.2BSD 1983 !
, , Ethernet. !
, !
.
ARPANET,
80!. , !
.
, AT&T,
, ,
, .
!
.
,
, !
. 1986
4.3BSD, . 1986
1990 ,
NFS, VFS,
.
, , 4.4BSD
BSD Lite, 1993 .
OSF/1

1988 AT&T Sun Microsystems !


System V.
, !
, IBM, DEC, Hewlett!Packard, !
Open Software Foundation (OSF), !
AT&T .

OSF/1.
, , OSF/1
UNIX. , , !
, UNIX System V.

UNIX,
, !
, , , !
. !
, . !
, , !
, ,
.

www.books-shop.com

:
Mach, !.
Mach
DEC !
Alpha,
Workplace IBM.
Chorus.
Chorus/MiX V.3 Chorus/MiX V.4,
SVR3 SVR4. UNIX !
, , !
, !
.
UNIX
PC UNIX !
.
UNIX PC,
!
(Andy Tanenbaum)
UNIX. !
.
Minix PC 8086 ( ).
!
UNIX Linux, !

(Linus
" " Intel i386,
, Alpha DEC.


UNIX , !
.
, , ,

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

%RRNVVKRS

piracy@books-shop.com

, , ,
UNIX.
IEEE POSIX
1980

UNIX, . .
, !
.
UNIX. 1984 !
ANSI, ,
.
, , 1985 ,
Portable Operating System Interface for Computing Environment,
POSIX (
).
1988 POSIX 1003.1!1988,
(Application Programming
Interface, API). !
,
UNIX.
1003.1!1990. !
, ,
, !
,
.
POSIX,
UNIX, :
POSIX 1003.2%1992
POSIX
POSIX

UNIX

, %

"" (threads) POSIX,
pthreads

1984 !
,


,
, , !
!

www.books-shop.com

77

,
.
/Open !

. 1992 , !

Portability Guide 3
!
POSIX 1003.1!1988 X
Window System,
.
XPG3 , API
BSD System V (SVID), STREAMS.
, Spec
1994 XPG4.2.
1996 /Open OSF !
The Open Group,
. , !
, Common Desktop
Environment (CDE),
Motif. !
Distributed
Computing Environment (DCE), OSF.
SVID
1984
USG !
System V Interface Definition, SVID, !
UNIX System V. !
, ( ) !
System V.
SVID . . System V Verification Suite,

, ,
System V.
SVR4 SVID (
) , , SWS.
ANSI
1989
(American National Standards Institute, ANSI)
.

, ,
( UNIX).
,
.

www.books-shop.com

12

UNIX
,
UNIX. , ,

. , !
, !
.
SunOS Solaris Sun Microsystems, HP!UX
Hewlett!Packard, AIX IBM, IRIX Silicon Graphics.
, !
, ,
, !
, . , ,
:
. ,
!
, " UNIX".
. !
" UNIX" ,

System V, BSD OSF/1. , , ,
Digital UNIX !
System V BSD UNIX, !
BSD.

.
. 1 ( !
) UNIX
.

%

%

SVRx

xBSD
/vmunix

/etc/rc*.d

sh(1),

csh(1)

www.books-shop.com

13

UNIX

1 ()

SVRx

"" S5 ( :
), UFS ( :

< 255


lp(1),
lpq(1),
daemon)
%

%
ps !aux


UNIX.
AIX

UNIX IBM SVR2


OSF/1. (SMIT).

BSD

HPUX

UNIX Hewlett!Packard. 1996 !


HP!UX 10.10 HP!UX 10.20, !


( 128 )
3,75 . 1997 !
64! .
IRIX

UNIX Silicon Graphics,


(MIPS). !
BSD UNIX, IRIX (6.x)
System V Release 4. 64! !
.
Digital UNIX

OSF/1 Digital Equipment Corporation (DEC).


DEC OSF/1 BSD UNIX.
System V. 64!!
, !
Alpha, , !
UNIX, DCE, CDE, .
, Fast Ethernet ATM.
SCO UNIX

1988 Santa Cruz Operation (SCO), Microsoft Interactive


Systems System V Release 3.2

www.books-shop.com

14

Intel 386. SCO AT&T


SCO UNIX
System V/386. 1995 SCO
SCO
Release 5 ( Everest) UNIX

SVR4. !
900 , !
, 2000 .
Solaris
UNIX SVR4 Sun Microsystems. 2.5.1 !
, 64! . !
,
UltraSPARC, Intel 486, Pentium, Pentium Pro PowerPC. 1998 !
64! !
.

UNIX
UNIX
. , !
.
UNIX , , !
, , !
, UNIX . ,
, !
Solaris SCO, UNIX .
UNIX, !
:
1. ,
, .
UNIX, ,

,
20% , .
, !
. !
, UNIX . !
, UNIX
, , !
.
2. UNIX
.
. !
. !

www.books-shop.com

3.

4.

5.

6.

UNIX

, !
, ,
, (telnet, ftp, !
, DNS . .), !
.
. UNIX, !

. !
, !
.
, .
,
, !
.
,
. , !
. !
, , !
, .
, !
, !

.

UNIX

, . 1.

. 1.
UNIX

www.books-shop.com

16
(kernel). !
, !
. , !
.
/ (, , ),
, !
. !
.
, , !
, , !
UNIX.
, .
.

:
,
.
!
.
!
. !
, !
.
.
,
. (open), !
(read) (close) ,

read(2) close(2) .
main
{

int fd;
char
/* ( )
fd =
0_RDONLY)
buf 80
read(fd, buf,

www.books-shop.com

UNIX

17

2.

. 2. %
UNIX

:
1.
2.
/


, ,
. (2), read(2),
!
,
.
,
, /
.
( !
), !
.
, !
,
/.

www.books-shop.com

18


( ). :

(, !
)


, !
,
. !
,
.
,
(scheduler), !
(, , !
/). , ,
.
, !
/, . !

.

. !
, , , " ". ,
,
( , !
),
. !
:
, !
.
.


.
/
/
!
(, , . .).
!
, !
.

www.books-shop.com


UNIX

UNIX !

. , UNIX
, .
UNIX
: . ,
/
. , !
,
. ,
. , !
.
,


UNIX; UNIX !
; !
, , , !
; UNIX,
, .
, !
UNIX , !
;
shell
; ,
UNIX. !
.

, Internet

,
,
. .

%RRNVVKRS

piracy@books-shop.com

20

1. UNIX


UNIX ,
. !
, . !
, UNIX , !
!
. !
, ,
, CD!ROM, , , .
UNIX "" ,
, . , ,
, ,
UNIX, .
, UNIX
(), !

system). ,
.
(root directory),

(),
, . UNIX !
, !

, !

( !
, CD!ROM ), !
.
,
. ,
, !
, , ,
,
. ,
,
UNIX 4.
, , !
, .
(
inode), !
, !
: , ,
. , !
. !
, !
.

www.books-shop.com

21

UNIX 6 ,

:

(regular file)
(directory)
(special device file)
FIFO (named pipe)

(link)

, !
. !
. !
, !
. ,
, . .
.
. ,
, !
, !
.
, !
. , , !
, .
. 1.1 .
,
. !
( mode), .

. 1.1.

www.books-shop.com

22

1. UNIX

!
. UNIX (character) (block)
. ,
.
!
,

.
, .
, 5.
FIFO ,
. FIFO System V UNIX,
.

3.
. ,
.
, . !
.
, , ,
, !

(hard link). ,

(second) , first (. 1.2).
$ pwd
$

first

. , !
ls(l), first second !
. !
. !
. , , , !
. !

. ,
(first second) ,
. . ( ).

. , "",
, "" .
(. . !
).

www.books-shop.com

. 1.2.

23

,
, , ls(l)

www.books-shop.com

24

J. UNIX
$
i
12567
12567

first
second

, !
, ,
! /:
$

1
2

andrei

staff

7245 Jan 17 8:05

second

.
,
.

,
. , !
, , , . ,
(. 1.3).
, ,
.
.
:

!s

$ pwd
$
 first
$ cd /home/sergey
$
1
1 andrei

staff

15 Jan 17 8:05


symfirst ( )
second ( ). !, !
symfirst , first
second, 15 .
, !

15 . !,
symfirst
!
).
( !


!
, . , !
symfirst

www.books-shop.com

25

. 1.3.

.
TCP/IP. ,

www.books-shop.com

26

1.

UNIX

BSD UNIX
!
, , !
, . !
" BSD UNIX" 3.
UNIX
!
, !
. !
, ,
.
.

. 1.4. UNIX
.


UNIX.
, !

www.books-shop.com

27

, !
.


!
, , .

/dev , !
.
/dev ,
. , /dev/dsk

.
/etc


.
.
/etc/rc2.d . ,
(run level),
/etc/rc2 . .
BSD UNIX , !

/etc/re
UNIX
System V default,
(,
!

UNIX System V !

/lib



.
libx.a ( libx.so), , !
. , !

X Window System libXll.a.


"" . ,
UNIX ,
. . "" !
,
! . !

!

www.books-shop.com

28

1. UNIX

.
, , 4.
/mnt

() !
!
. /mnt , !
!
. !
4.
/ /home
!
. , andrei , !
,
/u/andrei.
UNIX /usr.


, . .
!
UNIX
,


!

. .
/var

UNIX System V /usr/spool,


!
, . .
/tmp

,
UNIX. !
.


UNIX : (user owner) !
(group owner). , !
, .

.

(primary), !
(supplementary).

www.books-shop.com

.
!
,
.
, !
,
.


!
! !, :
1

2
1
1

3
andy

4
group
student

235520
3450

Dec 22
Nov 12

quest

! ,
. !
UNIX. , SCO UNIX !
, , Digital
UNIX ! , !



! !
, . ,
sergey

sergey

!

!
, . !
, staff !
, :
$

staff *

, , . !
, ,
. "" :
1. !

, (. .
1. ! (group ID)
EGID ( System V);
) GID , ( BSD).
, System V, !
BSD.
SGID . . " "
.

%RRNVVKRS

piracy@books-shop.com

1.

30

UNIX

,
. , !
(. 1.1),
( ), , , !
( ) !
.
1.1.

%
%
%
%

chgrp(1)

SVR4

BSD 4.x


,
( %
POSIX)

UNIX
, :
User access (u)

Group access (g)

Other access ()

( )

UNIX :
(read,
(write, w)
(execute, ).

1
rwxrxr

2
1
1

andy
andy
andy
andy

:
group
group
group
group

36482

Dec 22

64

Aug 15

4889
7622

Dec 22
11

19:13
11:03
15: 13
09: 13

temp
a . out

(
, ). !
, '!'. !
, ,

www.books-shop.com

31

[ [

, ,

[
[

!
(superuser) . !

.

!, 'g' !,
!
,
),
, V !
Y ) ,
('+' , '!' '=' )
. . ,
$ chmod
! ownfile !
.

, .
:
$ chmod a+w text

$ chmod go=r text

%
,

$ chmod


runme

$ chmod

text2

,
%
,
,

www.books-shop.com

32

1.

UNIX


. ,

$

754 *

:
(0 , 1 !
) , ,
.

, !

$ chmod

o=r *

. !
, , !
. , cat(l), !

, . .
, (w). ,
,
(). !
, shell.
,

. , , ,
, !
, : !
, , . , !
, !
,

, !
, .
.
, !
.
,
!
. ,
.

www.books-shop.com


( ) , .

(,
"!
" , !
. ,
(. . ) cd (]).
!
. ,
, !
, .
, !
. !
, , "" , !
, ,
.
, ,

"",
. "" .
$
?
$

darkroom

! 1

$
$

group

a!r+x darkroom
1
2

denied

$ cat
ok

Dec 22

19:13

darkroom

""

andy

$ cp f
darkroom
$ cd darkroom
$
darkroom

65

group

65

Dec 22

19:13

darkroom

darkroom


...

(, , %
)

. !
, , !
, . , !
. , !
, !
, ,
. ,

www.books-shop.com

34

UNIX

, . ,
,
,
Sticky bit . .
. 1.2 !
, .

cd

%s

cat
cat

runme
,
,


/u/andrei

%

%
%

()


report.txt

report.txt

%
runme

runme

X
W

X
X

XW

!
, ,
.
, 9 , 3 .

,
( ),
. :
1. , !
. . !

www.books-shop.com



.
2. , :
) (, !
!
), ,
) .
,
, , :
) , ,
) .
4. (other) !
, , .
. ,
, !
!, !
, !.
, :
2

group

65

Dec 22

19:13

andy group,
, filel. !
. ,
. !
, ,
andy !
(), ,
.

, .
,
!
. , !
.
chmod(l),

Y . 1.3. ,
SGID filel
$ chmod g+s f i l e l .

. 1.3 , ,
.

www.books-shop.com

36

UNIX

1.3.

Sticky bit

S
S

Set



UID

Sticky bit
save text mode)
UNIX .
!
(,
(. .
) , !
.
( ) SUID SGID !
, .
( ) !

!
, . !
SUID SGID , !
. ,
, , !
, ,
. SUID
, SGID !.

. ,
!
( /etc/passwd /etc/shadow,
, !
). ,
. !
SUID
(,



.
!

, ,
. SUID SGID
, !
.

www.books-shop.com


( root),
,
, . . !
, .
$
!r!sr!sr!x

3 root

sys

15688 Oct 25 1995 / u s r / b i n / p a s s w d *

,
.

, , !
(, ).
,
.
4.

(.
1.4.

Sticky bit

Set

SGID

, %

%
, %
BSD UNIX

,
. ,
, ,
.
Sticky bit !
, . !
, , !
,
. /tmp, !
, !
!
.
SGID .

!
. !
UNIX System V
BSD, !
.

www.books-shop.com

1. UNIX

38

!
:
$

!1

!r!sr!sr!x

5 sys

sys

367

Dec 19

sys

15688

Oct 25

root

20:29
1995

chmod(1)
% chmod(1)
Sticky bit
%


,
%
%

UNIX . !
!
!
, !
.
, !
. , !
, .
, . . , !
, !
. , , ,
,
. !
(run levels),
, !
, , .

, !
, .
,

www.books-shop.com

,
, !
/ , .
( ) .
,

. !
, !
UNIX . , !
, ,
, .

, . !
, ,
cat(l),
. , !
(, FTP, Telnet),
.
UNIX . ,
,
.
!
,
.
, .

UNIX
. UNIX
, (signals), (pipes), !
(shared memory), (semaphores), (messages)
, .


!
.

.
,
, .
: shed ( ), vhand (!
),
( )

%RRNVVKRS

piracy@books-shop.com

40

1.

UNIX

kmadaemon ( ). !
ink, UNIX.
init , !
(/etc/init),
.

,

( ), . !
(
, . 3)
UNIX: , ,
. . !
!
.
, ,
.

, !
. , , !
.
. , ls(l) !
. !
(login shell), !
UNIX. ,
login shell .
,
, ( )
.
.
,
,

,
. !
shell, !
. , !

ps(l) , shell.

www.books-shop.com


UNIX ,
, !
.
Process ID
PID,
. ,
(. .
) . !
, . . ,
, . !
,
PID . ,
.
Parent Process ID
, .
(Nice Number)
,
. !
, !
, .

( !
) , !
.
(TTY)
, ,
. ! .
(RID) (EUID)

, . !

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

www.books-shop.com

1.

42

UNIX

SUID, !
!
(, ).
(RGID) (EGID)

, . !

.
,
( SGID).
ps(l) (process status) , !
, :
$ PS

root
root
root
root
root
fed
fed
fed

ef |
head 20

0
0
0
1
0
0
2
0
0
3
0
0
1
0
627
311
0
314
304
0
3521
0
512

TTY
Dec
Dec
Dec
Dec
Dec
Dec
Dec

17
17
17
17
17
17
17

TIME
:00
0::01
0:

7;

:01
0::27
0:
0::01

9
9

pts/3
pts/4


pageout
bd
emiclock


" UNIX".


UNIX
, !
fork(2) ,
. !
. ,
, . ,
,
fork(2). , !
PID. ,
.
, . . ,
(2). !
, !
.
, ,
/,
, .

www.books-shop.com

43

UNIX !
,
fork(2), ,
.
.
, , ( !
shell)
(shell)
fork(2), shell. ,
shell (2),
, shell.
ls(l) shell, ls(l) !
. ls(l) "".
. !
. 1.5. !
, 2.

. 1.5.

"" ,
ps(l), , :
:
UID

PID
745

PPID
1

10

STIME
10:11:34

TTY

TIME
0:01

CMD

www.books-shop.com

44

1. UNIX

ls(l), shell
UID

PID
745
802

PPID
1
745

10
14

TTY
10:11:34
11:00:00

TIME
0:01
0:00

sh
sh

shell
UID
userl
userl

PID
745
802

PPID
1
745

10
12

STIME
10:11:34
11:00:00

TTY

TIME
0:01
0:00

CMD
sh

STIME
10:11:34

TTY

TIME
0:01

CMD
sh

ls(l) :
UID
userl

PID
745

PPID
1

10

fork!and!exec.
, fork(2) !
(2). !
!

UNIX fork(2).
fork!and!exec,
(2). ""
.
" " , ,

. 1.6 sched

(
).


! !
. !
.
, ,
. !
, 0,
SIGFPE, , <Del>
<Ctrl>+<C>, S I G I N T .

,
fork
, , 0. !
2.

www.books-shop.com

45

. 1.6. "" UNIX



kill

, a pid !
, . !
,
, !
( !

, !
, , !

:
$
$ kill $!

&


kill(1) SIGTERM;
$! PID , %

:
1. . , !
, , 0
,
.

, ,
kill(l), shell, !
.

www.books-shop.com

46

I. UNIX

2. . ,
.
3. , !
. , SIGINT !
, ,
"". , S I G K I L L SIGSTOP
, .

15
,
.

SIGTERM. !
S I G K I L L (9),
, :
$ k i l l 9 pid

, .
:
!. ,
, !
.
,
, .
, NFS (Network File
System), ,
, .
, SIGINT
, , !
, .

( !
) (,
SIGKILL SIGSTOP). , SIGHUP
DNS
.
!
.
2 3.


UNIX. kill !I .

www.books-shop.com


, UNIX "" ( !
) . ,
, ,
!
.
UNIX
. !
. !
! (!
, , , )
. . (, , !
, ). !
, !
/
.
:


, !
, !
.
. ,
, .
/dev Digital UNIX,
SCSI:
1
1

root
root

system
system

8, 1
8, 1

Apr 18
Apr 18

11:03
13:15


,

. !
,
. ,
, .
(raw

www.books-shop.com

1. UNIX

48

interface). , ,
, :
crw
crwr
crwrwrw
crwrwrw

1
1
1
1

root
root
root
root
root
bin
bin

system
system
system
system
system
terminal
terminal

8, 1
8, 1
13,1
7, 0
V, 1
3, 2
3, 3

Apr
Apr
Apr
Apr
Apr
Apr
Apr

18
18
18
18
18
18
18

11:04
13:15
18:08
15:20
15:20
16:10
16:10

/dev/rrzOb

/dev/tty02
/dev/tty03

!
.
(
!
.
(major) (minor) .
. !
(,
!
(, !
).
!
. 1.7.

. 1.7.

www.books-shop.com


UNIX

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

Solaris:
/dev/dsk/cOt4dOs2
,
( ) :
/dev/rdsk/cOt4dOs2

/dev/dsk ( ) /dev/rdsk ( !
). !
UNIX System V.
, SVR4,
:
sn

k , / ( SCSI
ID), m ,
!
(LUN) SCSI.
/dev/rdsk/cOt4dOs2
( 0)
LUN=2 .
SVR4
. !
!
. , Solaris /dev/sdOa !
/dev/dsk/cOt3dOs, :
root root

12 Oct 31

17:48

/dev/sdOa

SCO UNIX
/dev/root, /dev/usr . ,
(root, usr).

%RRNVVKRS

piracy@books-shop.com

1.

50

UNIX


. , , !

(, 1 . .).
, !
/dev/ttynn,
. . 1.6
.
1.6.

/dev/rstn
/dev/cdn

/dev/rst1
/dev/cdO

/dev/ttypn
/dev/ptypn

/dev/ptyp5

/dev/zero




SCSI%
CD%ROM
()
()

%




,
0

, %
0


UNIX, !
, . . , .
, . !
, , !
.
, ,
. !

www.books-shop.com


. !
, !
UNIX.
, ,
, ,
, UNIX .
,
. .
(
login name). !

(User Identifier).
, !
. !
, ( ,
).
, . !
( ,
), , !

(Group
Identifier). UID GID , !
.

!
,
, (!
). ,
. !
,
/etc/shadow.
, /etc/group !
, .

, /etc/passwd.
,
/etc/passwd .
(, !
), !
/etc/passwd !
, .
, !
. !
UNIX .

www.books-shop.com

1.

52

UNIX

,
.

no


:
(), .
:
name

. !
login.
!
. , !
,

.
. !
, !
. ,
, ,
passwd!encod. !
.
!
.
,
passwd!encod '' (
'!').
, '*',
. ,
'*' !
. , !
'*'
. !
.

www.books-shop.com

53

UID


. !
, !
, , .

(,
). UID = 0,
.

GID

!
. !
/etc/group,
, .
!
. !
!
(,
).

comments

, "" .
,
, . !
(,

) .
.
. ,

, !
,
.
, UNIX
.
UNIX !
. !

(Bourne shell),
(C shell)
shell),
. ,
, , !

(restricted shell), !
. , , !
,
. /etc/shells,
, !
.

www.books-shop.com

54

1.

, (
) . :
, !
.
.

, !
.

!
:
.
, . !
, , , ,
, . !
, . ,
! , . . , !
! .
, , .

!, . !
, !
( , ).
, !
:
;
2
;
3 ,
.
.
, , !
:
1.
. ,
, .
,
'*' .
2. , .

8 12.

www.books-shop.com

55

:
! .
, !
, , .
,
.
,
, .
4. ,
.
5. ,
. , !
. .
(!
, , !
).
.


UNIX !
. ( !
UID ):

root

bin
cron

news

, , UID=0.
.
, ""
. %
. %
, root . UID.
UID=0
,
, %
UNIX
, , %

, %
,
, %

www.books-shop.com

56

UNIX
()

nobody
uucp

, NFS

copy (uucp), %
UNIX%

.
, , , :

root wheel
, GID=0
user users staff ,
UNIX

UNIX
UNIX ,
, , . ,
, , drag!and!drop, ,
, UNIX , , Windows NT.
!
! .
. !
, UNIX
!
. , !
, shell. !
UNIX !
shell.

shell
UNIX
: Bourne shell
shell

shell
, !

shell (bash), .
!
UNIX, , :

www.books-shop.com

UNIX

57

1. , !
, shell. UNIX
(. 1.8):

, ,
.
!
,
, !


, !
shell.
Shell !
, .
.
Shell ,
,
, (
, )
, !
.
!
, exit, .
2. !
. !
,
Bourne. shell
, , ,
UNIX. shell
(script). !
, !
.
,

, :
, , !
. !
, , !
. "" ,
, . !
.


3.

www.books-shop.com

1.

58

UNIX


:

Bourne shell (sh)
shell (csh)
Korn shell (ksh)
Bourne%Again shell (bash)

.
!

. 1.8. ,

www.books-shop.com

UNIX

4. , !
shell.
(,
), .
Bourne shell

, ,
, . , ,
, shell , !
, !
.
, !
. !
, !
! .
Bourne shell, ,
.

.

,
, , !
. , shell . !

.
, , !
!
. Bourne shell
'#':
"" (
, core ..)

, :
find /home name core print

core

!
, !
:

Bourne shell. , (

%RRNVVKRS

piracy@books-shop.com

60

1.

UNIX

), !
, !
.

!
.
, :
var , a value .
,
, !
name
echo :
$ echo


name:

$
. !
, shell
. !
:
, , var , a command !
,
:
$ pwd

$
$ echo $cdir
$ cd /usr/bin
$ pwd
/usr/bin
$ cd $cdir
$ pwd

, var,
$var . !
. 1.7.

www.books-shop.com

61

UNIX

1.7.
$var

var; , var
, var
var, ; string.
var
, var ,
string
var , string
. string ,
var: parameter not set

var , %

, echo:
$ var=userl
$ varl=user2
$ echo $varl
user2
$ echo
userll
$ echo
want to redefine
do you w a n t to r e d e f i n e v a r ?

UNIX
, . !
:

PATH
MAIL
TERM
PS1
PS2





shell
shell

ansi
#
>


, :

,
:

www.books-shop.com

62

1. UNIX
()

PATH=/usr/bin:

%
7
1

$ pwd
/u/usr
$ cd some/new/directory
$ pwd

(

)
!
cd :
$

cd $HOME

.
PATH !
, . !
, :
$ run

run .
run , PATH
:
$

(!
, ). ,
, shell !
.
PATH ':'. ,
('.'), shell !
.

, PATH
'.'. . !
, ( !
), , /tmp, !
,
,

www.books-shop.com

UNIX
UNIX
( !

. ,


. ('.')
( PATH)

, "" .
, ,
, ,
PATH, .
MAIL ,
.
MAIL
TERM
. , !
, (,
).
, !
,
.
PS1 PS2 !
. !
. !

. ,
PS1. , !
, ,
, PS1 :

, , , telemak,
:
, <Enter>, !
. :
$
>
>
>

while :
do
echo
done

<Enter>
<Enter>
<Enter>
<Enter>


!
. ( ! , !

<Del>.)

www.books-shop.com

(54

1.

UNIX

, ,
.
, ,
shell ( ).
shell
,
. !
! . ,

MAIL, , ,
, ,
TERM.
.

.

, , shell !
, . !
, !
(. . #, !
$#). . 1.8.
1.8. shell
$2, . . .


shell
,
, .
, :
$2 $3 . .

$@

, .
, :
. .

, !
. .

echo
$0
echo $1 $2 $3
echo $1 $2 $3

2 4

www.books-shop.com

UNIX
$1, $2, ... $9
. $1

$2 2 . . . !
, shift n, !
(
). .
$0 . !
argv[], .
$# . !
!
.

if [ $#
2 ]
then
echo u s a g e : $0 argl arg2
exit 1
fi


$ test2.sh
usage: test2.sh
$
h2
$

arg2

if , !
.
($?) !
.
, 0, .
exit ,
(. ). !
,

grep(l) sergey .
grep(l) 0. , grep(l) !
, , !
sergey .
test3.sh:
grep sergey /etc/passwd
if [ $? ne 0 ]
then
echo sergey
fi

UNIX
, PID. , !
PID. PID $$. !
,
, :

www.books-shop.com

66

1.

UNIX

test4.sh:

/

/:

. !
, , , !
, ,
, .
, ,
. shell !
/. , !
, !
.
. 1.9 /, . 1.9
.
1.9.
>file
<file
1 |2
n>file
n>&m

file
file
file
1 2
file
To , file

" ": str.
%

To ,

.

:
$ logger

www.books-shop.com

67

UNIX

logger
. file.log !
, . , '>' !
, , .
, !
, !
. , , , 1 2. !
, . , !
:
$ logger

. log

. 1.9.
!
. , , !
:
$ run 2>/dev/null

,
.
.
,
$

2>S1 &

/dev/null.
'&' , !
1. ,
, ! !
. , Shell
,

www.books-shop.com

UNIX


!

( ). !
:
$ ps ef I grep

myproc.
ps(l) , !
grep(l) , ,


myproc. . !

$ ps ef | grep myproc I awk

print $2

myproc,
(.
!
. " ".
:
$ at Dec 31

cat

| elm

"

, at(l) ,
( ),
( 31 ).
" " , :
cat(l)
!
.
,
, shell,
:
:
$ ps !ef I grep myproc | grep !v grep
, ,
,
myproc: myproc grep(l)
myproc (ps

, !
).

www.books-shop.com

UNIX


shell,

shell ,
.
, !
shell (,
, shell
. shell.
:

. 0 ().

, :
while :
do
done

,

%
shell,
runme. ,
.
%
include_script, %
.
. runme

break []

for while. [
,
ps %ef I awk
print $1
I
while read uid pid
do
if [$pid !eq $PID]
then
echo pid=$pid user=$uid
break
fi
done

cd
echo [string]
exec



,
string %
()
runme, %
. , login shell
( , %
) exec Is,
%

%RRNVVKRS

piracy@books-shop.com

j obs

www.books-shop.com

UNIX

71

trap command
sig2

command,
,
sig. . ""

type name

, name %

, %

( , , ).
2

unset

w a i t pad

var2 .

, ,
%
. , PATH, PS1,
PS2,
%


shell. , !
, !
. shell, .
:
{

}
, shell.

shell .

mcd
{
cd
}

, , !
, !
:
1. . , !
, . !

www.books-shop.com

72

UNIX

, shell
, , !
, .
2. , :

.
, var

f i n d $var !name sh !print
. , !
:
f i n d / u s r / b i n !name sh !print

, . !
:
* ( ),
'.',
[abc] (
),
? .
/.
(>, <,
|), shell
.
/ " "
.
4. , !
. :
, ,
.
, !
shell, .
,


. , . .
( ), !
. , , !
.
, ,
. , rm !
:
$

client
server
$ rm *

$
$

www.books-shop.com

UNIX

rm(l) , !
. '*'
shell,
!
, . rm(l)
:
client

server


/, . !
, / !
, . , !
UNIX .

, !
, , !
,
. , .
,
, ';' :
$
date
Apr 18 1997 21:07

, : !

,
.
. shell !
, !
, .
'&':
$ find
$

print

&

find(l)
!
, ,
, .
!
.
,
. ,
, !
:
&&

www.books-shop.com

74

UNIX

!
, :
$ grep sergey

grep sergey /etc/group

, !
.
!
. !

\ \ echo

!
. !
,
.

Bourne shell , !
if. :
if
then

fi

commandl,
. . , !
. .
, !
. :
if grep sergey
then
echo sergey
fi

sergey grep(l) (

0), .
if.
set
if [

then

echo

www.books-shop.com

UNIX

if [
= "2" ]
echo 2
else
echo 3
fi

, !
, . !
.
test, (
)
test
if.
test
test :
test

[ ]
(. 1.10) 0, !
, 1 .
1.10. , test

%s file


file
%w file


%


%f


file
file
% file
file
%b file


% file


file
file
%g file
file SGID
%k file
file sticky bit

!z string


!n string
string

= string2

stringl != string2

www.books-shop.com

76

UNIX

1.10 ()

eq

11 % 12
12
12
11 12
11 %1
11 12
11
12

% 12
11 12

:
.'
!
!

, ( NOT)
( AND)
,
( OR)

.
, .

:
if [ ! f
then
echo "

fi

]
"

if [ s $MAIL ]
then
echo " "
fi

""
Internet
/etc/inetd , !
.
if [  /etc/inetd ]
then
/etc/inetd
echo "
fi

, , !

www.books-shop.com

UNIX
if [
then

77
!

exit

fi

Bourne shell .
:
1) while
do

done
2) until
do

commandl
done
3) for var in
do

commandl
done
while commandl,
. .
, . !
if, , , test.
until commandl,
, .

. . !

for ,
. var ,
. !
,
shell.
for, , var
, .
,
.
,

Solaris 2.5 , , !

while.

www.books-shop.com

78

1. UNIX

cat / e t c / v f s c k |
w h i l e read special f s c k d e v
fstype fsckpass
mntopts
vfsck
#
fsckdev . .
do
case $special in
' '* | ' ')
#
continue
tt ,
continue
esac

#
F $fstype $fsckdev >/dev/null 2>&1
done


( ) for.
for dir in
do
find $dir ! type d
done

+7 exec


/usr/tmp
.

case :
case in
command

command

esac

, . !
, , !
';' ,
", !

www.books-shop.com

79

UNIX

".
default
switch : !
, '*)'.

SCO UNIX.
state=$l
set
case $state in
if [ $9 = "2" o $9 = "3" ]
then
exit
fi
[ f
]

[ f

*)

echo "usage $0
esac

, start, !
. stop,
.
.

, !
. read
, !
. ,
.
read !
, , !
. !
, .
:

echo "input:
while read
var2 var3
do
echo varl=$varl
echo var2=$var2
echo var3 = $var3
echo "input:
done


$
input: read
read

var3=
$

%RRNVVKRS

piracy@books-shop.com

80

1. UNIX

read .
, ( !

read !
( 1) while .
, !
var3 . var3 .

.
Bourne shell
,


.
( ),
, .
,
, .
:

. %
%

, !
, !
. , :
%

% +

:
%

( )
,

, pref, %
, ls(1), , %
%ls

!
:

www.books-shop.com


bg

fg

jobs [!p | !1]

kill
stop
wait

81

UNIX


. [
.

.
, [
.

[
. , [
[
.
:
[1 [
.

.
, [

.
[
.

jobid .

!
:
$
&
[1] 9112
$
[2] 9113
$ jobs
[1] Running
+ Running
comml
$ stop %1
$ jobs
[1] Stopped (signal) inf.j
[2] + Running
comml
$ stop %%
$ jobs 1
[1]  9112 Stopped (signal)
inf.j (wd: /home/andy/SH/JOB)
[2] + 9113 Stopped (signal)
comml (wd:
$ bg
[1] inf.j &
$ jobs
[1] + Running
[2] Stopped (signal) comml
$ kill
$ jobs

www.books-shop.com

82

/. UNIX
[1] +
[2] ! Done
$

UNIX
UNIX.
,
.


[opt] .
cd [dir]

.
.
[opt]
file2 cmp(1) , %
diff [opt] filel file2
. ,
.

( 13%
4% ):
$ cat filel
1

2 3
7 8 9 10
11 12 13 14 15
$ cat file2
1
2 3

7 8 9 10
11 12 13 14 15 d i f f 2
$ cmp filel file2
f i l e l f i l e 2 d i f f e r : char 13, l i n e 4


, %
,
. ,
%
ed(1),
filel file2:
$
filel file2
4
> diffl

< 11 12 13 14 15
> 11 12 13 14 15 d i f f 2

www.books-shop.com

UNIX

[opt] filel

file2

[opt] filel

dir

[opt] filel

file2

[opt] filel

mv

dir

83

(1) .
, :
$ filel file2
$
filel file2
261425
1 andy user
261427
1 andy user

49 Dec 24
49 Dec 24

filel
file2

mv(1) .
,
(1) mv(1) 2.
%
.
. %

, (%
) ,
0.

[opt] filel...

[opt]

filel file2

[opt] source target

mode]

[!p]

ls(1)
.
, %
, ,
.
.

source
, target.
%s .

dirl...
pwd

fgrep [opt]

. %
.

filel...
grep [opt]
filel.
egrep
filel.


fgrep(1) (fast grep).

, .
, ,
:
5 fgrep "
chap*
%
/ , !.
, , %
!v.
grep(1) egrep(1)
, , %
, , %
.

www.books-shop.com

84

1. UNIX

, "" %
(center) (centre) ,
:
$ grep

file

$ grep

cat [opt] file


more [opt]
e
head
file
tail [opt] file

file

[er] , %
'
'
%
%
%
shell.
.
cat file file
. ,
, . . "" %
, cat(1) !v.
(, ,
) .
%
, %
(1) more(1), %
.
( n )
( n )
head(1) tail(1), .

,
:
$ sort

file

,
(,
; ,
). ,




,
$ sort
+1 file
:


www.books-shop.com

UNIX

( %
), +1 , %
.
.
%d<sep>. %
,
( ), %
:

cut

$ cat /etc/passwd |

cut

!d:

WWW Administrator
Y u r i Korenev
Serge Smirnoff
W3 group
Konstantin Fedorov
Andrei Robachevsky
Sergey Petrov

,
.
find

[opt]

UNIX, %
dir. ,

Bourne shell :
$ find / !name sh !print 2>/dev/null
/usr/bin/sh
/sbin/sh

%name
, %print (
).
find(1)
, , ,
. . ,
core ( ,

), , %
, (
""
), :
$ find / !name core !atime +30 !print

www.books-shop.com

86

UNIX

,
:
$

/ name core

+30 exec

.
user file

chgrp group file


mode file

% .
% .

...


.
.
(ASCII), file(1) %
(, . .).
,
magic number,
/etc/magic.
$ file *
report.doc:
work:
figure.gif:

tar archive
ascii text
directory
program text
ELF 32bit MSB executable
data


nice % [
command
renice new nice


(nice number), %
. , :
$ nice 10



nice. UNIX nice number,
. ,
,

, . ,
big_program , %
.
%
( nice number):
$ nice ! !10

renice(1) %
. ,
$ renice 5 1836

nice number %
1836 5.
nice(1), %
.

www.books-shop.com

87

UNIX
ps

ps(1)
.
:
F
( ,
. .)
S
(
, S
, R , I %
, Z )
UID
()

PID

PPID

PRI
%

nice number
TTY
('?'
%
)
TIME

( %
)
COMMAND
,

kill

. . signo. signo
, . kill !I
%
:
$ kill !I
1)

2)

3)

5)

6)

7)

4)
8) SIGFPE

9)

10)

11)

12) SIGSYS

13) SIGPIPE

14)

15)

16)

, :
$ kill 9 18793
$ kill SIGKILL 18793
at [opt]

at(1)
at, %
. %
,
.
, , %
:

www.books-shop.com

88
$ at May 30
cat

UNIX

I elm

%, %
%
.

UNIX
" !
" UNIX, ,
:
,
, .
, , .
.
"" , UNIX !
!
. ,
,
, .
, ,
.
.
, , "" ""
, .
!
. !
UNIX , !
. !
,
.
!
,
WWW! Internet,
.
UNIX:
. ,
.

www.books-shop.com

UNIX

89

Bourne shell, sed, , awk,


perl APL.
. (
!),
.
. , ,


, .
. , !
, !
.
, !
?

. !
,
, !
, ,
, ,
.

!
, " " .
. !

!
. ,
. , !
.
: # cd /home
#

!rf

!s * | sort

I head !1 | awk

# cd /home
cat
!s * | sort !rn | head !1 I awk
I compress

printf

2.
. !
, !
, ,
. !


, , !

%RRNVVKRS

piracy@books-shop.com

90

I.

UNIX

. !
motd.
. , !
!

:

# kill !9

# compress
I awk '

sort !rn +8 !9

!augxww

head !1

s o r t !rn +8 !9

head !1

$2}

.
. Perl,
, !
/etc/passwd, /etc/shadow /etc/group.

!
. !


.
.
motd.
,
, , , !
.
. " , !
, .
".
:

# cd /home; mkdir
echo "Bob
/etc/passwd

home d i r e c t o r y "
!f" >

4.
. . !
. , !
, ,
, !
.
!, .
. . !
, , !
.

www.books-shop.com

UNIX
. . !
. .

.
. .
5.
. ,
, 2%. !
, : " , ",
.
.
AT&T, , !
. xtrek.
. Ethernet !
.
: # compress !f / d e v / e n O
6. ""
.
!
, !, .
. ,
.
: # cat
alias vi
f

cshrc
v BoZo

> ~/.z;

. .
.
7.
.
, .
. !
, .
: # uptime
l : 3 3 p m up 19 days, 2 2 : 4 9 ,
6.45,

users, load average: 6 . 4 9 ,

6.31

www.books-shop.com

92

UNIX

wall
, .
, 500.

:

8.
. RDBMS, perl Smalltalk. !
.
. Oracle.
.
.
grep(l) .
: % dd ibs=80 i f = / d e v / r d i s k 0 0 1 s 7 | grep "Fred"

UNIX, !
,
, !
/.
shell,
. , , !
, , , !
UNIX. !
, !
UNIX.

www.books-shop.com


UNIX

,
UNIX, .
.
UNIX. !
, !
. . , !
!
,
. !
, UNIX.
UNIX
.

UNIX ; !
, ,
, !
; , !
.
!

UNIX: !
. !
, /,
, .
:
, ,
.

UNIX

UNIX !
, !

www.books-shop.com

94

2. UNIX

, !
UNIX.
(system calls). , , , !
, !
, !
. UNIX
50 , , , SVR4, !
120.
2
. UNIX
,
. UNIX , !
( )
, ( !
!
). !
,
. ,
,
.

.
,
. ,


, !
strcpy(3C) ( )
(
)
. , , !
!
UNIX.
3 .
, ""
,
. !
.
!
, Epoch: 1 1970 !
. , !
, ( )
,
. .). !
/, ,
. .

www.books-shop.com

95

UNIX

. 2.1 !

.



. !
,
.

errno, !
. , , !

,
errno. <errno.h>
, errno, !
.
, , !
errno, . !
!


, .
errno :
external

int errno;

www.books-shop.com

96

2.

UNIX

,

. ,
errno ,
.
ANSI , !
:

ttinclude <string.h>
char

errnum !
,
.

:
<errno.h>

void

char

!
, errno.
s, , !
,
, .
:
<errno.h>
<stdio.h>
argc, char

{
errno =
perror (argv [

, :
$
ENOMEM: Not enough space
Exec format error

, ,
UNIX. :
$
No such f i l e or directory

ENOENT

$ pg
do_not_read:

Permission denied

EACCESS

www.books-shop.com

97

UNIX

. 2.1 , !
,

.
2.1.

E2BIG
Arg list too long

, %

%
ARG_MAX

EACCESS
Permission denied

%
( %

GID
)

EAGAIN

%
, ,
%
UID.

(.
"" )

Resource temporarily unavailable

EALREADY
Operation already in progress

EBADF
Bad file number

,
; %
%
,
,

EBADFD

File descriptor in bad state


EBUSY
Device busy

(
), ;
,
; %
(, . .)

ECHILD
No child processes


,
,

EDQUOT

,

,

inode

Disk quota exceeded

www.books-shop.com

2.

98

UNIX

2.1 ()

EEXIST
File exists

%
, ,

EFAULT
Bad address


, , %

EFBIG
File too large

%
RLIMIT_FSIZE %
(.
"" )

EINPROGRESS
Operation now in progress

(, %
) %

EINTR
Interrupted system call

, , %
SIGINT
%
.
,

EINVAL
Invalid argument

%
. , (%
), %
. %
kill(2)

I/O error

EISDIR
Is a directory

, ,
,

ELOOP
Number of symbolic links encoun%
tered during path name traversal
exceeds
EMFILE
Too many open files

%

, MAXSYMLINKS

OPEN MAX

File name too long

( ) %
PATH MAX


File table overflow
ENODEV
No such device

. %
,

www.books-shop.com

99

UNIX

2.1 ()

ENOENT
No such file or directory

ENOEXEC
Exec format error

,
, %

ENOMEM
Not enough space

No message of desired type


, (. %
"" 3)

ENOSPC
No space left on device

%
%
( )

ENOSR
Out of stream resources


STREAMS. %
. %
%

ENOSTR
Not a stream device

,
STREAMS ( %
putmsg(2)
%

ENOTDIR
Not a directory

, %
,
(,
)

ENOTTY
Inappropriate

for device

ioctl(2) %
,

EPERM
Not owner

, , %

. %
, %

EPIPE
Broken pipe

(pipe),
, .
%
.

%RRNVVKRS

piracy@books-shop.com

2. UNIX

2.1 ()

EROFS
Read%only file system
ESRCH
No such process


( ), %

PID


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


UNIX.
, ! ANSI
UNIX, !, ,
, ! ,
UNIX, .
, ""
UNIX,
, , !
, , ,
, .
!,
, . , !
.

, UNIX, !
, !
. , !
. , ,
UNIX, !
.

, UNIX ( ) !
,

!.

www.books-shop.com

101

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

, , , .




!
, .

!
,
(1). , !
, ,
, .

#include. , (<>),
,
.
,
.
, creat(2)
, <fcntl.h> :
linclude
ttinclude <sys/stat.h>
<fcntl.h>
int

char

creat(2) !
!
, .
, ,
char,

UNIX !
, , creat(2)
int. ,
_t,
UNIX, .
<sys/types.h>, !
.
, int, char . ., !

www.books-shop.com

2.

102

UNIX

, !
. , UNIX
, creat(2)
mode_t.
, !

.
UNIX ,
,
. , ANSI , POSIX. 1 XPG4,
,
. 2.2.
2.2.

<cpio.h>

, %
cpio(1)
, %
(ASCII, %
, . .)
isdigit(3C)

<dirent.h>

,

. .
(. "%
" )

<errno.h>
<fcntl.h>


open(2)
creat(2), ,

, %

<ftw.h>

, %
(file tree walk) ftw(3C)
nftw(3C), a

<grp.h>

%
, :
getgrnam(3C),
getgrgid(3C) . .
: ,
. .,

<langinfo.h>

www.books-shop.com

2.2 ()

<limits.h>

,
: %
,
,
. .

<locale.h>

, %
,
( ,
. .), setlocale(3C)

<math.h>

(, ,

(message
catalog), catopen(3C)
catclose(3C)

/etc/passwd, :
getpwnam(3C), getpwent(3C),
. .
<regex.h>

, %
, %
:
. .

<search.h>

,
, : hsearch(3C),
hcreate(3C),
setjmp(3C),
siglongjmp(3C), a %

<setjmp.h>

<signal.h>

<stdarg.h>

, %
:
sigemptyset(3C),
. . (. ""
)
, %

<stddef.h>

( size_t)

<stdio.h>

<stdlib.h>

<string.h>


string(3C), strcasecmp(3C), strcat(3C), strcpy(3C) . .

<tar.h>

, %
tar(1)

www.books-shop.com

2.

704

UNIX

2.2 ()

<termios.h>

, %

<time.h>

, %
: time(2), ctime(3C),
localtime(3C), tzset(3C), ,
getitimer(2), setitimer(2). %
3

<ulimit.h>


ulimit(2) , %
. . "" %

<unistd.h>

<utime.h>

%
utime(2) %
( )

<sys/ipc.h>

, %
(IPC),
3

<sys/msg.h>

, () %
IPC. . "" 3

<sys/resource.h>


, %
: getrlimit(2) setrlimit(2).
""

<sys/sem.h>

, () %
IPC. . "" 3

<sys/shm.h>

, ( %
) IPC. . " %
" 3

<sys/stat.h>

%
,
: stat(2), lstat(2),

" "

<sys/times.h>

%
times(2), %
(
, . .)

<sys/types.h>

www.books-shop.com

105

2.2 ()

<sys/utsname.h>

%


(, ,
..)

<sys/wait.h>

. 2.2.

. 2.2.

www.books-shop.com

2.

UNIX

,
, , !
(1).
( Makefile), !
. !
.


!
,
, !
. !
: , !
. ,
(

, !
. ,
(

,
.

!
:
$ make prog

$

! prog

prog. !

prog !
!.
, , !

,
!
,
.
!
.
$

% f

f ile2 .

% prog filel.o

file2.o

prog, %

www.books-shop.com

/07


!
. , !
, , ,
, !
. UNIX !
COFF (Common
Object File Format) ELF (Executable and Linking Format).
, !
!
. , ,
COFF ELF !
:
?
?


( , !
!
), , ,
,
?

, !
?
. 2.3 , !
COFF ELF, .
,
. (text), !
(data), (stack). ,
,
.
,
. !
" " .
,
, !
, !
. !
BSS.

www.books-shop.com

108

2.

UNIX

. 2.3. COFF ELF

ELF
ELF , !
!, , .
ELF :
1. (relocatable
,
. !
!
.
2. (shared object file) !
, .
, !
,

. , !

,
.
.
, !
. , , !
,
.

www.books-shop.com


. 2.4 , !

.
. !
, !
. !
, .

2.4. ELF
ELF! ,
(. 2.4).
2.3. ELF%

[]

e_type

, %
:
,
(32% 64%) . .
, ELF

%RRNVVKRS

piracy@books-shop.com

2. UNIX
2.3 ()

e_phoff
shoff

e_phnum
e_shentsize

,
. . 2.4
ELF%. EV_CURRENC
(),
, %
( )
( )





()
()
,
2.4. e_machine ELF%

88

Sun SPARC
Intel 80386
Motorola 68000
Motorola 88000

486

Intel 80486

860

Intel i860
MIPS RS3000 Big%Endian
MIPS RS3000
RS6000
PA%RISC
nCUBE
Fujitsu VPP500
Sun SPARC 32+

386
68

MIPS
EM MIPS RS3 LE
EM R S 6 0 0 0
EM PA RISC
EM

EM V P P 5 0 0

EM SPARC32PLUS

, ,
, .

www.books-shop.com


() !
, ,
.
!
:





(, , )
LOAD,

, ,
. !
, ELF!
, ,
.
, , , !
() . ,
. !
,
(BSS). 3.
INTERP .
, !
. ,
( !
) ,
. ,
.
, .
, !
, . !
UNIX !
. !
,
,
. .
,
(section).
() ,
!
. ,

www.books-shop.com

2.

UNIX

.
. , ,
, ! !
,
!
, , ,
, .
ELF 3
, !
COFF.
COFF
. 2.5 COFF. !
COFF
UNIX

,
. , ,
.

. 2.5. COFF

. !

www.books-shop.com


,
.
(symbol table)
(string table). ,
. , , locptr
Ox7fehO. ,
, !
. .
, !
.
, , ,
strip(l).
ELF!, , !
(. 2.5).
2.5. COFF%

f_timdat

f_f lags

, , %
. .

COFF ,
.
COFF
,

(. 2.6).
2.6.

tsize
dsize


(text)
(data)

bsize

(bss)

SCO UNIX

.

www.books-shop.com

2.

UNIX

2.6 ()

entry

text_start
data_start
COFF , !
.
.bss , !
), , !
.
.
.
, ,
.
,
, , , ,
(, . .).
, .
.
!
. !
!
. , !
, ps(l), .

UNIX
!
,
.
.
, ,
, ,
.

,
(. . ), !

www.books-shop.com

UNIX

115

!
.
!
:
argc, char

char

(argc) , !
, .
argv [

,
, ,
argv
. . argv
envp [ ] , !
.
!
1, !
. "".
ANSI
argc argv. POSIX.1 envp,
!
environ, . 2.6:
extern char

!
UNIX.

. 2.6.
,
!
,

, !
.
ttinclude
extern char
argc,

char

www.books-shop.com

16

2.

UNIX

int i

argv[0],
for
i++)
=
for
i++)
if (environ[i] != NULL)

(
a.out). , :
$ a.out first second 3
,
argv[l] = first
= second
argv[3] = 3

!

!


sysconf(2).

:

ttinclude <stdlib.h>
char
char
name, a
int

char



.
, !
, !
.
ttinclude <stddef.h>
tinclude

www.books-shop.com

UNIX

argc,

{
char
char

if
=
== NULL)
/* ,

{
TERM ,

}
else
/* TERM ,
,
{
Change?
gets
if
||
{

}
}

, TERM. !
TERM , !
. TERM , !
,
.
:
$
TERM=ansi. Change? [N]y
TERM=vtlOO
new
$

,
:
a.out TERM, , :
$ echo
ansi
$

www.books-shop.com

2.

UNIX

"
" .
, , !
. !
, , , !
. : !
, ,
? , ,
, .
shell
!
/: , !
. (
) !
(
!
, , !
.
shell . shell
(
),
(>, <,
. 1, " UNIX"). " !
" !
.
!
,
.
, ,
, !

!
, , ,
, main().

. !

exit(2),
. , !
, , !



exit(2)
!
:

www.books-shop.com

UNIX
, !

(. ""
). exit(2)
.
exit(2) :
void

status,
!
. !
0 !
. !
, . , grep(l),
,
:


1
2


. , ( fail)

shell:
{
}

$ fail

$ echo $?
i
$
| | echo

fail
shell, fail

fail

, exit(2) ,

!
/. _exit(2), !
/,
.
. " ".
(exit handler), !
, exit(2), !


" ".

%RRNVVKRS

piracy@books-shop.com

2.

120

UNIX

. , LIFO
( ), !
"" . ,
.
!
(. "" ).

#include
int

atexit(l) 32 .
. 2.7 !
, .

. 2.7.

www.books-shop.com

121


UNIX
/:
1. ,
, !
.
2. /, !
/.
""
, .
:
, , !
;

;
;
;
,
, ,

. 2.7 ,
.
,
/, !
, .
2.7.

creat(2)
close(2)

/ %
. , , %
, %
. ,

,

www.books-shop.com

]22

2. UNIX
2.7 ()

dup2(2)
lseek(2)

writev(2)
pipe(2)
fcntl(2)

,

%
. / ,







, %

:
int

char *path, int

(path) . !
( /),
( ).
lag
, . 2.8, .
, !
, ,
(2) (errno=EACCESS). mode,
,
( . 2,8,

)
" " .
2.8. ,

O_RDONLY

0_WRONLY

www.books-shop.com

123

2.8 ()

O_RDWR

O_APPEND

, . . %

, %
. , ,
(.
" " " "
mode

0_EXCL

O_CREAT, (2) %
,

O_NOCTTY

O_SYNC

0_TRUNC

,
0

O_NONBLOCK

read(2) write(2)
. %
, , ,
EAGAIN

,
, !
, . .

. , 0 2 ( !
), (2)


/:
$

(1)
close
/*
1 ,

=
,
0
I 0 CREATE ] 0

www.books-shop.com

}24

2.

UNIX


!1, errno !
(. " ").
, 0_RDONLY,
of lag.

o_SYNC , ,
, !

,
, .

, !
.
!
, .
4.

/
.

!

errno = EAGAIN, , !
, ,
.
creat(2)
!
:
ttinclude
int creat (const char


path
, a mode . !
:
(GID)
(EGID) !
, SGID !
mode ( ).

,
Sticky bit.

1. !
" " .
, 0,
. creat(2) !

mode);

www.books-shop.com

!
,

:
int

errno !
.
close(2) !
. , exit(2),
,
.

dup2(2)

int

f i l d e s !
(2), creat(2),
pipe(2). !

!
, fildes.
, , !

( ), !
. !

, !
, :
int

fildes, int

, ,

f i l d e s 2 . !
fildes2 ,

shell:
$

2>61

(1)

www.books-shop.com

126

2. UNIX

fd =

lseek(2)
, !
, !
.

. , !
0 ,

. lseek(2)

. :
ttinclude <unistd.h>
off_t lseek(int fildes,

off_t offset,

whence);

o f f s e t whence,
:
SEEK_CUR

SEEK_END


, !
.
lseek(2) !
. !, lseek(2) /,
.
!, , lseek(2), !
. ,
, ,
, . ,
, !
, !
4 .
read(2) readv(2)
read(2) readv(2) , !
,

www.books-shop.com


pipe(2) fcntl(2). !
:
ssize_t
ttinclude

fildes, void *buf, size_t


<sys/uio.h>
fildes, struct iovec *iov,

ssize_t

,
,
nbyte , fildes, !
. !
, buf.

nbyte.

iovcnt !
readv(2). iov !
, :
struct {

void

iov_len;

!
, iov.
, . 2.8, scatter read
( scatter (.) ). !
.
write(2) writev(2)

read(2)

. :
ttinclude
ssize_t

ssize_t

fildes, void

size_t

<sys/uio.h>
fildes, struct iovec

int iovcnt);

,
, !
nbyte , fildes, !
. !
, buf. !
nbyte.


iovcnt

www.books-shop.com

2.
/ gather (),
/, ,

. 2.8.

pipe(2) ()
( )
. ,
(, ) !
. !
" "
. :
int

f ildes [

, a
.

!
!

!
3.

www.books-shop.com

pipe(2) !
,
, !
. !
, /,
, , . !
!
!
. , , SCO UNIX
5.0)
HPPS (High Per!
formance Pipe System). HPPS
!
, .
fcntl(2)

!
.

,
, :
<fcntl.h>
int

int cmd,

cmd ,
:
F_DUPFD

,
. %
, f ildes. %

F_GETFD


(

(FD_CLOEXEC). , (2)
, ,

,

, %
. , , %
, %
(2). . 2.8. :
=
F_GETFL,
,
accbits =
&
if (accbits == 0_RDONLY)

else if (accbits ==

fddup =

F_SETFD
F_GETFL

F_DUPFD,

fildes2)

else if (accbits

%RRNVVKRS

piracy@books-shop.com

130

2.

F_SETFL

UNIX

, %
.
0_APPEND, 0_NONBLOCK, 0_SYNC 0_ASYNC.

F_GETLK

F_SETLK

F_SETLKW

. %
, ,
.
%
,

.
, %
. 4,
" ".
.
%
,
. fcntl(2)
EACCESS EAGAIN.
,
, %
, , . %
W wait ().

/
,
/ .
,
""
UNIX, /.
,
,
/.
/ .
!
<stdio.h>. (libc.so

, ,
.
!
( FILE),
. /

stdout, stderr !
, . !
:
extern FILE
extern FILE
extern FILE

www.books-shop.com


!
. 2.9.
2.9.

1
2

()

stderr

2.10.

fopen(3S)

%
,

fclose(3S)

,
,

getc(3S)

putc(3S)

gets(3S)



( )
( )

fseek(3S)

scanf(3S)


, ,
/, , . , ,
:
(1, ",
printf

printf(3S).
, ,
. !
, 1,
.

www.books-shop.com

2.

UNIX

, . .

,
.
,
, .
!
.

/,
read(2)
!
, !
.
:
. !
, /.
/ , , !
. malloc(3C)

, !
getc(3S), gets(3S),
puts(3S) . . !
, !
. !
(. . ) , !

. !
/ (. . read(2)
( !
). !
, ,
.
.
,
.
, , ,
.
.
:
<stdio.h>
void
int

char
char *buf, int type,

setbuf(3S)
stream. buf
NULL.

www.books-shop.com

133

!
, , . !
type, :
_IOFBF

_IOLBF

!
FILE, . 2.9,
_base, ,
_cnt,
_file, ,
_f lag.
.
s t _ b l k s i z e stat,
" " . !
, !
,
!
<stdio.h>.

. 2.9.

UNIX
, , . !

www.books-shop.com

134

2.

UNIX

,
(
etc/rc0.d/K201p, /etc/rc2.d/K20Ip

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

int

char

const char

new
inode existing. !
. , , !

1.

ttinclude <unistd.h>
int
char


.
. , ,
, , !
, !
, (,
).
, ,
, UNIX !
, , .
, ,
, .
!
.
!
. , ,
!s.
ttinclude <unistd.h>
int
char *name,

const char

, name !
symname. ,
,
. !
. . !
,
, !
. ,
. .
,
.

www.books-shop.com

/35

access (2)
chdir(2)
chmod(2)
chown(2)

+
+
+
+

creat(2)
exec(2)
link(2)

+
+
+
+

mknod(2)
open(2)
readlink(2)

lstat(2)
unlink(2)

+
+
+
+
+
+

!

ttinclude
int
char *path, void *buf, size_t
path .
!

.

, ,
, !
:
linclude
ttinclude
ttinclude <fcntl.h>
<stdio.h>
BUFSZ 256
/*B

argc, char

www.books-shop.com

136

2.

char
int n r e a d ,

UNIX

fd;

/*

nread =
buf,
if (nread < 0)
{
}
/*readlink
=
/*

fd =
if (fd < 0)
{

}
nread =
if (nread < 0)
{

buf,

}
=

exit
}

, !
unix0.txt:
$
$

s
1
1
1

andy

user
user

10
498

Jan 6 0 9 : 5 4
Jan 6 0 9 : 5 3

s y m l i n k . t x t !>
unix0.txt

1975 AT&T

, .
,
,
, UNIX.

www.books-shop.com

,

, !


!
.
.
!
:
#include
caddr_t
int

addr, size_t
int prot,
f l a g s , int f i l d e s ,

len fildes,
o f f , addr.
,

prot !
, ,
(2). . 2.12
prot .
prot.
PROT_READ |

.
2.12.

[
prot

PROT READ

PROT WRITE

PROT EXEC

PROT NONE

addr 0,
!
. , !
!
.
len

, 96 ,
4 ,
4096 . 96 , !
4000 . !

3.

www.books-shop.com

138

2.

UNIX

4000 , !
. , !
,

,
.
(prot = PROT_EXEC) !
. ,
!
, !
.


(, ), !
.

!
. . 2.13 , !

2.13.
flags

MAP_FIXED
MAP_NORESERVE

%

%

, %
addr
He


,
, ,
. ,
, ,
MAP_SHARED
.

. .
. !
, ,
addr. addr
0,
.
, ,
, . ,
.

www.books-shop.com

139

.

!
. ,
,
. . !
.
.

!


!
.
<sys/stat.h>

#include
raain(int argc, char
{
int
caddr_t addr_src,
struct stat filestat;
,
|

/*
lseek(fd_dst,
 1,
/*3
fd_src,
PROT_READ |

fd_dst, 0);

/*
addr_src,
exit

, ,
!
, lseek(2) !

.

. !

.
, !
! .

%RRNVVKRS

piracy@books-shop.com

2.

UNIX

,
. "",
, , .

! !

int
int
int

char
fildes,
char

uid_t owner, gid_t


owner, gid_t
uid_t owner, gid_t

, !
.
,
(. . ).

,
!
. owner group
!
.
BSD UNIX
. , ,
"" , , !
. !
, ,
, .

System V ,
UNIX System V !
.
SUID SGID
, ,
!
.

,

EUID EGID. !
UID GID , EUID
EGID !
. !
. , , !
, . ,

, ,

www.books-shop.com

141

.
SUID SGID.
.
!

iinclude
<sys/stat.h>
int chmod(const char *path, mode_t
fildes,

mode !
( SUID, SGID Sticky bit),
, . 2.14.

(, )
.
2.14. mode

S ISUID

04000

SUID
SGID,
7, 5, 1
, #
6, 4, 2
Sticky bit
,
%
%%

%
%%

,
%
%

S_ISGID

S ISVTX

01000
00700

S_IRUSR

00400

00200
00100
00070

00040
00020

S IXGRP

00010

S IRGRP

00007

00004
00002

S_IXOTH

00001

S IROTH

%
%
,



%

www.books-shop.com

142

2. UNIX

, ,
. , ,

|
| S_IXUSR. S_ISGID , !

,
SGID, !
.
,
, .

ls(l) !
.
ttinclude
<sys/stat.h>
<stdlib.h>
main
{

int fd;
/*
fd =
1

*/

1
*/
|
1

1

, !
:
$

rws
rws
rws

andy

1
1 andy

user
user
user

0
0
0

D
.;
Jan 6 19::28
Jan 6 19::28
Jan 6 19::28

my file
my file
my file


,
(root directory) (current
working directory). (,

!
, ,
, , !

www.books-shop.com


. '/',
. .
,
,

, !

int
int

char


, , path.
,

, , !
, , !
, !
, .

.
. !

int
int

<unistd.h>
char

,
:

char
, ,

== 1)

!
. , . . !
( ) ,
,
.

www.books-shop.com

2. UNIX

144

,
, , , ,
, , !
.
inode. !

<sys/stat.h>
char
struct stat
(const char
struct stat
fildes, struct stat

int
int

s t a t ,
.
2.15. stat

mode t st mode


inode. st_ino st_dev %

ino_t
dev t st dev

dev_t

, ( %
)
%
,

t st

uid t st uid

gid_t st_gid

%
.

off t st size
st_atime
time t st

time t st ctime

long st b l k s i z e

long

512% .

st_blocks

, !
<sys/stat.h>:

www.books-shop.com

145

2.16.

FIFO

, ( , !
) , 0
1970 . ,
.
, !
:
<sys/stat.h>
#include <time.h>
argc, char
{
struct stat
char
, &s)

) ptype = " ";


else
st_mode) ) ptype = "";
else
ptype =
";
else
ptype = ". ";
else
ptype =
else
ptype = "";
else
ptype = "FIFO";
else ptype = "

=
/*
=

&

/* inode*/
=
/*
=
/*,
= (%d,

www.books-shop.com

2. UNIX

=
=
/*
= (%d,

=
,
=
=
=

!
, , .

.
:
$
type =
perm =
inode = 13
= 1
dev = (1,
= 286
= 100
rdev = (0, 0)
size = 1064
atime = Wed Jan 8 17:25:34 1997
mtime = Wed Jan 8 17:19:27 1997
ctime = Wed Jan 8 17:19:27 1997
$
13
1 andy
user

1064

Jan 8

1 .
, .
.
. !

!
. ,
, .
:

www.books-shop.com

/47

:
,
.
,
. !

.
.
, !

.
" " 3.

; .
, , , !
.


,
, . !
PID !

PID !
, , , !
. PPID
, ( )
.
, !
: !
UID, EUID, !

EGID.
,
, .
, ,
UNIX.
, ,
. !

SGID.

!
, login shell,
. UID (EUID) GID
(EGID) shell ,
/etc/passwd. , !
, .

www.books-shop.com

148

2.

UNIX

,
, ,
, shell.
login shell, !
.
, "" !
SUID SGID. ,
,
, !
.
!
.

. 2.10.

www.books-shop.com

149

!
:

uid t
uid_t
gid_t
gid_t



.
!
:
ttinclude
<unistd.h>

int
int

gid)


setgid(2) !
,
setegid(2)
.

!
, . !
!
,

<pwd.h>. . 2.17.
2.17. passwd

char

char *pw_passwd

, ; %
%
/etc/shadow,

gid_t

char

( GECOS), %

char

char

%RRNVVKRS

piracy@books-shop.com

2. UNIX

, ,
. :
linclude <pwd.h>
struct passwd

char

, :
passwd *pw;
char

char

char
/* logname,

pw =
/* ,

if ( pw == 0 )
/*

else
{

arg,
}

execve(2) ,
. "
" .


!
, .
!
,
, (heap ).
.
, , !
!
, .
:

www.books-shop.com

1. , !
, :
char ptype = "Unknown f i l e type";

ptype
,
.
2.
,
:
char

ptype
, !
, , BSS.
, !
, .
. :
fund
{
int
char
static int =

.

,
.
3.
4. !
. ,

,


.

,
, ,
.
, (heap) !
, ,
.

! (break address). !
!.

www.books-shop.com

2. UNIX

752

UNIX brk(2)

int
void

brk(2) ! !
endds , ,
(. 2.11). sbrk(2) !
incr. incr 0, !
, ,

brk(2)

, !
/ .
<stdlib.h>
void
void
void
void

size_t
*ptr, size_t

s i z e .

calloc(3C) nelem
, e l s i z e . !
.
realloc(3C)
( ,
size).

, ( !
) , . , 100 !

4096 , 4.

www.books-shop.com

/53

, !
.
free(3C) , !

!
ptr.
,
calloc(3C) realloc(3C),
,
. ,

double , 8,
, .
!
sbrk(2) brk(2). ,
, !
, free(3C). , !

!
, !
,
, !

free(3C), . !

#include
ttinclude <stdlib.h>
{

char
char
char

obrk =
=
64
naddr =

nbrk =

Ox%x,
= % (
naddr, nbrk, nbrk
,

obrk =

www.books-shop.com

2.

UNIX

" != % (
obrk
}

:
20

= 208, 
22

)
(Ox20ac8)

22 ( 0 )
$

,
free(3C), ! .
,
, .


, !
. .


shell , , ,
.
, . U N I X
.
: , .

. h>

, ,
, ,
. , !
, :

,
,
,
, ,
,
,
, ,
.

, !
: , , ,

www.books-shop.com

/56

. .

,
.
,
:

PPID
,
, ,
, fork(2)
.
. ,

, !
. PID
, , , , 0.
!1, (,
, !
).
fork(2) ,
, , , !
. :

/*

}
else

}
}

,
, !

, !
, !

www.books-shop.com

156

2. UNIX

. , , !
, :
, !
. !
, . !
,
! , , !
.
UNIX ,
, . . . !


:
int
int
int
int
int
int

(const char

const char *argO,


const char *argn, char *
char
char
execle (const char
argO [
const char
char *
char
execve (const char
char
argv [
char
execlp (const char *file, const char *argO,
const char *argn, char *
execvp (const char *file, char *const


execve(2), !
( ),
.
,
, !
. . 2.12 ,
.

fork(2), .
, :
PID PPID,
,
( , !
SUID SGID),

, ,

FD CLOEXEC.

www.books-shop.com

157

. 2.12. (2)

.
, , !
UNIX. !
/
.
. 3.
1
(2),

!
, .

www.books-shop.com

2.

,
, ""
"". , ls(l),
!
!
. , !
.

"" . !
. !
.
, !
.

<sys/wait.h>

pid_t

idtype, id_t id,


int options);
pid, int *stat_loc, int


!
,
! .

!
stat_loc, !
. s t a t _ l o c !
:
() , %
.
WIFEXITED(status) ,
( %

, %
.
WIFSIGNALLED(status) , %
, %
.
WIFSIGNALLED(status) ,
core.

!
. idtype id ,

www.books-shop.com

/59

[
idtype

, %
, PID id.
waitid(2) , %
, id.

P_ALL

,
.

options , , !
,

options

.
(trap)
(breakpoint) .
% %
.
, %
.
, %
(. .
).
,
,
.

infop siginfo_t, !
.
.

!
.
!
!
.

/*
get

%RRNVVKRS

piracy@books-shop.com

2.

UNIX

/* : and
and,
pid =
if (pid == 0)
{
/*3
/* 

pexit
}
else
(shell)

!
!
. , !
,
, !
.
UNIX, !
. "",
()
.
, BSD, System V, ,
(reliable) . ,
BSD, System V. !
POSIX.1 !
.
, !
. , , !
<Del> <Ctrl>+<C>,
S I G I N T . , <Ctrl>+<\>,
UNIX 15 ,
.
, !

ttinclude
<signal.h>
int

t pid,

int

www.books-shop.com

, .
.
:
( ) !
. !
, <Del> (
!
SIGINT, ,
!
, , 0,
. .,
. !
, (,
). !
, ,
.

.
, ,
.
SIGALRM, , ,

kill(2)
, .
, , !
, , . !
, , !
. !
.
,
:
,

.
.
,
SIGSTOP !
, . SIGKILL !
"" ,
SIGSTOP .


. !
.

www.books-shop.com

2. UNIX

. 2.18. ,
.

core (

. !
!
!
. core !
:

!
! !
;

SGID, !
! !
;

core (
. "" ).
2.18.

,

, %
, %
alarm(2) setitimer(2).

. %
,

.
, %
(

%
, ).
,
.

,
.
%
, 0 %
.

www.books-shop.com


2.18 ()

,
, %
, (
). %
%
.

%
. ,

. %
SIGHUP
, %
, ,
.

SIGILL
SIGINT

SIGPIPE

, %
.

%

<Ctrl>+<C>).

,
.
, .


, %
( %
).
%
, %
.

.
,

(UPS).

SIGQUIT

SIGSTOP

%
<Ctrl>+<\>.


<Ctrl>+<Z>. %
.

%
.

www.books-shop.com

2,

164

UNIX
2.18 ()

SIGTERM

%
, %
. %
" "
, %
. . kill(1)
.

SIGTTIN

( %
)
.

SIGTTOU

( %
)
.


%
.


%
.

UNIX , !

,
UNIX. fork(2) !
.
(2)
. ,
!, !
(2).

:
<signal.h>
void (*signal (int sig, void

sig , .

,
! !
:
SIG_DFL

,
, . . .
, . , %
.

www.books-shop.com


!
!

!
.


. !
. !, !
, . .
. !, !
, .
!
. !
signal(3C).
, !
:
<signal.h>
static void
{

signo)

pause

: SIGINT, SIGUSR1
SIGINT
SIGUSR1
( ),
.

,

, ,
!1, !
errno EINTR. ,
SIGINT !
,
( ).

www.books-shop.com

2. UNIX
, :
$
&
[1] 8365

PID

$ kill !SIGINT 8365

SIGINT
$ kill
8365

SIGINT
SIGUSR2

$ kill !SIGUSR1 8365

User Signal 1

SIGUSR1 [


POSIX. 1 !

UNIX
.
, POSIX, !
(signal set), s i g s e t _ t .
.

32 , !
32.
:
frinclude
int
int
int

*set, int
*set, int signo);
*set, int


, !
s i g s e t t,
. !
, .

, .

, !
. sigaddset(3C)

.
!
, signo .

1
, !
.
:

www.books-shop.com

167

<signal.h>
int sigaction (int sig,

const struct sigaction *act,


struct sigaction

!
sigaction, :
void (*sa_handler) ()
void
(int, siginfo_t *, void *)

sigset_t
int

sig
sig

,
,
SIG_DFL
!.

sa sigaction NULL,
!
, .
, !
, .
, .
!
. , ,
!, .
, , !
.
, UNIX , , !
!

, .
:
% ,
sigaltstack(2)
%,
.
, .
SA_RESETHAND*

%,
SIG_DFL,
. ,
.

SA_NODEFER

%,
, %
sa mask. ,
.

* UNIX BSD.

www.books-shop.com

168

2. UNIX

SA_RESTART

%, ,
,

,
,
,

, sa_handler.
sig SIGCHLD, %
.

wait3(2),

%
.
SA_NOCLDSTOP* sig SIGCHLD, %

.
UNIX BSD 4.x sigaction :
struct sigaction {
void
sigset_t
int

! :
void

signo, int code, struct sigcontext

signo , code
, a scp !
.
UNIX System V
. SA_SIGINFO,
sig ,
, !
, siginfo_t, !
,

.
siginfo_t <siginfo.h> !
:
int
int
int

si_errno
si_code

, ,
, , ioctl(2),

www.books-shop.com

si_signo . si_code !
: ,
, siginfo_t
:
pid_t si_pid
uid t si uid


UID

, ; si_code
, .
si_code ,
si_signo, . 2.19
2.19. si_code

si code

si_signo
SIGILL



(opcode)
ILL_ILLOPN

ILL

ILLTRP

(trap)

ILL

PRVOPC

SIGFPE


FPE INTDIV

FPE_INTOVF

FPE_FLTDIV

FPE_FLTOVF
%

FPE FLTUND

(underflow)
FPE FLTRES
%

FPE FLTINV
%

FPE_FLTSUB

%RRNVVKRS

piracy@books-shop.com

2.

/70

UNIX

2.19 ()

si signo
SIGSEGV

si code

SEGV MAPPER
SEGV ACCERR

SIGBUS


BUS ADRALN
BUS ADRERR
BUS OBJERR

SIGTRAP

SIGCHLD

TRAP

TRAP TRACE
%


CLD_EXITED

CLD KILLED
""
CLD DUMPED

CLD TRAPPED

CLD STOPPED

CLD CONTINUED

SIGPOLL


POLL IN

POLL OUT

POLL_MSG

POLL ERR

POLL_PRI

POLL HUP

www.books-shop.com

171

, !

(. 2.20).
2.20. siginfo_t

si signo

si addr

si addr

int

si pid
si status

long

si band


(
STREAMS)

SIGILL
SIGFPE
SIGSEGV
SIGBUS
SIGCHLD

SIGPOLL

!

tinclude <signal.h>
int
how,

*set,

how,
:

%
set


set
set NULL, how . !
oset NULL, , , !
.

!
, :
<signal.h>
int

, , , !
set.

, !
set, !
,
, ! .

www.books-shop.com

2.

UNIX

ttinclude <signal.h>
int

sigset_t

, ,

.
!,
.
,
, BSD UNIX
!

System V
!
.
, !

. !
BSD UNIX. ""
, ,
.
ttinclude <signal.h>
ttinclude
ttinclude <sys/stat.h>
ttinclude <fcntl.h>
ttinclude <unistd.h>
/* ""
*/
void ( * m y s i g n a l (int signo, void ( * h n d l r )
{
struct sigaction
act, oact;
/*
=

(int)

= 0;
if (signo != SIGALRM)
lags |=
/*
< 0)

}
/*
static void
signo)
{
/*
(SIGINT,
*/
printf ( "

www.books-shop.com

mysignal (SIGUSR2,

, , !
! .


,
fork(2) . !

(process group ID).
, !
. , !
, ,
. !
, .
!
, . , kill(2)
, !
.


.
, , (session), !

.
UNIX , ,
, !
. , " " !
, , !
.
!
, !
. : getpgrp(2)
ttinclude
ttinclude
pid_t

www.books-shop.com

2.

UNIX

pid,
,
.
, , !
, .
setpgid(2) !
.
ttinclude <unistd.h>
int

pid,

pid_t

pid
pgid.
( ). !
,
(2),
.
, !
pgid, (group leader) !
. , !
. ,
, .

ttinclude
#include
pid_t g e t s i d ( p i d _ t

, pid ,
, , getsid(2).
, , !
.

#include
pid_t

, !
! . !
.
, ,
.
, (controlling
terminal), , , !

www.books-shop.com

. !
/ ,
,
, .
. !
( !
shell) ,
( , !
). shell
!
, SIGHUP
. ,


, !
, .
(foregroud group),
(background
SIGINT SIGQUIT,
, . !

, , SIGSTP,
SIGTTIN
:
$ find / name
$ cat | sort

&



, , cat(l)
sort(l), .

,
.
,
,
. !

,

"" ,

,
!
. !
!
.


(job control). !
, shell.

www.books-shop.com

2.
$ ps !efj

UNIX

| egrep

2436 2407
2431 2407
andy 2407 2405
andy 2435 2407

2435
2431
2407
2435

SID

2407 1 15:51:30
2407 0 15:51:25
2407 0 15:31:09
2407 0 15:51:30

TTY

ttyOl
ttyOl

TIME
0:00
0:00
0:00
0:00

CMD
sort
find / name foo
sh

cat

(sh, find, cat sort) !


, ttyOl.

, (2435) !
(2407).
find(l), !
(2431). ,

, a
.
ps(l) , ,
, , !
cat(l)
. , !,
cat(l) ,
ttyOl. !,
<Del> (
SIGINT. !
( !
), , , SIGINT.
.
, !
. !
.

. 2.13. ,

www.books-shop.com

,
, shell.
!
S I G I N T
(
<Del> <Ctrl>+<C>)
shell .

UNIX . , !
.
"" , ,
. ., !
. , , !
, ,
. !

ttinclude
int
int

resource, struct rlimit


resource, const struct rlimit

resource ,
. rlimit
:

, , (soft) (hard) !
. !
, .
,
64, 1024.

. !
!
.
. !
!
( ).
,
. !
rlim_max RLIM_INFINITY. !
(, ) !
.

. 2.21.

www.books-shop.com

2. UNIX

178

2.21. ( resource)

%
core, %

. %
0, core
.
%
%
.

core %
%
%
.

SIGXCPU.

%
%
, . . % brk(2)
%.
FSIZE

%
,
.
0,
.



SIGXFSZ. %
%
,
%
EFBIG.

RLIMIT NOFILE

,
%
.

EMFILE.

RLIMIT STACK


%
.
SIGSEGV. %
%
%

%


.
%
brk(2)

. (
ENOMEM.
System V.)

RLIMIT NPROC

, %
.
(
BSD UNIX.)

www.books-shop.com


2.21 ()

R L I M I T MEMLOCK

%
%
(RSS Resident Set
Size).
%
%
, %
. ( %
BSD UNIX.)

%
, %
, %
RSS.

% %
( mlock(2) %
) , EAGAIN.

%
mlock(2). ( %
BSD UNIX.)

, !
:



void
resource, char *rname)
{
struct rlimit

if

==

else
printf (

if

==
printf

else
}

STACK, "RLIMIT

%RRNVVKRS

piracy@books-shop.com

2.

UNIX

/* BSD */

RLIMIT_NPROC

/* BSD */
ttifdef

/* BSD */
ttifdef RLIMIT_MEMLOCK
)
#endif
/* System V */

#endif
}

Solaris 2.5
:
$
infinite
infinite
2147479552
infinite
64
8388608
infinite

infinite
infinite
2147479552
infinite
1024
2147479552
infinite


!
, !

UNIX. ,
,
. !

UNIX. !
!
.

.
,

www.books-shop.com


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


.
!
,
,
!
.

" ", ,
.
, !
, :
1. , !
/
. , !
,
.
2. ( ),
/.
,
, , . !
, , "!
" UNIX.
3. !
. , !
(SIGINT
,
.
4. !
syslog(3),
.
5. .
, , , !
, . !
, !
.
!:
<stdio.h>
<syslog.h>
ttinclude <signal.h>

www.books-shop.com

2. UNIX

argc, char * * a r g v )
{
fd;

struct rlimit
/* init,
. ,
/ :
SIGTTOU, SIGTTIN,
if
!= 1)
{
signal (SIGTSTP, SIG_IGN)
/* ,


, .
, 
, .

. . PID , ,
,

, 
.

.
shell ,
, , 
. , 
,
shell
if
!=0)
/*
/*
,

}
/* .
.

for (fd = 0; fd <

fd++)


UNIX System V. BSD U N I X

, ,

TIOCNOTTY .

www.books-shop.com






PID ,


" " (.
.*/
",
|
"
,

!
.
syslog(3),
syslogd(lM), !
, , !

.

:
void

<syslog.h>
(int priority, char *logstring, /*

logstring , !
p r i o r i t y . :
LOG_EMERG

"" . %
.
,
, , %
.
, , %
.

LOG_ERR

.
.

LOG_NOTICE

, ,
.
, , ,
.
,
.

www.books-shop.com

2.

UNIX

!
, !
.
l o g s t r i n g , ,


!
, errno.
.

.
:
void

int logopt,

ident . !
logopt , :
LOG_PID

LOG_CONS

%
.

ident, , %
fork(2).
%
.

, f a c i l i t y :
LOG_KERN

LOG_CRON

, .
,
( ).
, %
.
, .
, %
USENET.
,

void closelog


, !
.
,
.
:
,

www.books-shop.com


,
(2).
ttinclude <sys/wait.h>
extern char ** environ;
#define
80

#define CD
ttdefine ECHO 2
EXEC 3
define PROGRAM

1000

/*, ,
, ,

,
/ path arguments.

,
int
char
char
main
{
int command;
int
char
char
while (1)
{
/*
write (1,
2)
/*
cmdsize = read(0,
=
command =

{
/* ,
(CD) :

break;

(1, args[0],
break;
args,
write (2, "shell: cannot execute",

21)
break;

www.books-shop.com

2, UNIX

/* , ,

=
if (pid < 0}
write(2,

" s h e l l : cannot f o r k " ,

else if ( p i d == 0)
{
args,
write
" s h e l l : cannot e x e c u t e " ,
}
else

/*0
break;

}
}
}

,

. , !
,
. shell !
, execve(2) !
.
,
.

UNIX .
UNIX ,
, ! !
. !

.
, ,
. , !
UNIX !
, U N I X ,
.

www.books-shop.com

UNIX
. !
, , , !
, , !
/ !
.
!
.
(run levels) , !
.
, , !
UNIX, , FTP, !
(news) !
.
:
, , !
UNIX , !
!
.
UNIX
( ) .
, "", !
!
. !
, . .
!
, !
!
UNIX
. U N I X
,

.

www.books-shop.com

3.

,
( ,
). "", !
"" "" .
,
, , ,
.
.
!
,
. UNIX


UNIX System V BSD.


, UNIX !
, ,
, , ,
, .
. 3.1 ,
.

, , !
/. UNIX !
, !

.
UNIX
, PDP!7 !
. , PDP!7 !
, fork(2). UNIX !
(2), !
. !

,
, !
( ) ,
. 1972 UNIX
, . . !
/ , !
, "" /

www.books-shop.com

).
, UNIX 1973 .
.

. 3.1. UNIX


(kernel mode) (user mode).
, !
.
. !
, , !
, .
, , !
.
.
,
!
. , , , !
,
!
.
:
. !

%RRNVVKRS

piracy@books-shop.com

3.
, , , ,
.
, , !
. !
, , , !
. ., , !
. ,
.




user, , ,
<sys/proc.h>
!
UNIX. . 3.1

SCO UNIX, !
, , .

char

(, ,
. .)

, %

char

unsigned int
u n s i g n e d short
u n s i g n e d short

p suid

int

short
short

short
sigset t
int

UID


( %
)
(PID)

p_pgrp

unsigned
time t

p size
p

caddr t

LDT

s t r u c t pregion

*p_region

short

unsigned int

[]

,
u%area

www.books-shop.com



!
, ,
, ,
. !
, ,
, .

, ,
, . !

curproc. !
,
, curproc, !

.
user,
block,
,
(. .
).
curproc, user
(, )
. . 3.2
UNIX.
u!area ,
. ,
, ,
, !
, . ,

, u!area .
. 3.2, u!area !
, (kernel stack). !
,
.


.

. . 3.3 !
, !
.

www.books-shop.com

3.

. 3.2.
1. . !
.
2. . !

.

www.books-shop.com


3. , ,
(
!
, !
.
4. (asleep),
, !
/.
5. , !

.
6. fork(2)
: , !
.
7. exit(2)
(zombie, defunct). , !
,
, .
.

. 3.3.
,
, .

www.books-shop.com

3.

6, !

fork(2).
, " " !

3 ,
. !
, 1 .

, , !
.
.
!
. , !
sleep () (4).
, !
. !
, " ", !
wakeup

, !
"
!
(context switch), !
, , , .
, , !
, !
, .

. ,
!
.
,
,
.
, , !
, !
. !
: ,
, . !
, !
, . ,

, !
.
UNIX
, !
!

www.books-shop.com


.
"" SIGSTOP, S I G T T I N
S I G T T O U . ,
,

, !
, !
"". ,
" ". !
SIGCONT, !
"" " ",
, , !
"".
SVR4.
, exit(2)
.
. ,
, ,
"". !
, !


, .


!
. , ,
(Random Access Memory, RAM)
.
, ,
, .
, , , .
!
, UNIX. ,
, !
, ,
.

.

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

. !
"" .

www.books-shop.com

3.

UNIX

. !

(Memory
Management Unit, MMU) !
, .
!
. , ,
!
.
( , , !
), , , !
.
!
.
!
,
, UNIX.
, !
:
,
.

.
!
.
.
!
.

. , ,
, .
UNIX !
. . ,
. " ",
:
,
; !
/;
7% !
.
.

www.books-shop.com



, , !
. UNIX
64 ,
, !
, .

, ,
. !
, .

. , !
!
, , , ,
.
:
!, , !
, !
, , !
. !
, ,
, !
. !
.
!, !
!
. !
.
!,
.
,
. ,
1 , 8
,
80 !
!
. , , !
. !
!
.
, !
.

www.books-shop.com

198

3.

. !, !
!
. !,

. !
( )
"" . !

.
, !
. !
!
(

. !
.
, , !
!
.

.
. 3.4 !
. ,
, !
, , .

,
.

. 3.4.

www.books-shop.com

199

!

, ,
. ,
,
,
. !
, ,
(page fault), !
,
, !
!
. ,
.
(
) !
. !
,
SCO UNIX
Intel. , UNIX, !
,
, !
, .

Intel
, . !

, !
, . , !
, !
. !
:
. (,
INDEX) ,
, , .
!
, !
,
. !
. , !
, .

, !
.

%RRNVVKRS

piracy@books-shop.com

200

3.

!
(Local Descriptor Table LDT) !
(Global Descriptor Table GDT).
, LDT !
, GDT !
(, ).
LDT, GDT
. , !
, ,
. 3.5.
1

INDEX

TI

RPL

. 3.5.

0, GDT,
LDT. RPL !
. ,
, , ,
, ,
SIGSEGV.
LDT GDT . !
, , !
, , !
!
, , , ,
, . , , !
.
(, , ) :

32% . %
32%
.
.
, %
. %
, %
, ,
. , ,

(, ), %
%
.

www.books-shop.com

, Descriptor Privilege Level (DPL), %


%
RPL %
. %
,
, . . RPL DPL.
% %

. ,

, %
, %
.
UNIX ,
, %

.

.
. , %
, %
.

,
, . ,
.
,
.

. !
!
. ,
, , (. 3.6).

. 3.6.

www.books-shop.com

202

3.

,
,
. ,
,


.
, ,
3 , . . !
1 , . !

" ".

, ,
,
(, !
). !
,
,
!
. ,
, ,
, ,
.
. !
(4 Intel)
, . !
Intel 4 .
, !
,
. ,

!
. ,
, . !
,
,
. , !
,


, !
. , !
.

www.books-shop.com

203

,
!
,
. !
,
. 3.7.

. 3.7.
, 22 31 ,
(Page Directory Entry, PDE). ,
, 1024 !
(page table). , !
. , 12 21 , !

(Page Table Entry, ).


4 , 1024
. , .
, , !
12 . , !

= 4
.
. 3.7 , !
.
PDE
( 10 ) .
. ,

www.books-shop.com

3.

, , !
. !
, , 32! !

(. 3.2),
.
3.2.

. , %
(=0) , ,
, %
.

U/S

. U/S = 0,
() . ,
.
( ).



. ,
, . ,
,
,
, , ,
.
. !
. 3.8.
(CR3 Intel)
. SCO UNIX ,
, !
CR3 .
( ) , !
, 1 , !
, .
256 .

,
, ,
Intel, !
.
, . ,
,

, .

www.books-shop.com

205

0x00000000

. 3.8.
, , !
, !
768 . 3
.
, !
(),

,
, , .
. 3.9
!
COFF ELF. , !
!
3 .
!
. !

, , !

.
, .

www.books-shop.com

3.

206

,
,
.
COFF

ELF

. 3.9.


, U N I X !
,
.
!
.
,
.
.
, :
; !
( Intel
CR3) ( , ,

; !

); .

www.books-shop.com

207


.
.
.

.
!
, !
.
!
UNIX,
SCO UNIX.

SCO UNIX
, (region). !
, !
,
.
, , ,
, . !

.
. !

!
.
,
,
( !
).
,
. !
. !
region.
!
,
pregion (per process region), ,
. pregion !

region pregion . 3.10.

www.books-shop.com

3.

208


. 3.10. SCO UNIX
p_next, pregion
, p_reg,
region, pregion
,
. . p_type . !
:

UNUSED

TEXT

DATA

STACK

SHMEM

www.books-shop.com

209
()

PT_LIBDAT
PT_SHFIL

,
.

region, . , !
.
,
r_nvalid (.
" ").
, r_refcnt .

,
(, ,

inode ).
!

!
pregion
.
t crash
=
> pregion 101
SLOT
PREGG
101
0
1
2
3
4

namelist = /unix, outfile = stdout

12
22
23
145
187

REGVA
REGVA
0x700000
0x701000
0x80001000
0x80031000

TYPE
TYPE
text
data
stack

FLAGS
rdonly

rdonly
pr



: ,

.
!
,
pregion region. ,
!
p_reg pregion,
, . REGVA
.

, 4
,
region .

%RRNVVKRS

piracy@books-shop.com

3.
!
. , !
:
>region 12 22 23
SLOT

PGSZ VALID

12
22
23

1
3
2

1
1
1

NONE

SOFF

KEF

11

1
0
1

0
0

0
0

1
1

0
0
0

NSW

BACK

5
23
24

15
0
238
0 135

TYPE

FLAGS

154 stxt done


154 priv done
priv stack

PGSZ , VALID
, . !
, ,
, !
, . , !
INOX inode,
, .
:
154
INODE TABLE
SLOT
154

SIZE =

472

FS
1,42

1562

RCNT

LINK

123

56

SIZE

MODE

8972

755

FLAGS
0

R130

tx

, !
(MAJ/MIN), inode INUMB.
1562.

, :
$ ncheck

1562

1562


UNIX PDP!11 16!
64 . !

,
.
(overlay),
, . !
, !
. , !

, , !
.

, !

www.books-shop.com

211

, !
. !
.
.
!
, . !
, !
, !
. ,
, .

UNIX


32! !

www.books-shop.com

212

3.

4
. UNIX,
,

80! UNIX
, !
.
,
, !
, .
,

. , !

(MMU ) !
!
. .
!
, !
.
, !
.
, !
.
, !
, ,
. , !
!
, !
(. 3.12).
,
, :
1. , . . !
(fetch policy).
2. , . .
(placement policy).
, !
, !
( ), . .
(replacement policy).
,
!
. !

www.books-shop.com

213

: .
!
, ,
. ,
!
. UNIX !
.

,
, .
1

. 3.12. ,
,
!
,
. !
,
.
!
, !
.
()
.
, "" !
. ,

www.books-shop.com

214

3.


, . 3.13.

. 3.13.
1. !
. , !
, !
. !
.
2. ,
.
, ,
, , ,
, !
( !
) ,
. !

www.books-shop.com


, ,
.
3. , !
.
,
.
,
, , , , !

,

( ) ,
.
4.
, . !
. !
, !
.
, !
, .
, ,
. !
, !
.
. ,
,
.
UNIX . , SCO
UNIX p f d a t
. UNIX
!
.

:
!
, 32! !
4 .
, . . !
.
!
, . . !
.

,
.

www.books-shop.com

216

3.


, , !

.
, !
, . UNIX !
, , !
, !
. .
, , !
(time quantum time slice).
, , !
(
) .
UNIX , ,
. , !

. !
:
.
, , !
.
!
, ,
.
, .
100 200
.
. ,
.

. !
, !
, , , !
. , , !

.

. UNIX !
,
,
,
, . . !
.

www.books-shop.com

217

!
.
, !
, !
.
, ,
,
. .
,
" ", !
.
!
UNIX!. !
,
!
, ,

(alarm).

, !

.
(CPU tick, clock tick). ,
, UNIX
10 ,
.
H Z , !
<param.h>. , 10
HZ 100.
!
.
, . !
,
. ,
. , !
:

, ,




www.books-shop.com

3.

( )



(alarm)
, !

. !
(major tick), !

,
.
. !
,
4 , a SVR4


.

,
. , SVR4 !
:
int co_ID =

arg, long

f n
, ,
arg,
d e l t a .
f n
,
!
( ),
.
, !
:

, !
.
TCP,
!
,
,
, .
, !
,
!

www.books-shop.com


.
!
. !

.
, !
UNIX. !
!
,
,
. ,

SCO UNIX , !
. !

.
.
0, !
. . 3.14 .

. 3.14.

!
.
(real!time), (profiling)
(virtual time).
timer,


. itimer , !
.

%RRNVVKRS

piracy@books-shop.com

220

3.

:
ITIMER_REAL

ITIMER_PROF

.
,


.
,

.
,

BSD UNIX !
settimer(2), !

,
. ,
,
. System V


. UNIX SVR4


.
BSD,
!
, BSD UNIX

.
, ,
. !
. , ,
! , .
SIGALRM.
,
.
, ,
.

.
!
,
.
,
.
.

System V, SCO UNIX,


.

www.books-shop.com


, ,
, . !
.

UNIX , !
, . !
, , ,
.
:
. ,
, , , !
.
.

user.
, !
.
.
:

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

www.books-shop.com

3.

, ,
.
,
.
,
:
1. , !
.
2. .
!
.
4. .

. !

()

!
,
. !

,
, !
.
, , !
.


UNIX
. !
, !
,
, !
.
, , !

. !
,
.
UNIX . !
.
!
,
.

www.books-shop.com


,
( ),
"" .
U N I X ""

, , ( !
) ,
, !
, . !
"
! .

.

.
:

,
, nice number ( nice), !
.
0 ( )
127 ( ). ,
,
, .


(!
).
,

, !
,
, ,

!
, .
. 3.3
UNIX
SCO UNIX
5.0). ,
BSD UNIX
.


U N I X .

.

.
SCO U N I X ,
!

www.books-shop.com

224

3.

3.3.

4.3BSD UNIX
% 0
(/ )
10

20

30



% 40

SCO UNIX
95
88
81
80
75
74
73
66

, !
.
, !
,
. , ,
, , , !
.

, !
. !
, , , .


: nice number

p_priuser

a*p_nice


. !

.

nice . ,
nice
!
1. ,
_ .
, a p_nice nice (nice number).

www.books-shop.com

225

.
, ,
.
, !
( 65), !

!
.
, UNIX SVR3, :
p_cpu


. ,
!


_.
!
, (. . nice
number) "" .
4.3BSD UNIX

load ,
,
. !
SVR3, !
_ !
.
!
, . .
, !
. !
!
(). , !
,
, , , (
). (, !
) !
. , !
,
, ,
.

www.books-shop.com

3.

, . , SCO UNIX !
127 . BSD UNIX
32 , , !

. .
, . .
, (round
!
.
, , !
, . ,
, ,
,
.


, UNIX
. !
,

!
, ,
shell
.
,
.
!
; .
UNIX
() , . !

, !
.

.

:
PID,
.
Round robin
,
, .

.

!

.

www.books-shop.com

.

, !
, ,
.
.

.
, !
, .
. 3.4.
3.4,

% %

(text)
(data)

,
,
(copy%on%write)

%
UID
GID
%
EUID
%
EGID
(PID)
ID
ID
(PPID)
nice number
%

(,

(,

www.books-shop.com

3.

228


3.4 ()

, %

FD_CLOEXEC (,

, %

FD_CLOEXEC (,


.


PID.

(

" ").
, .

!
.
, !
.
, !
.

fork(2) .

fork(2) PID .

.

fork(2) !
. ,
, (2)
, !
.
, . .
, .

www.books-shop.com

229

. ,
UNIX System V, " "
COW). , !

, , !
, . !
,
. !
,
, , .
,
, . ,
,
.
(2) ,
, COW,
(. . ), COW
.
BSD UNIX. !
vfork(2). !
, (2) !
. vfork(2) !

, . !
, (2)
exit(2), !
. vfork(2) !
, . . ,
. !
,
. vfork(2) !
,
.
!
. pregion ,
,
region, . , !
, region !
( )
. . 3.15
. ,
,
, , !
COW. ,
!

%RRNVVKRS

piracy@books-shop.com

230

3,

! , !
.

. 3.15.



, , !
,
.

,
. (2) !
.
UNIX
.
" !
" 2 COFF
ELF. , !
!
.

www.books-shop.com


, (2)
:
.
,
. .
, !
. (2) ,
1. ,

(2)
,

. (. .
)
, (2) !

!
XPG4), .
SUID SGID, (2)


(2) !
, !
.
.

. vfork(2),
.
!
, . , !
, ! ,
. !

.

,
, ,
.

.
,
. !
.

, EUID EGID ,

GID .

www.books-shop.com

232

3.

. ,
.
, , !
( ELF
INTERP)
. !
!
.
.
, , !
, .
. 3.16.

. 3.16. : )
) ; ) %
; ) %

www.books-shop.com

233


, !
, !
. UNIX !
. !

. , !
.
, , , ,
,
.
!
. !
(,
/ !
) ,
, .
, , , ,
. ,
, !
, , u!area. ,
,
.
, , !
, , !
. ,
, !
, !
( ).
!
.
, !
!
. , !
, ,

.
. , Intel !
(gate). : (trap
gate) (call gate).
,
.

www.books-shop.com

234

3.

,
, . ,
.



.
, .
!
/ , () , !

.

, .
,
. !
. !
, .
, , , !
, , , !
, .
, !
. !
!
, .
.
, , !
, !
.
.
,
. , !
. , !
"" " ", !
. !
.
, "" , !
.
!, . !
, !
, . , !
, !

www.books-shop.com

235

. ,
, , .
, !
.
,
.

,
,
.
. , !
, ,
.
:
.
!, , ,
. , , ,
. , , !
, ,
, .
"" " " !
. ,
, .
,
,
.
, !
.
, !
, ""
!
.
" ".


exit


!
,

. exit
:
.
.

www.books-shop.com

236

3.

"".


.
, u!area, !
, .

,
"" .
, !
.
, !
!
.

exit
!
"".

, !
.
,


!
.
, " "




,
,


!
"" !
. (, , ) !
, ,
.

!
, !
. !
. !
.

2. !
UNIX

www.books-shop.com

237

. !
, !
.
. !
. .
,
PID .
,
.
. ,
.
.
/dev/tty. !
.

, .
, , , !
/dev/tty, .


. !
. !
, , <Del>
<Ctrl>+<C> ,
, ,
.
, ,
2.
!
. !
, , !
.
, ,
. !


,
, , !
! . !
:

www.books-shop.com

238

3.


, , ,
.

, !
,
<Ctrl>+<C> <Ctrl>+<\>, !
,
.

!
!
kill(2). !

.

,
,
!
. , !
!
,
. !
,
.

!
!
, !
.

!
, , !
. .
.
, !
,
.


, !
, .
: !
( core ), ,
( ,
), !
.

www.books-shop.com

239

2,
, ,
, . !
, .
. ,
SIGSTOP !
,
, , . ,
!
, , , ,
( ) .
, ,
, , . !
!
, . . ,
, !
. !
, .
, !

,
, .
issig
:
1.
.
2. !
, .
3. ,
.

() , !
,

!
, .
, !
, !
.
,
. , , , !
(<Del> <Ctrl>+<C> ). !
(, !
),
, , !
, , !
, S I G I N T .

%RRNVVKRS

piracy@books-shop.com

240

3.

, !
.
, ,
(. . ),

.
, ,
. !
,
(, , ,
. .). , !
,
, , !
. ,
, .
!
, :
. !
, !
, /.
,
. ,
, , !
,
EINTR.
, !
( EINTR).
, ! !
,


, UNIX !
.
,
.

BSD UNIX . !
, !
,
EINTR. !
.

www.books-shop.com


.
UNIX , . .
.
:


.

:
. ,
!
.
.
, !
, , !
, . !
. !

!
.
.
. !
, , !
.
, !
, .
,

Communication,
,
UNIX, :


FIFO ( )
( )


IPC System V
UNIX IPC

BSD UNIX ( ).

www.books-shop.com

242

3.


,
,



! , . !
,
! !
.
.
.

!
shell:
cat m y f i l e

()
!
myfile, ()
, , .
! :
12 45 260

, myfile.
, . !
,
.


[0]

[1] . , !


fildes
,

[1] ?
. !
!
. f i l d e s
,
pipe(2), .

(DNS)
!

www.books-shop.com

243

, !
.

.
,

,
shell .

. 3.17. cat(1)
FIFO
FIFO First In First Out (!
). FIFO ,
,
. !
, FIFO , !
. FIFO !
. FIFO UNIX System V
BSD. FIFO System III,
.
FIFO UNIX
, . " !
UNIX" 1). FIFO
int

int mode, int

pathname ( FIFO),
mode , . . (. mode ),
dev FIFO .

www.books-shop.com

244

3.

FIFO shell:
name p

FIFO , !
.
FIFO :
1. ,
FIFO, ,
.
2. , FIFO,
. , ,
, !
, .
3. , !
0 . !
,

( FIFO !
O_NDELAY).
4. , FIFO, !
. , , !
, !
.
5. ,
FIFO,
.
. !
,
, SIGPIPE,
!
0
( !
SIGPIPE, !
).
!
, FIFO . , !
",

.
:
<sys/stat.h>
FIFO
#define
80
()
{

www.books-shop.com

245

char
/*
/* FIFO

if (
S_IFIFO I 0666, 0)<0){

}
/*
if ( (
= open(FIFO,
<

}
/*

while ( (n = read(readfd, buff,
if
buff, n) != n) {
printf
/*3 FIFO, FIFO
close

> 0)
}

exit (0)


FIFO

{
int writefd, n;
/*
if ( (writefd = open(FIFO,
<

/*
if
",

}
18)

!= 18)

}
/*3

/*
if

<

exit (0)


,
. FIFO,
. , !
,

www.books-shop.com

246

3.

.

(name space). !
, , !
. ,
FIFO . !
FIFO !
.
IPC, ,
, ,
. (key)
ftok(3C)
:

ftok (char

char

filename , !
. , !
!. ,
. ,
,

.
inode , !
, .

!
.
, ,
, .
IPC
(), () . !

( ,
), . . ! !
, (
).
3.5. IPC
IPC

FIFO

www.books-shop.com

247

3.5

IPC

IPC System V . !
!
get:
,

.
!1 . , get
, !
, !
(
, !
. get key
ipcflag.
. i p c f l a g
PERM, , !

(
)

,
, :
PERM (
)
0400
0200
0040
0020
0004
0002

r
%%%%%%%
%w

%
%
%
%

[
ipcflag

PERM

IPC

: (ENOENT)


PERM

PERM I IPC_CREAT
!

www.books-shop.com

248

3.


System V
UNIX. ,
,
IPC .
3 3 !
(. . !
). IPC.
, , , , !
.
IPC !
,
( !
, ).

, !
, . !
:
%
%
UID
cgid

(9 )

( ) , !
( !
, , ).
, IPC ,
. !
, !

semctl(2),


,

. , !
IPC "", !
. ,
.

,
UNIX System V, , !
!
. !
.
. , ,

www.books-shop.com

249

! . !
, , !
.
!
, :
(
)
( )
( , !
)
!
.

!

(msg_cbytes

), !


, !
(. 3.18). !
.


. 3.18.


#include
<sys/ipc.h>

%RRNVVKRS

piracy@books-shop.com

250

3.
#include
int

key_t key, int

!, !1 .
, !
. , :



:
<sys/ipc.h>
ttinclude <sys/msg.h>
int
int

const void
msgsz, int
msqid, void *msgp,
msgsz, long

int

, !

, !
, m s g s z . !
:
long

char

m s g t y p !
. msgtyp 0,

. msgtyp 0, !
. msgtyp 0,
,
msgtyp.
!
.
msgtype, !

.
, !
.
!
. , !
, , , 1.

www.books-shop.com

251

!
(, PID),
, !
.
msgrcv(2) !
(), 1, !
, . !
. 3.19.

. 3.19.

!
. !
FIFO
. , , !
, .
",

mesg.h
MAXBUFF
80
PERM


msgbuf,


struct our msgbuf {
mtype;

www.books-shop.com

252

3.

char
} Message;

:
ttinclude <sys/ipc.h>
ttinclude
ttinclude

{
(
Message
message;
key_t
key;
msgid, length,

if ( (key =

<

/*

if ( (msgid

PERM |

n =
,
if (n > 0) {
if

<
}


n) != n) {
}

}
else {

/*
exit

:
ttinclude
ttinclude <sys/ipc.h>
ttinclude
ttinclude "mesg.h"
main
{
(
Message
message;
key_t
int msgid, length;
/* ,
=

www.books-shop.com

253

if ( (key =

<

exit(l); }
,
if (

<

}

if ( (length =
",

if

<
}

(void *)
length, 0)

}

if

0) <

, , !
, . !
IPC, !
, FIFO .
, , !

.
. ,
(, ).
,
(, ).
,
. , 1 !
, 0 . !
. 0
.
1 . , !
, , . . !
0. !
1.
.

:

www.books-shop.com

254

3.

1. . !
,
.
2. !

(. . ) .
,
,
. !
!
(. !
).
,
.
System V :
, ,
, (!
, , . .).
!
, ( 0 1).
(
)
!
:
struct
struct
sem_nsems

!
sem:
ushort

ushort
ushort

semval
sempid


, !

, !

, !

, sem !
, ,
, ,

www.books-shop.com

255

, , .
,
.
( , !
)
ttinclude
#include <sys/ipc.h>
ttinclude <sys/sem.h>
int

key, int

int

!
,
1.
!
. , ,
, . s e m f l a g

(IPC_CREAT, IPC_EXCL).
!
, , !
. !

ttinclude
ttinclude
ttinclude
int s e m o p ( i n t

struct

size_t


, , !
semid. ,
nops. , !

(, )
.

struct sembuf {
short sem
short
short sem

/*

UNIX ,
semop:
1. semop ,
.

www.books-shop.com

256

3.

2. semop , ,
.
semop , ,

semop. semop !
.
,
( ),
), ,
( ).
!
!
. !
. , ,
,
. .
,
, , !
.
!
(. . 0 1).
0 , 1 !
(, . .), !
. , :
static struct
, , ,
, 1, 0

= {

/*

static struct sembuf sop unlock [1] = {


0,
0

, !
. , , (
) ( ) !
, (. . 1). !

"" ,
. , , , !
.

www.books-shop.com

257

1. . ,
( 1), !
( 0).
2. .
:
( 1)
!
0, . !
(. . sop_lock),
"" ,
.
: 1
!
,
.
.
static struct
, 1, 0,

= {
(1),

static struct sembuf sop_unlock [1] = {


, 1, 0

:
1);
:
(
), :
, 0,
. !
, ,
!
, !
, , . , !
2,
.
:
,

if ( (semid = semget. ( key,


< 0)

perms

IPC_CREAT I

www.books-shop.com

258

3.

if

(errno = EEXIST)

{
if (


=
key,
perms ) ) < 0)

}
else

,
else


!
(, FIFO,
) .
, , , , !
,
. !

, !
.
, ""
. ,
, !
. , !
, !
, .
!
:
1. , .
2. .

.
4. , !
.
5. !
, .
,

:
struct

shm_perm

, (.

)
shm_segsz

www.books-shop.com

ushort

259



<sys/ipc.h>
int

key,

size, int

, !1
. s i z e !
.
s h m f l a g

,
, !
. ( )
(attach)
ttinclude <sys/ipc.h>
ttinclude <sys/shm.h>
char

shmid, char

int

!
. !
:
1.
,
.
2. shmaddr , !
SHM RND
SHM RND ,

shmaddr .
SHM_RND , !
,
shmaddr SHMLBA.

. ,
!
s h m f l a g .

%RRNVVKRS

piracy@books-shop.com

260

3.

, !

, . 3.20.

3.20.
, (detach) !

<sys/ipc.h>
int

!
:
,
. ,

.
!
( ) .
. !
,
0, 1 .
, .

: ,
, (0),
. ,

www.books-shop.com



, !
.
!
, , !
. ,
mem_lock !
, !
",

ttdefine
80
ttdefine
PERM
0666
/*
typedef struct
int segment;
char
} Message;
/*0
static struct
[1 ] = {
1, 1, 0
,
static struct sembuf
= {
1, 1, 0
/*
static struct sembuf
= {
, , ,
0 }
/*0
static struct sembuf
, 1, 0

:
<sys/ipc.h>
<sys/sem.h>
<sys/shm.h>
"shmem.h"

{
Message
key_t
key;
int shmid, semid;
/*

,

www.books-shop.com

262

3.
if ( (key =
printf

<


if (
PERM |

(Message.) ,
< 0)

{

if ( (msgptr

(Message

0,

}
<
}




if (

2, PERM |
<

if

1) <

/*,
.
if
2) <
printf ( "

/*0
if

/*0
if

1) <

<

}

exit (0)

:
ttinclude
ttinclude <sys/ipc.h>
#include
#include

{
Message

*msgptr;

www.books-shop.com

key_t

key;

,
if (
/*
if (

semid;


(key
<

}

(shmid =
<
}

if (

= (Message *)

0,

<
}


if ( (semid =

2,

<
}

/*3
if (semop (semid,

, 2) <

1) <


if

/*3
",
/*0
if

1) <

/*,

if
2) <

if

<
}

/*
if
IPC_RMID, 0) <

if

(semid, 0,

< 0) {

www.books-shop.com

264

3.

BSD UNIX.
BSD UNIX !
:
!, !
, ,
.
, , !

UNIX. !
, , . .
(communication domain),
.
,
(),

(socket). !
,
.
UNIX, , !
.
,
, !
, .
!,
.
, !
, , (virtual
circuit) (datagram), !
.
, !
. :






, , ,
. , !
!
.

. , ,

www.books-shop.com

265

,
.
!
!
.
. !
, !
.
BSD UNIX :
(datagram socket),
, .
(stream socket), !
.
.
(packet socket), !
!
. !
.
(raw socket), !
.
, !
, !
. !
, .
System V
, .

,
!
. !
, ,
, . . 3.6 !
.
3.6. BSD UNIX

SOCK_SEQPACKET

www.books-shop.com

266

3.


!
, .

,
. ,
, !
.
, . . !
, .

:

int

domain, int type,

domain , type
, a protocol ( , . .
0). !
, ,
.

(protocol family), . !
domain :

UNIX. .
.
Internet (TCP/IP).
.
Xerox NS.

!
( ), !
AF ( address family ).
PF (protocol family)
PF UNIX, PF
. .

BSD

, , socket(2) ,
. UNIX System V !
, BSD
( STREAMS). !
, 3 . , !
BSD UNIX,
2

www.books-shop.com

267

,
. 3.7
UNIX,
, TCP/IP,
.
3.7.
:

AF UNIX


SOCK STREAM

SOCK

SOCK SEQPACKET

SOCK RAW

!
( ).
AF_INET :

SOCK_STREAM

(TCP)
(UDP)
(IP)

TCP/IP
6.
. !
!
. !

, :
1.
2.
3.
4.
5.
, ( ),
, .

.

www.books-shop.com

268

3.


, !
!
. ,
, !
, !
. !
,
.
!

. 3.21, , !
. 3.22.

. 3.21. (
)

www.books-shop.com

269

. 3.22. , (
)
, !
(binding) ,
, . !

int bind(int sockfd, struct sockaddr *localaddr, int


s o c k f d , !
;
, !
; addrlen . ,
, !
(
): .
, !
, .
( <sys/socket.h>):

%RRNVVKRS

piracy@books-shop.com

270

3.
struct

char

sa_family ( !
), a
. , !
.
, UNIX !
(
struct sockaddr_un {
short
char

/*

*/


,
!
. UNIX !
.
,
,
, . Internet (!
TCP/IP)
( <netinet/in.h>):
struct
short

{
/* ==AF_INET */

struct in_addr
char

(IP!) 6.
, 32! !
sin_addr, () 16!
sin_port.
. 3.23 .
, ,
, . !

1. . !
, "" . !
, .
2. !
!

www.books-shop.com

.
. UNIX
. !
, ,
.
!
, .
3.
, !
.
UNIX

Internet

un

sockaddr in

AF_UNIX
port
IP%

2
1s
2
)

10

He

86

. 3.23.
!

!
!
.
:
ttinclude
ttinclude
int

sockfd, struct sockaddr *servaddr, int

, !
, !
.

www.books-shop.com

272

3.


sockfd, !
. !
servaddr, , a addrlen
.

,
.
,
(),

!
.
!
, !
.
listen(2) , !
. :

int

(int sockfd, int

s o c k f d ,
. ,
. backlog
,
!

int

sockfd, struct sockaddr


int

accept(2) !
, sockfd,

UNIX (AF_UNIX). !
, . , TCP
( AF_INET) ,
, !, .

www.books-shop.com

273

. !
accept(2) !
clntaddr

, !
.
:
=

..

for ( ;

) {

newsockfd =
if
()
0) {
close (sockfd)

exit (0)
}
else

close (newsockfd)

, !
,
"" , !
!.
, accept(2)
. , n e w s o c k f d ,
accept(2),
: . !
, sockfd .
sockfd ""
.
,
read(2)

!
(
):
ftinclude
int send(int s, const char
int
int
int
s, const char
int len, int flags,
const struct sockaddr
int
int
s, char *buf, int len, int flags);
int recvfrom(int s, char
int len, int flags,
struct sockaddr
int

www.books-shop.com

274

3.

!
, recv(2)
. !
,
recv(2)
"" , . .
!
, . msg

toaddr,

.
!
,
buf ,
.

:


, (%
)



. !
,
!
, UNIX. , !
:
",
!
,
.
, UNIX !
. !

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

!
,
:

<sys/un.h>
MAXBUF 256
char

www.books-shop.com

275

struct
int
sockfd;
int
saddrlen, caddrlen,
n;
/* */
if
=
< 0} {

}
/* .
UNIX ,


, */

=
.
saddrlen =

if

(struct sockaddr
saddrlen) < 0)

{

exit

}
/*
*/
=
) {
caddrlen =
n =
buf, MAXBUF, 0,
(struct sockaddr
if ( n < 0) {
/* recvfrom
,



if
buf, n, 0,
(struct sockaddr
caddrlen) != n) {
}
}

!
. .
,
. !


,

" !
", .

www.books-shop.com

276

3.

:
ttinclude
<sys/un.h>
char
= ",
ttdefine
256
char
{
struct sockaddr_un
serv_addr,
int sockfd;
int saddrlen, caddrlen,
/* ,


*/

=
saddrlen =

if

+
*/
=

< 0) {

}
,



. . . ,


,

caddrlen =

if

(struct sockaddr
caddrlen) < 0)

}
/* , */
msglen =
if

msg, msglen, 0,
(struct sockaddr

saddrlen) != msglen)

www.books-shop.com

277

/*
if
=
{
printf

b u f , MAXBUF,

, NULL,

< 0)


/* */

exit (0)
}


UNIX,
.

FIFO

write

close

write

close

%
%

(
UNIX)

%
%

msgget

msgsnd

connect
%
% write

sendto
close




.
,
, ,
. !

www.books-shop.com

278

3.

. !
, :

, , !
, !
.
,
, , .
, !
(POSIX.

.
(
1 ) . !
, !
.
!

!. !
IPC :
17
17
17
17
17
17

53

08
13
18
Average

0.20
0.60
2.20
0.80
0.00
0.76

sema/s
20.00
12.20
10.40
25.10
15.60
16.66

UNIX, !
. !
, !
. , !
, !
,
.
,
, !
,
UNIX.
,
, !
. , !
, .

www.books-shop.com

UNIX ,

. (. . !
, ) ,
NFS (Network File System) !
.
CD!ROM, ,

UNIX, .
UNIX System V s5fs.
, , FFS, ,
UNIX. s5fs ,
. !
UNIX , !
. ,
UNIX AT&T .
!
UNIX System V (s5fs) BSD
(FFS), , ,
UNIX.
FFS, UNIX
. , !
UNIX !
.
!
,
"" .
,
Sun Microsystems.
SVR4, UNIX .
SCO
UNIX.

%RRNVVKRS

piracy@books-shop.com

280

4.


!
, !
!
.
, !

.

System V
!
, (partitions). !
. UNIX !
,
.
, ,
. , !
, !
. !
, .
s5fs
, .

. 4.1. s5fs

www.books-shop.com


, , , !
,


. !

. inode ilist.
inode (root) inode ,

. ilist !
. !
, s5fs ,
, .

. !
. inode, !
.
, !
. !
512 ,
SCO
UNIX 1 ( ).

,
(, !
).
, . !

().
:

(s_type)
, !
, ilist
(s_isize)
,
inode,
(

(512, 1024, 2048)


inode

www.books-shop.com

282

4.

inode
,
. ,
. inode
,
inode.

, !
0 inode.
,
, ,
. !
. !
,
. ,
. ., .

. ,
, !
.
. !
,
. , ,
.

, inode, , !
, . . . !
inode,
, inode.
:
, ;
, .
inode
in!core inode, .
inode (struct dinode) . 4.2. !
inode :
,
.
, . .

.
% %
.

www.books-shop.com


di_size

di_mtime
di_ctime
di

addr[13]

283

.
.
.
.
inode (
di_atime, di_mtime).
.

. 4.2. inode

: (IFREG
,
, IFBLK IFCHR
);
!

SGID sticky bit),


1.

www.books-shop.com

284

4.

,
. inode :

!

!
di_atime di_mtime. , di_ctime ,
, , , .

.
, inode !
,
!
,
,
.
13 . 10 !
. !
, .
, !
, .
, ,
,
.

,
.
( 10 1024
) ,
. , 266
(10 + 256x1024), . !
,
16777216 (256x256x256).
UNIX . ,
, lseek(2) !


,
.
s5fs , !
, , . !
, !
, , ,
.

(

www.books-shop.com

System V

285

.

.
. , ,
, .
inode
. ,
. !


, , ,
.
. , . . !
, (),
. !
.
s5fs , !
16 : 2
, 14 . !
inode, 65 535.
: 14
. . 4.3.
( )


(,
inode 0.
, !
. !
,
.
,
! .


. , "" !
. ,
!
, . ,
,
. , ,
,

!

, .

www.books-shop.com

4.

286

SCO UNIX , !

!

).

, ,

bin

News
mail


. 4.3. s5fs

www.books-shop.com

System V

287


s5fs .
!
.
!
. !
, !
. s5fs !
, .
!
.
, .
, ,
, . !
, !
!
, ,
. ,

.
. !

. !
/. , !
, UNIX SVR2 512 , SVR3
1024 .
, !

. .

,
. !
, . !
(
) ,
inode, ,
.
, !
inode,
.
, , (14 !
) inode

.

www.books-shop.com

288

4.


, 4.2BSD UNIX
Berkeley Fast File System, FSS.

BSD UNIX
4.3BSD UNIX !
, ,
. Berkeley Fast
File System (FFS).
FFS, s5fs,
.
,
.
s5fs, !
. !
,


!
. !
, .
!
(cylinder group).
!
. !
, , inode, !
!
(. 4.4).

. 4.4. FFS

www.books-shop.com

BSD UNIX

289

!


2 inode. !
inode ,
BSD UNIX , s5fs.
!
inode, , , !
inode .
, !
inode.
,
.
!
. , ,
, !

.
, !
!
. ,
.

. ,
!
. FFS 64
. ,
UNIX .
, !
, 60% .

. , !
. !
/,
. !
/ .
,
(0,5 ), !
, : !
.
!
, . , !
, !
, ,

%RRNVVKRS

piracy@books-shop.com

4.

290

, , . . 4.5

, .

. 4.5.


.
s5fs . !
inode !
, , ,
.
s5fs, FFS !
, . !
:
, !
, !
.
, , ,
.

.

www.books-shop.com

BSD UNIX
, !
.

,
. !
.
!
. , !

.
. , !
.
!
"" .
, , ,
, . .

,
. !
, ,
. ,
,
s5fs.
!
. ,
FSS
. !
.
, FSS !
10% .

FFS
( 255 ).
FFS ,
:

[]

inode (


,
. !
, d reclen !

www.books-shop.com

292

4.

. !
d_ino. !
FFS . 4.6.

. 4.6. FFS


, !
.
UNIX !
.
,
UNIX, DOS. !

www.books-shop.com

293

,
. !

(. 4.7).
UNIX ,
.

4.7.



, !
inode,
.
DOS,



, !
UNIX.
(
virtual inode ).

www.books-shop.com

4.

294

1984
Sun Microsystems !
, , NFS
(FFS). !
SVR4,
UNIX (,
SCO UNIX).
(,
) in!core inode, !

vnode ,
, . vnode !
, !
, , ,
.
vnode .
4.1. vnode

u short

lag

u short

v count

struct filock

filocks

struct vfs

struct

vfs

*v_vfsp

enum vtype

v_type

caddr t

v data

struct

op

vnode
vnode


, vnode

, %

vnode: , , %
, %
,
, %

vnode

vnode v_count,
.

,

,
vnode .
vnode (, , inode) !
.

( v f s ,
), ,

www.books-shop.com

295

,
,
"" vnode.

v_data ,
. ,
in!core inode.
vnode v_op. !
!
vnode. !
, !
!
,
. , !
, . 4.2.
4.2. vnode
()

close)
(

int
int

int

read) ( )

vnode. %
(),
vnode.
.
vnode.
, vnode.
, vnode.
.
vnode:
,
%, %, %
,
,
, %

,
,
vnode, .
vnode.
GID, %
.
,
vnode.
UNIX %
(, DOS).
%
vnode.
vnode.

vnode .

www.books-shop.com

4.

296

4.2 ()
int
int
int
int
int

_link) ()

int
int

readlink)
()

int

inactive)

vnode.
vnode .
.
, vnode.

, vnode
.
.

.
vnode, . . vnode
.

(vnode)
. 4.8.

. 4.8.


, !
.

www.books-shop.com

297

,
, , .
.

v f s , !
. v f s
, !
,
, ,
. !
. ,
!
.
. 4.3.
4.3. vfs
struct vfs

next

struct vfsops
struct

vnodecovered

int

vnode, %
.
: ,
SUID . .

int

vfs bsize

vfs data

,
%
.

!
. , s5fs,
, .
vfs_op , !
!
v f s .
. 4.4.
,
!
.
4.4.
mount)

int

.
%
.
.
%
(, %
).

www.books-shop.com

4.

298

4.4 ()

int

(*vfs
(*vfs

vnode .

int
int

int

()

%
, : , %

inode.


.
(fid file Iden%
tifier), %
. fid , , %
inode .
vnode
, fid.

UNIX
(File System Switch),
, !
. UNIX System V
,

, s5fs,
nfs.
vf ssw , . 4.5.
4.5.
char
int
struct vfsops
long

name
init) ()
*vsw vfsops
vsw flag


. 4.9.


, , (
), (,
) , !
. !
vnode,
(
()
() ), ,
!
.

. !

www.books-shop.com

299

, ,
. !
,
v f s ,
. 4.11.

. !
(root) , v f s
.

, . !
, v f s

.

. 4.9.

!
. !
. ,

, , !
NFS !
. !
, :
;
!
,
data v f s ;

%RRNVVKRS

piracy@books-shop.com

300

4.


,
.


. ,

!
.
, ,
,
(, NFS).
vnode !

,
(, SCO UNIX, !
)
vnode. ,
Sun Microsystems, vnode !
, .
, !
, .
. 4.10

.
!
.

vfs
!
. !
Solaris 2.5:
crash
=
=
= stdout
>
/ on /dev/dsk/cOt3dOsO read/write on Tue Feb 25 15:29:11 1997
/usr/local on /dev/dsk/cOtOdOsO read/write on Tue
25
1997
/tmp on swap read/write on Tue Feb 25
1997
/dev/fd on fd read/write/setuid on Tue Feb 25
1997
/proc on /proc read/write/setuid on Tue Feb 25 15:29:11 1997
on /dev/dsk/cOt6dO
on
Mar 25 15:29:43 1997
>
FSTYP BSZ
PDATA
FLAGS
ufs 8192
800018
0 f5b79b78
0
notr
ufs 8192
32,0
800000
f5c29adO f5c28c88
0
notr
4096
0,0
0
0
notr
fd 1024
158,0 2780000
f5c4f5d8

proc 1024
156,0 2700000
0
283920
hsfs 2048
f5f20698 f5b60d98
0
rd

www.books-shop.com

301

. 4.10.

www.books-shop.com

4.

302

(
vfs .
vnode
> vnode f5c29adO
VFSMNTED VFSP
2 f5c25c60 f0286570

VTYPE
d

RDEV VDATA
VFILOCKS

f5c29ac8
0

,
(VFSMNTED)
v f s , v _ f s p (VFSP)
.
> vfs f5c25c60
FSTYP BSZ
8192 32,0
> vfs f0286570
FSTYP BSZ MAJ/MIN
ufs 8192 32,24

PDATA
800000

f5c29adO

FLAGS
0

FSID VNCOVERED PDATA


BCOUNT FLAGS
800018
0
f5b79b78
0 notr

, inode ufs, !

(VDATA) :
> ui f5c29ac8
UFS INODE TABLE SIZE = 1671
SLOT MAJ/MIN
LINK

32,24

7552

SIZE

512

MODE

FLAGS

rf

www.books-shop.com


,
7552
,
>

303
ufs !

i 7552

7552


, ,
,
.
, !
. , , !
, ,
!

. 4.6 , !
.
4.6. ,
(2)
chgrp(2)

mkdir(2)
mknod(2)
link(2)


%
%






, !
, '/'. ,
, .
.
. '/', !
,
,
. , !
. !



, !

www.books-shop.com

304

4.

:
.
u_area:
struct
struct vnode


vnode

vnode, !

u_rdir.
, vnode !
vn_lookup

. !
vnode, .
vnode
.
(. . !
),



s_root

vnode. .

, , !


vnode (
VROOT
vn_lookup

vfs_vnodecovered, v f s !
. , !
.
, ,
, "" !
,
vn_readlink
!
. (. . !

vnode , !
u_rdir u!area.
, !
(,
). vnode
.


2, , !
, !

www.books-shop.com

305

. , !
,
, .
, !
,

,
!

(
, , .
.
,
.

. 4.12.
, , !
(file descriptor table). !
,

. 4.12 ,
.
, ,
(system
table),
, (, ,
. .), ( ),
vnode .
.
. 4.12,
,
vnode.

www.books-shop.com

306

4.


,
,

pipe(2). !
, !

,
,
. !
, user. . 4.7 !
user,
.
4.7. user,

, ,

(


,
(


!

.
UNIX !
, u!area. !
. , ,
64 ,
.
. , ,
, !

!
"" 2. , !
, Solaris 2.5,
, uf_entry,
. 4.7.
!

u!area !

www.books-shop.com

307

. , !
:
crash
=
= stdout
> proc #8591
PROC TABLE SIZE = 1498
SLOT ST
SID
NAME FLAGS
121 s 8591 8589 8591 8591 286 48 bash load
> user 121
PER PROCESS USER AREA FOR PROCESS 121
PROCESS
command: bash, psargs: bash
start: PO
24 18:11:31 1997
mem:
type: exec
of current directory: f5b95e40
OPEN FILES, POFILE FLAGS, AND THREAD REFCNT:
F Oxf62b6030, 0, 0
F Oxf62b6030, ,
F Oxf62b6030, ,
0022
RESOURCE LIMITS:
cpu time: unlimited/unlimited
file size: unlimited/unlimited
swap size: 2147479552/2147479552
stack size: 8388608/2147479552
size: unlimited/unlimited
file descriptors: 64/1024
address
unlimited/unlimited
SIGNAL DISPOSITION:


u _ o f i l e

, . !

.
!
vnode , , ,
. 4.12.
,
.
, !
, . !
:

www.books-shop.com

4.

308

f_flag

FREAD

. , O_RDONLY
.

( (2),
%
. ,
( FREAD),
, .

. ,
.

FAPPEND

. %
. , O_APPEND
.

FNONBLOCK,

. %
. ,

%
.

FSYNC

%
%
. , o_SYNC .

FDSYNC

%
.
,
.

FRSYNC

FCYNC FDSYNC %
.
, %
. %
%

f_of f set

. %
.

user !
(fd=0), (fd=l)
(fd=2). ,
. file :
> file Oxf62b6030

ADDRESS RCNT TYPE/ADDR


OFFSET
f62b6030 9 SPEC/f5e91clc
15834
> vnode f5e91clc
VCNT
VFSP
VTYPE
2
0
f5c6b2aO

FLAGS
read write
RDEV
24,26

VDATA

VFILOCKS
0

www.books-shop.com


( !
TYPE ),
(VDATA)
!



!
specfs,
.
. , !

, snode,

> snode f5e91c18


SNODE TABLE SIZE = 256
HASHSLOT
f5f992e8

f636b27c

NEXTR SIZE

COUNT

FLAGS
up ac

(REALVP) vnode
( ufs). !
.
> vnode f5f992e8
VFSP
2
0
f0286570
0
>
UFS INODE TABLE SIZE =
SLOT MAJ/MIN
32,24
317329 2
> !
i 317329

VTYPE

LINK
1

286

RDEV
24,26

VDATA
f5f992eO

SIZE
0

MODE
620

FLAGS
rf

317329

( !
),
.

UNIX
.
,

, U N I X
. !
,

. , ,
, ,

. !
%RRNVVKRS


.
piracy@books-shop.com

4.
. !
( )
( ).
, ,
, !
, .
(advisory lock).
, !
,
. !


lockf(3C).

!
2.
f l o c k , . !
. 4.8.
4.8. flock

short

: F_RDLCK
(read lock),
(write
lock),
.

short

l_whence .
, %
lseek(2) 2:
SEEK_CUR, SEEK_END.

of f_t

l_start

,
l_whence.

of f_t

l_len

. l_len %
, ,
.
, , %
GETLK.

l_type f l o c k ,
:
RDLCK)
,
, !
. , !
,
.
, !
:

www.books-shop.com

struct flock

lock;

lock
=
0;
SEEK_SET;
= 0;
. , ,

fcntl(fd,

record,
=
SETLKW,

UNIX
(mandatory lock),
.
. , SCO UNIX (SVR3)

, !
,
lockf(3C), . U N I X
SVR4
, ,
.

, !
. ,

! ,
.


,
.
,
, ,
, .
/, , U N I X !
!



(, NFS).
/
!
.

www.books-shop.com

312

4.

, /
, ,
. !
. !
, /
. !
/ , , ,
UNIX .
, !
, !
. !


/. !
. 4.13.

. 4.13.

www.books-shop.com

313


,
.
, buf,
, !
, .

/. !
, / !
.
/ .
buf . 4.9.
4.9. buf

b_f lags

av_f orw,

b_addr

. %
(,

%

) %

B_PHYS)
,

,


b_flags .
, !
. ,

.
,
"", !
. B_READ, B_WRITE,
B_ERROR !
. / !
.

(write!behind),
.
"",
!
. /
, !
. !

www.books-shop.com

4.

/ (,
, ). !
, !

.
/
. 4.14 / !
.
, !
!
, !
.

read(2)
!
. !
!
.
.
,
, .
, ,
buf .

(read!ahead),
,
!
(. 4.14, ). ,

!
/,
, , , , !
(. 4.14,
!
.
"" buf (. 4.14, ). !
, !
(.
).
,
, /, !
. !
,
.

95% 85%
.

www.books-shop.com

315

. 4.14.

www.books-shop.com

4.

.
(Least Recently Used, LRU). !
, , ,
.
, !
!
. ,
, / ! !
. !
, !
, .
, , ""
, ,
. , !
, ,
.
, !
/
. ,
, !
.
UNIX
:
!,

, "" .
, sync(2)
/, !
, ""
!,
(

!
.
, !
!
( UNIX ,



/,
.

/ ,
, !
. !

" ".

www.books-shop.com

317

"" , !

(. 4.14, ).
SVR4
SVR4 !
. !
.
, , , !
.


!
. ,
, . . !
, !
, ( !
).
,
. !
/ .
,

, !
, .
. !
,
. !
,
, , .


.
, !
, ( !!
inode

, .



. , SCO UNIX .

30 .
, !
"", bdflush

www.books-shop.com

4.
!
,
, !
. !
.
, !
, ,
. !
,
,
.
. !
:
1. ,
.
2. inode.
,

.
( ),
inode
1.
.
(). ,
, . . !
inode, di_nlinks 0. !

, inode, (.
).

. , , !
. , , ,
.
, !
. !
, 1
(. 4.15, ). , !
, !
, .
!
, .
, . .
!
/.
.

www.books-shop.com

319

,
,
.

. 4.15.

%RRNVVKRS

piracy@books-shop.com

320

4.


!
:
1. mode (
).
2. , ( !

, ( inode
).
4. inode ( !
).
5. !
inode .
6. (, !
).
7. "" ( inode, !
).
8. inode .
.

. 4.16.

www.books-shop.com


,
. !
!
, , :
fsck [options]

filesystem ,
.
!
.
() !
(). !
, . !


.

U N I X .

UNIX, . . ,
!
.
,
, , !
/,
.

www.books-shop.com

/
.
. !
(Transport
Layer Interface), 6. !
, !
. !
, ,
, !
.
, ,
( ), (
), / !
.
, !
, !
. !
!
, UNIX
. ,
,
, , . !
,
. !
/ UNIX.

STREAMS, !
UNIX System V. , !
,
. STREAMS
UNIX System V.

www.books-shop.com

323


U N I X !
. !
, !
.
UNIX . !
, , , !
,
.

!

"" .
!
. UNIX !
, , !
, .

, ,
,
:


. !
, , ,
. .
!
,
. !
, !
,


(). !
, ,
, ,
.
,
.

, ,

, !
.

www.books-shop.com

5.

324


(raw drivers)


!
, . , , !
, !
, .

,
!
, !
.

. 5.1 !
UNIX.

UNIX

,
, . !

www.books-shop.com

326

!
!
. !
. !
:

/dev/zero

.
, %
. , %
, ps(1), %
.
, %
. /dev/kmem %
.
.
"" . %
, 0 %
.
/dev/null
.
.
.


(major number) .
, ,
!
, ,
, (minor number). !
(, ,
, ""). !
.
,
, , !
, .

(
!
.
, , !
, , ,
. , !
.

www.books-shop.com

326

5.

. !
:

.
, !
. , !
, .
(
):
struct
int
int (*d_close)
int
int
int

}
struct
int
int
int
int
int
int
int
struct

()

}
open





open

dev (
.
dev.
,
.

. !

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

www.books-shop.com

327

,
(,
) .
!
, . ,

mm,

,

.
. 5.1 ,
, , ,
. !
UNIX. ,
,
,
xxwrite

.
5.1.

[
[

%
. %
%
%

. , %
%
%
, %
%
%
.

,

, . .

(
%
). %
.
,
%
.

www.books-shop.com

328

5,

5.1 ()

[
[


. %

, %
, %
ioctl(2).


, %
. %
%
%
,
xxread

.

.
%
,

, , %

.

%

.

%
,

%
, %
,
%

%
, %
.


, %
,
/%
.


,
.

www.books-shop.com

.
,
!
,
. !
,
,
.
, ,
:
.
UNIX, , .
/. / !
,
, , .
.
,
( ).
.
, !
ioctl(2).



. !
!
.
. 5.2 5.3
.
, UNIX
.
,
, ,
,
, .
,
. :
. ,
read(2), !
x x r e a d ( ) ,
. , .
!
. ,
, !

%RRNVVKRS

piracy@books-shop.com

330

5.

( ,
).
, ,
xxstrategy
.

. 5.2.
,
!
. , , !

www.books-shop.com

. 5.3.


:
(top half)
(bottom half).

www.books-shop.com

332

5.

, . . !

.
,
, !
(
(} ). !
/ .
. ,
,
, .

. , !

, u!area, !
, , !
.
. , ,
, !

"" . ,
,
, .
, xxhalt
xxpoll
xxintr
. xxhalt
!
, ,
, .


, . !
, , , " " !
. xxpoll
!
, xxintr

.
()

() !
. UNIX !
,
.
UNIX SVR4 i n i t

start


,

.

www.books-shop.com

333


4 . .
,
(,

s5fs), .

, ( in!core !
) .

vnode. vnode , !
. , vnode
, s5fs,
( , FSS)
!

s5f s_open

.
, U N I X ,

. , U N I X !
, !
, ufs.
, !
!
, ufs.
UNIX . !
ufs.
!
.
vnode ,
.
System V
, devfs
!
vnode
. !
, vnode, , !
, vnode
specfs.
,
,

SVR4 specfs, SCO


!



devfs.

www.books-shop.com

334

5.

, (

, !
specfs, !
.
. !
,
!

. !
ufs

, ,


.
!
, IFCHR, . .
.
s_open

,
specfs, ,

( special inode), ,
. ,
vnode,
specops,
. ,

s_open
vnode, ,
,
, (2)
, vnode !
specfs, vnode /dev/kmem. ,
/dev/kmem specfs.
vnode . 5.4.

. 5.4. /dev/kmem

www.books-shop.com

335

. , !
, , !
.

, , ,

.
specfs !
snode,
. , snode
(common snode),
. ( )
common snode,
. , ,
snode specfs
vnode, inode , !
, vnode.
snode
:
common snode, s_realvp, !
vnode ,
.
vnode inode snode
, .

, , ,
. vnode,
common snode. , !
, !
.
, !

. !
vnode .
. 5.5.

, ,

. ,
, !
, .


( ).
,

www.books-shop.com

5.

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

. 5.5.

www.books-shop.com

337

!
( ),
open
. ,
!
.
, !

, !
snode
!
specfs, .
, ,
!
, !
s_dev snode.
. !
,


snode ( vnode, !

!
vnode specfs, !
. ,
. . 5.6.

. 5.6.

Clone (.) .

www.books-shop.com

338

5.

, !
, (clone driver).
, "" ,
, . !
, . .
, . !
STREAMS,

, . , !
, :
$

!1

crwrw
crw
crwrwrw

1
1
1
1
1
1

root
root
root
root
root
root

sys
sys
sys
sys
sys

11,
11,
11,
11,
11,
11,

44
5
3
40
42
41

Oct 31 16:36
Oct 31 16: 36
Nov 3 1995
Nov 3 1995
Oct 31 16:36
Nov 3 1995

arp
ip
tcp

11
. , , tcp, To
, 42, !
tcp . !
, clopen() !
, . clopen() !
TCP
cdevswf[] clopen () !
xn() , tcpopen(), !
CLONEOPEN. t c p o p e n ( )
, !
(. . ) !


specfs. ,
TCP!
.



UNIX
.
: ,
,
.

www.books-shop.com

339

UNIX !
.
, !
!
.
, . .
,
UNIX .

UNIX !
. , ,
, (,
STREAMS).

. ,
,
, , !
, , !
.
.

:
.
, !
.
.

.
.
, , !
, , , !
, . !
,

Solaris 2.5, . 5.2.
5.2.
, %

, , %

%RRNVVKRS

piracy@books-shop.com

340

5.
5.2 ()

_inf

, %

struct

_inf
,

struct

, ,
,

Solaris 2.5 !
:
mod_remove ( 9 F )
mod
.


!
,
, ,
. !
. ,
!
, ,
4 8 .
, !
. !
.
,
. !
. !

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

.

www.books-shop.com

341

, /
:
.

.
: !
.

!
/ xxstrategy ( ) .
, ,
b u f , ,
. !
buf / !
. buf:
. (,
B_DONE)
B_PHYS)

, %




,

buf
. 5.7.
, vnode .
,
, . , !


,
. vnode ,
, .
, , ,
!
,
. , , !
, ,
.
. !

.

www.books-shop.com

342

5.

. 5.7. ()
! !
vnode, ,
vnode (
page SVR4, pfdat SVR3), / !
vnode.


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

www.books-shop.com

343

, !
/.
/, ,

, !
. !
specfs, , !

.
vnode , .
!
, , v_rdev vnode,
(

!
, !
, ,
!


!
, ,
, "", . !

,
.
!
/.

,
.
!
(
),
, .

, ,

, , !

STREAMS,

.


" STREAMS".

www.books-shop.com

344

5.

, , !
.
,
!
/. . 5.8
/ ,
( ),

( ).

. 5.8. %

%

,
.
!

www.books-shop.com

345

, ,
.
, !
, , , !
.
,
!
. ,
, !
, xxintr
!
xxwrite
!
, xxwrite
,
xxpoll
,
( !
).
, !
x x i n t r (), , ,
.
!
,

:
struct cblock
struct cblock

_ cblock.

, , cblock,

. cblock !
. ,
cblock . !
cblock . 5.9.

5.9.

64
clist

www.books-shop.com

346

5.


. 5.10.

. 5.10.
clist


! , !
!
, . !
UNIX

,
: / . !
UNIX !
, !

. , SCO UNIX !

/dev/tty02 . .

www.books-shop.com

347

, ,
. !
UNIX,
, . ,
,
(line dis!
cipline).
/:
1. . !
.
2. , .
!
, ,
( , , !
) , !
. ,
, .
,
. !
, .
!
( , !
) ,
. , ,
shell.

! . ,
, !
,
.
:
1. .
2. .
, .
4. , .
5. , ,
.
6. ,
, .
,

www.books-shop.com

349

5.

, .

,
.
, !
. , !
,
. !
.

xterm
X Window System.
,
, !
, !
. , !

, .
.
!
(slave). !

www.books-shop.com


,
,
. ,
!
,
, ,
, ,
. !
, !
, ,
shell.
,
,
.


.
( )
,

,

!
.


,
!
,
" ", !
, .

. !
, !
.
, login(l)
(login shell), !
. ,
,
. !
, , ,
"" ,
(, , . .)
.
.

.

%RRNVVKRS

piracy@books-shop.com

5.

350

STREAMS
/ STREAMS
" /" (Ritchie, D. .,

www.books-shop.com

STREAMS
"A Stream Input!Output System", AT&T Bell Laboratories Technical Journal,
Vol. 63, No. 8, Oct. 1984) 1984 . !
UNIX SVR3.
/ !
.
/,
,
!
.
( ) !
, .
. !
!
. !
/
, , !
UNIX.
!
/ !
. ,
.
, !
,
!
. , ! !
, ,
.
, ,
, !
/.
, !
.
!
( ) !
. , IP
( 3 OSI
!
: TCP UDP. IP
, !
(, Ethernet, Token Ring

OS1 ,
(ISO), 7 .
, TCP/IP SNA,
. 6.

www.books-shop.com

352

5.

).
/,
.
STREAMS .
, !
, ,
. STREAMS
,
, !
.
, , !

, .
STREAMS !
UNIX !
. STREAMS
,
UNIX SVR4.
STREAMS
STREAMS !

, STREAMS
,
, !
.
. 5.13 !
STREAMS.
, !
.
, , , . !
!
. , , !
, !
.
.
,

ioctl(2). !

( STREAMS) ,
, .

www.books-shop.com

STREAMS

353

poll(2),

, ,
. !
, ,
(read queue) (write queue).
!
.
(downstream), (upstream).
, . 5.13 2
1, . !
2 !
, !


.

. 5.13.
. ,
1

www.books-shop.com

354

5.

, , ,
. ,
!
, . !
!
.
STREAMS !
(push) .
.

, .
!
, !
. (pop) .
. 5.14 , !
,
TCP/IP. IP, TCP UDP !
, Ethernet Token Ring
!
.
TCP
Ethernet,

Token Ring.

. 5.14.

%

www.books-shop.com

STREAMS

355

STREAMS !
.
, .
,
,
!
,
!
.
,
. 5.14,
!
. !
UNIX.
STREAMS . 5.15.

.
%

%
STREAMS
TCP UDP ,
IP
!
,
.
STREAMS.

STREAMS !
.

www.books-shop.com

5.

356



, . . .

. !
, !
,
. . 5.16.

. 5.16. STREAMS
queue. !
queue :
q qinfo
q first, q last
q next

qinit,
.
,
.

.
().

www.books-shop.com

357

, queue !

.

, qinit. !
!
: xxput
xxclose
, !
, .

(*qi_putp)
(*qi_srvp)
(*qi_qopen)

, .

xxopen ,
.
(}
. xxput

, . xxput

(, , !
), !
.
()
.
xxput
.
(} , xxput ()
!
, .
,

.
.
qinit:
%
, , . .
queue.
,
.

STREAMS.
%
.

STREAMS . !
!
. !
. !

www.books-shop.com

5.

!
. ,

STREAMS.
:

msgb (message block)


(data block).
, !
.
msgb :
b_prev

%
%




, ( %
)
msgb

datab
:

,
. ,
db_base

db_type
db

!
, , .

!
.
STREAMS !
. .
, ( !
) !
.
,
.
,
,
,
,
. 5.18.

www.books-shop.com

STREAMS

359

5.17. STREAMS


. !
,
. , !
, STREAMS
,

%RRNVVKRS

piracy@books-shop.com

360

. 5.18.
!
TCP. TCP , . . !
, !
. , !
, .
, !
, ( IP),
.
, ,

www.books-shop.com

361

STREAMS

db_ref ,
, !
0.

0, .

,
.
:
. ,

!
!
.
STREAMS !

:
M_DATA

. ,

write(2) .
.
M_DATA. %

getmsg(2) %
(
M_PROTO), (

M_BREAK

break.
STREAMS (STREAMS pipe)
.
%
.
%
. , %
%
.
.
, %
, .

M IOCTL

. %
.
M_SETOPTS

%
.
. %
.

www.books-shop.com

362

5.

,
,
.
. !
, , .
. !
:

M_IOCNAK

M_PCPROTO
M_PCRSE


ioctl(2).
%
M_IOCTL


,
.
%
M_IOCTL


. %
, %
close(2) poll(2).

(, ) .
,
, % %
(


,
ioctl(2).
ioctl(2) ,
,
.


%
.
,
, %
.
.
, %

, !
. !

www.books-shop.com

STREAMS

363

!
. ,
, .
,
. , !
, !
. !
read(2)

, .

int

*q,

q !
xxput
, .
xxput
!
, .

. !
. ,
xxput
xxservice

. xxput
!
, ,

!

() , !
, ! , !
, !
. ,
xxservice

() , !
, . ,

() (
) , !
. !
xxput ()
() !
.
. !
. !
xxput
!
.

www.books-shop.com

364

5.

xxput
!
,
:
*q,

mp q,
, , !
.


runqueues

!
:
! /
.
!
.
, !
STREAMS .
runqueue
,
. !
, , !



, .
! , ,
runqueue

.

, , !
, xxput
xxservice
!
.
,
xxput
, !

, . 5.19,
xxput
, !
,

xxput

. .:
*mp)
{

STREAMS
UNIX.

www.books-shop.com

365

STREAMS

. 5.19.

, !
. ,
, .
, .
(
, , ,
!
,
! . ,


,
.

,

( )

! . ,
.

www.books-shop.com

366

5.

,
. ,
, ,
.
, 1 3 !
, 2 . , 2

3, !
xxput
,
3

,
, ,
:
*q,
{
/*


xxservice
3. xxput
!

!
.
:
int

,
!
, , . . !

!
, ,
. ,

1. ,
, . !


( 2,
1), !
, .
. 5.20.
3,
.
{

!=NULL) {

if

www.books-shop.com

STREAMS

367

else

break;

}
}

. 5.20.
getq(9F)
,

. 1 , . .
!
"",
,
3. !
, , !
xxservice () . !

www.books-shop.com

368

5.

, 1 !
.
,
, !
, , , .
( ) !
, !

.
, 1 ,
. 1
, STREAMS !
xxservice
,

3.

. , xxput

xxservice
!
". ,
, , .


. ""
. !
,
.

,
(streamtab, qinit,
)
(
xxput ( ) , xxservice ( ) xxclose
!
.
!,
.

.
. ,
.
!, .
,


.
.

www.books-shop.com

STREAMS

369

, , .
.
(., ,
. 5.15),
.
, . !

,
.

.
,
, , , !
/.
,
, !
STREAMS. !
, ,
,
:
, !
, .
, !
.
, ,
.


!
, !
, !
.

, !
.
.

<stropts.h>
putmsg(int fildes, const struct
const struct strbuf

int

, !
PROTO ,

%RRNVVKRS

piracy@books-shop.com

5.

370

DATA.
strbuf ctlptr
!
.
strbuf :
struct strbuf {
int
int len;
void
)

m a x l e n , len , buf
.

!
, RS_HIPRI.

, !
, , .
, !

.

, !
, , !
. , , !
.

, !
, .

read(2)

M_PROTO, . , !
PROTO
M_DATA, getmsg(2) :
.
getmsg(2) :
ftinclude <stropts.h>
int

f i l d e s , struct s t r b u f
struct strbuf

*ctlptr,
int

SETOPTS



!
() .

www.books-shop.com

STREAMS

!
,
,


!
,
!
, a
.
getmsg(2) ,
RS_HIPRI, , !
f l a g s p , !
.
, , !
, !
.
, , ,
.
, ,
! . ,
,
. !
, .

, ,
STREAMS, !
!
. ,
( , ),
, !
STREAMS:
qinit streamtab. !
. 5.21.
streamtab

xxclose
xxput xxservice
s t r e a m t a b
qinit, , !
. , q i n i t , !
I_LINK, !
. !
qinit ,
( ).

xxclose

. !
xxput ( ) ,
()

www.books-shop.com

5.

372

, . !
qinit
!
!
,

mi_minpsz),
() (mi_idnum,
mi_idname).

() STREAMS

STREAMS


d_str, NULL !
. STREAMS
. ,
streamtab ,
. !
. . !
,
cdevsw [
.


, STREAMS.
, : !
,

www.books-shop.com

STREAMS

373

( ), !
.

!
.
,
specfs,
. vnode

specfs spec_open
spec_open

c d e v s w [ ] ,
!
. STREAMS stropen
!
.
, !
. 5.22.

. 5.22.

www.books-shop.com

5.

374

stdata,

, .
!
.
queue
stdata.
queue

,
STREAMS.
!
. ,

queue !
.

.



,
, , !
!
. .
!
. ioctl(2).
I_PUSH ,

. !
:
fd =
ioctl(fd,
ioctl(fd,
I_POP, (char
ioctl(fd, I_POP, (char

/dev/stream, !
modulel
,
!

!
. /,

,
, . ,
q_qinfo queue
streamtab . ,
, UNIX !

www.books-shop.com

STREAMS

375

fmodsw [
streamtab. !

.



ttinclude
<stropts.h>
<sys/conf.h>
int ioctl(int fildes, int command,

!
, .
ioctl(2) !
. !
: ( !
)
.
.
ioctl(2),
, , !
.
ioctl(2) !
. , !

, . !
,


, !


!
.
!
. , ioctl(2)
,
. ioctl(2)
!
,
.
STREAMS.

www.books-shop.com

376

5.

.
!
, .
STREAMS
.
ioctl(2)

strioctl:
I_STR, (struct strioctl
struct strioctl {
int
int
int ic_len;

_ ,
_ ,
,

! ETIME,
_ ,
ic_dp

, !



(ic_len, ic_dp). .
,
.
, , !

.
!
.
ioctl(2) (transparent
ioctl(2),
.
ioctl(2),

command arg. arg !
,
( ), !
. , !
.
.

www.books-shop.com

STREAMS

,
M_COPYIN,

. ,
.
, !
.
M_IOCARGS,
. .

!
.
, , !
M_COPYIN
M_IOCARGS. , ,
.
.
!
, ,
M_COPYOUT, ,
. ,
. !
,

,
ioctl(2).

STREAMS
,
STREAMS.
, . ,
N:l,
. ,
1:, !
. !
, , !

.

arg,

COPYIN.

www.books-shop.com

378

5.

, STREAMS !
, !
.
!
!
. !
.
, !
, , !
vnode,

. ,
.
, ,
.
, . . 5.23 !
.

. 5.23.
.
!
. !

www.books-shop.com

STREAMS

379


.
!

st_muxwinit.
STREAMS


. %
, .
, %
, , %
.
I_PLINK


,
.
I_LINK.

I_UNLINK,

. !
IP, !
Ethernet, FDDI.
Ethernet, FDD1
IP, . !
:
fdenet =
=
fdip =
ioctl(fdip, I_LINK, fdenet);
I_LINK,

, !
fdenet, f d f d d i fdip (. 5.24, ) !


!
, . 5.24, .
!
( , ,
Ethernet FDDI),
STREAMS, !
. !
IP Ethernet . 5.25.


.

%RRNVVKRS

piracy@books-shop.com

380

5.

. 5.24.

/,
. !
, !
UNIX , . !
!
.

www.books-shop.com

381

. 5.25.


STREAMS,
. ,
,
UNIX.

www.books-shop.com


UNIX

!
. ,
, !
.
.
!
,
, (!
, ,
), .
UNIX , !
.
.
UNIX !
,
TCP/IP.
, !
XX Internet. !
TCP/IP
, Ethernet FDDI,
ATM, ! !

.

TCP/IP Internet Protocol (IP), User Datagram Protocol (UDP)
Transmission Control Protocol (TCP). !
,
, !
.
TCP/IP.

TCP/IP ,

www.books-shop.com

TCP/IP

383

BSD UNIX, , !
, !
OSI.
,

. , !

(Remote Procedure Call ),
!
, CORBA (Common Object Request Broker), Java . .

BSD UNIX UNIX
System V.

TCP/IP
TCP IP.
, , , !
. , , !
.
1969 Defence Advanced Research Projects
Agency (DAPRA)

(packet switching network). , ARPANET,
!
. !
!
, . !
TCP/IP. 1983 TCP/IP !
(MIL STD), DAPRA !

TCP/IP UNIX.
TCP/IP:
,
!
. TCP/IP

.
TCP/IP !
. TCP/IP !
: Ethernet, Token!Ring,
. . .

www.books-shop.com

384

6.

UNIX

, !
!
.
, ,
Internet.
TCP/IP
!
, !
, , !
. .

TCP/IP
TCP/IP
Internet
. Internet !
,
TCP/IP . Internet !
, !
( ). !
.
Internet "" 1969 , DARPA
, ARPANET.

. ,
DARPA Bolt, Beranek and Newman
(BBN). 1969 ,
: (Stanford Research
Institute), ! (University of
California at Santa Barbara), !
(University of California at Los Angeles) (University of
Utah). !
Honeywell 316, Interface Message Processor (IMP).
,
ARPANET. !
, . !
!
(National Science Foundation, NSF)
! . 1981
NSF CSNET (Computer
Science Network).
1984 ARPANET : MILNET,
, ARPANET
"" .

www.books-shop.com

TCP/IP

385

1986 NSF ,
56 / !
. NSFNET
1995 , Internet. !
45 /, !
4
NSFNET
ARPANET. 1990
. ,
ARPANET,
,
.
ARPANET !
. Network Control
Program (NCP). ,
.
ARPANET, , , !
:
( !
! ),
,
, , ,
. , ,
(internet), !
(, !
, ).
Internet
Protocol (IP), !
, Transmission Control
Protocol (TCP),
.
1973


1995 4852000,
3 . 1996 Internet :
, 134 365 , .
1997 Internet Network Wizards
(http://www.nw.com) 16 146 000 ( DNS), !
828 000 . , "" 3
.
,
, .
,
.

www.books-shop.com

386

6. UNIX

TCP/IP
TCP/IP ,
: ,
, . !
, , ,
.
( ). !
, .
: !
, ,
, .
. ,

, , , !
.
,
!
,
. :
/ (Application/process layer)
(Host!to!host layer)
Internet (Internet layer)
(Network interface layer)
,
.
,
(, Ethernet !
!).
, (, ).
Ethernet, IEEE802.X, SLIP, PPP . .

TCP/IP, Internet ,
TCP/IP !
.
Internet ,
, . ,
,
, . !
, ,

www.books-shop.com

TCP/IP

387


,
,

. Internet IP.

, . !
, ,
, . . !
TCP UDP.
, !
, , !
, . .
Telnet, File Transfer Protocol
(FTP), Simple Mail Transfer Protocol (SMTP) . .
. 6.1
TCP/IP. , ,
,
, Internet.

TCP/IP !
. , RFC894 (A Standard for the Transmission of IP Datagrams over
Ethernet Networks) IP!
Ethernet, a RFC 1577(Classical IP and ARP over ATM) ATM.
. 6.2
TCP/IP. !
.
!
,
(Ethernet,
ATM . .). !
, ,
!
. IP.
, IP
! !
.
TCP UDP.

"" (router).
"", , .
OSI , , !
(
!
). UNIX ! ,
.

www.books-shop.com

388

6.

UNIX

,
.
TCP UDP , !
IP. ,
, Telnet
FTP.

. 6.1. TCP/IP

. 6.2. TCP/IP

www.books-shop.com

TCP/IP

389

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


. IP !
. . . IP! Internet!. ,
, , . !
, ,
.
.
, !
, (IP!) !
( ). , !
(
). !
, , !, !

(hop) .

2000 ( ), , 23, !
. . 6.2
, X. 2000
TCP (, !
), ,
23 . TCP, ,
IP,
. !
IP
( ) , X
.
, , !
(IP!
, . .).
.
(Protocol Data Unit, PDU), ,
, , .
(peer
module)
.
. 6.3 !
TCP/IP.
23 2000

%RRNVVKRS

piracy@books-shop.com

6.

UNIX

, !
, !
(,
Telnet). TCP
TCP , !
. TCP !
!
(). TCP !
, ,
. IP
, , IP
, .
TCP, !
. IP ,
TCP UDP,
.

. 6.3. TCP/IP

TCP/IP : !
, !
, .

www.books-shop.com

TCP/IP

391

OSI
TCP/IP
. !
,
. !
!
, !
.
IP TCP UDP.
, IP
.
!
.
,
. ,
, !

, "" !
. ,
!
.
1983 !
(International Organization for Standardization, ISO),
(Open
Systems Interconnection, OSI). !
.

, !
.
OSI, TCP/IP, !
,
, !
. !

.

!
.
OSI , !
. 6.1.

www.books-shop.com

392

6.

UNIX

OSI



(Application layer)


(Presentation layer)


(Session layer)


(Transport layer)

%
.


(Network layer)

%
%
. ,


(Data link layer)

%
. %
, %


(Physical layer)

%
. %


OSI. 1 !
2.
. !

. ., !
.
!
, !
,
.


, .
, !
, ,
: , !
, , .

(peer) . , !

, , !
.

www.books-shop.com

393

IP

!
, , , !
. .
, TCP/IP OSI.
. 6.4 TCP/IP OSI.
, Internet ( )
. , OSI
TCP/IP . !
, !
!
Internet.
TCP/IP

OSI


(Application layer)

(Application layer)


(Presentation layer)

(Session layer)


(Host%to%Host layer)


(Transport layer)

Internet
(Internet layer)


(Network layer)


(Data link layer)

(Network interface layer)


(Physical layer)

. 6.4. TCP/IF OSI

IP
(Internet Protocol, IP) !

!
. IP !
, ,
. . IP
. ,
IP, . !
, TCP IP !
, (

www.books-shop.com

6.

UNIX

) , !
. !
,
NFS,
"" UDP. NFS !
.
OSI IP 3! , ,
!
. IP !
: , .
, IP, !
(datagram), . 6.5.

,
IP, ,
IP. ,
,
(connectionless).

UDP TCP

. 6.5.

IP
!
,

!
.
IP
!
,
!
.
IP !
. ,


, . ,
FDDI 4470 ,
Ethernet 1500 .
IP!,
, . 6.6.

www.books-shop.com

395

IP

. 6.6.
20 .
Version 4 ( IPv4).

(Internet Header Length) 32!


. 20 IHL !
5. , !

(, TCP). Type of Service

!
:

Precedence. .
, !
Precedence !
(, !
Precedence
).

Delay. . 0
, 1
.

Throughput. . 0 !
, 1
.

Reliability. . 0 !
, 1 .

67

Type of Service
.

www.books-shop.com

396

6.

UNIX

, Type of Service. , !
, !
. !
Type of Service !
.
RFC 795 "Service mappings".
Total Length
(16 )
.

.
65535

32! !
. , !
, , !
, !
. IP!
, "" !
,
!
. ,

(),
!
.
Identification. !
!
! .
Fragment

.
Flags :
0

DF. 0 . !
1 .
, !

MF. 0 , !
( !

0). 1
,

!

. MF !
1 , ,
.

www.books-shop.com

IP

397

64! . !
Total Length
Fragment O f f s e t .
, , ,

:
Identification, (Source Address),
(Destination Address) Protocol.

Fragment


" " .
0,
. , !
, , !
. !
, a TTL !
1,
( ),
. !
""
Protocol ,
. !
RFC 1700 "Assigned numbers",
. 6.2.
6.2.

Internet Control Message Protocol,


Internet Group Management Protocol,
IP IP
Transmission Control Protocol, TCP
User Datagram Protocol, UDP
Resource Reservation Protocol, RSVP
Packet Video Protocol, PVP

2
4
6
17
46
75

32! 16!
/ Header Checksum.
Source Address Destination Address
. ,
IP!, 32 .
Options , Padding !
32! .

www.books-shop.com

6.

398

UNIX

IP! :
( ) .
IP!, , !
. !
, D.
, . 6.7.

110

!14!

%16%

'
1 1 10

. 6.7. IP%

(internet),
. IP! .
,
.
, ,
, !
.
. Internet !
. !
IANA, !
. !
.
7 , !

!
! 7 128 , 0 127 !
. ,
( ), .

www.books-shop.com

IP

399

, !
Internet
!
126 .

14 . !

.
Internet
150. !
.
254 .
80!
Internet !
"" . ,
, !
250 "" Internet
.
IP!.

(subnetwork) .
, ! !
IP,
.

, 32! , !
( ) !
. IP !
"" ,
,
(
),
,
. . 6.8.
" ", ,
ADDRESS MASK REQUEST ( )
ICMP ,
ADDRESS MASK
REPLY .
IP! !
(, . .).
. 6.3.

, ( ),
Internet, .

%RRNVVKRS

piracy@books-shop.com

6.

400

UNIX

. 6.8.
6.3. IP%

:0, :0
:0, :

:
: 192.85.160.0
: 255.255.255.240 : 2
: 4
0.0.0.0

0.0.0.5

( )

255.255.255.255

:1111...1

:S
:1111...1
127

192.85.160.255

%
N

192.85.160.47

S
N

127.0.0.1


DARPA, ,
,

www.books-shop.com


.
!

!
, .
TCP UDP !
.
!
, !

.
, DARPA !
. ,
(
OSI) .
48! , ,
.
(Internet)
Address Resolution Protocol (ARP).
Internet ( OSI) !
IP!.
Protocol
DARPA.
,
(port number), (!
), , !
. , !
( !
, IP! )
. () !
TCP! UDP!. IP! ,
, IP!
!
.
16
.
RFC 1700 "Assigned Numbers".
. 6.4.
6.4.

( )

7
20

echo
ftp%data

Echo
FTP

21

ftp

FTP

www.books-shop.com

6.

402

UNIX
6.4 ()

( )

23
25

telnet

(Telnet)
(Simple Mail Transfer Protocol)

53

domain
bootps
bootpc

(Domain Name Server)


Bootstrap Protocol

67
68
69
70
80

gopher

110
119
123

nntp
ntp

161
179

bgp

Bootstrap Protocol
(Trivial File Transfer Protocol)
Gopher
World Wide Web (HyperText Transfer Protocol)
(POP )
(Network News Transfer Protocol)
(Network Time
Protocol)
/ (Simple Network Manage%
ment Protocol)
(Border Gateway
Protocol)

User Datagram Protocol (UDP)


, !
, !
.
, ,


IP , ,
. , !
, !
, ,
.
UDP, !

, ,
TCP. UDP, . 6.9, 8
.
, 2 , !
. !

www.books-shop.com

403

.
Length
8 !
. Checksum
.
, . !
, IP!
Protocol IP!.
. 6.10. , !
IP!, ,
. , UDP !
Protocol 17.

. 6.10. UDP

,
UDP, :
DNS, 53.
Network Time Protocol, 123.
, 67 68
.

www.books-shop.com

404

6.

Trivial FTP
RPC,

UNIX

69.


,
(). , !
, UDP ,
, , !
. !
, ,
,
IP, TCP.

Transmisson Control Protocol (TCP)


TCP , !

. TCP
, Telnet, FTP
HTTP.
TCP ,
:
!
, . . !
.
.
, !
.
!
.
.
,
, , , !
, . . , !
, TCP, . !
, ,
, .
TCP! !
.
, !
. TCP! ,

www.books-shop.com

405

, .
TCP! .

. 6.11.

(Sequence Number),
TCP.
: !
(Acknowledgement Number), !

. !
.
, 32 !
TCP!, , !

! 1), 0. !
(Inintial
Sequence Number, ISN) .
(ISN+1).

!
(sliding window). TCP!
Window, ,
, , Acknowledgement Number.
TCP! 20 . !
, !
. !
, !
. .

. !
, TCP! .

www.books-shop.com

6.

UNIX

32! . ,

5.
Flags,
:
, ,
Urgent pointer .
, %
Acknowledgement Number.
PSH

,

, %
.
.

SYN

, %
, " "
.
, %
.

Checksum .

!
, , IP! , !
. !
IP , UDP !
.
Urgent Pointer !
. URG
, !
.
Options , !
, ,
(MSS). (Padding) ,
32 .
TCP[
, TCP
, !
TCP!. !
. TCP!
, (, !
), ""
TCP! , , !

www.books-shop.com

407

, . !
, !
, ""
" !
" (three!way handshake),
.
, , !
,

, . . !
, !
!. ,
( !
) !
! SYN , !
SYN !
. , , !
,
TCP!.
TCP! .
TCP!,

. , ,

,
.
, ,
, , !
. ,
, , ,
,
.
, ,
. !
, , , !
. !
, , !

TCP .
()
!
(

2 / 4,5 , (!
). !
,
2 . ,
"" . 100 /
5 .
S Y N S Y N .

www.books-shop.com

408

6.

UNIX

. 6.12. %
, %
%
TCP%
TCP . !
,
FIN (. 6.12).
. !
, !
FIN.
. !
, , !
FIN,
,
FIN , !
.

www.books-shop.com

.
!
TCP!.
, ( )
CLOSED. !
LISTEN.
!
SYN.
SYN!SENT .
SYN
SYN!RECEIVED.
"" ESTABLISHED. !
(, ) !
FIN,

(, ) !
CLOSE!WAIT,
. !
FIN!WAIT!2,
FIN. !
.
. 6.5.
6.5. TCP%

LISTEN

%
.

SYN%SENT

SYN%RECEIVED

ESTABLISHED

,
.

CLOSE%WAIT

%
, .

LAST%ACK

, %
. %

.

FIN%WAIT%1

, %
( ,
).

FIN%WAIT%2

CLOSING

%RRNVVKRS

piracy@books-shop.com

4/0

6.

UNIX
6.5 ()

TIME%WAIT

CLOSED

, %
, %
. %
2 MSL (Maximum Segment
,
.


TCP! ,
!
. , ,
SYN

!
.
,
, !
.
. !
TCP!. ,
TCP , !
!
.
, , !
,
() PSH, TCP
,
. , , !
( Telnet).
, TCP !
.

MSL, RFC 793 "Transmission Control Protocol",


2 . MSL 30 ,
1 2 .
,
(Transmission Control Block). , , !
, !
. U N I X !
.

www.books-shop.com


IP !
, ,
, ,
. !
TCP , !
. , TCP
.

. !

,
( ). TCP

(Positive Acknowledgement and Retransmission, PAR). ,
,
.
, . !
(NAK).

, . 6.13. !
.

200 . !


(=301). !
. , !

!
, !
.
, , TCP !
.
, (send window )
(receive window ) TCP!.
!
. , !
, !
, , !
. ,
!

, , , !
, !
. ,

, . !
" TCP" .

www.books-shop.com

6.

412

UNIX

( ) .

!
Window
), , , .

. 6.13.

. 6.14.
4 8 .
, ,
3, 5 . !
, 2 (7 8). !
,
"" . !
, , (
) .
. !
.
. !

www.books-shop.com

413

, .
, TCP !
.
,
, .

. 6.14. TCP
, , ,
, (offered
window),

. !
,
(usable window), !
, !
. , ,
, .
!
, , !
. , " "
(Silly Window Syndrome, SWS), .
TCP
TCP
, !
. , , !
,
TCP, . !

, !
, ,
. !
TCP, .

www.books-shop.com

6.

UNIX

" "
!
TCP. ,
, ,
, . !
, , !
!
( !
), " " (SWS).

, TCP. !
, ,
200 . !
1000 . ,
200 . !
(

. ,
,
1000 . !
1000 .
. 6.15.
.
800 ,
200.
SWS. , !
50 (, !
PSH). , 50 !
, , 150 (
200). !
50 , , !
(1000 ).
, , 950 !
, , , 50 .
50 , !
.
, , !
, . .
!
. .
: !
!
. !
, !

www.books-shop.com


.
"" !
.

6.15. SWS
,
. , !
, TCP
, .
,
:
1. . !
, ,

www.books-shop.com

416

6.

UNIX

( 0),

(Maximum Segment Size, MSS), 1/2 ,
, .
2. , !
,
, !
.
, SWS,

. , !
" ",
. !
, ,
. ,
SWS .
!
.
, , !,
PSH ( ,
), , !, !
.
,
,
, , , .

TCP , !
, .
,
!
.
, , !
(slow start). ,
, , !
,

!

(congestion window).

( MSS,
, ,

www.books-shop.com

417

536 512 ). !
.
, !
, .
,
, !
.
,
.
,
.
, ,
, . !
, !
. ,
!
, !


!
, .
, , !
.

, , .
,
. !
,
.
.
, , !
, ,
, ( 1%). ,

, ,
(Round Trip Time,
!
. sz (,
cwndo = sz
= cwndo +
=
=

www.books-shop.com

6.

UNIX

, ! !
. ,
: !
() .
!
, ,
. !

cwnd
ssthresh.
:
1. cwnd ssthresh
65535 .
2. , !
, !
.
( ! !
) ssthresh !
, !
. !, !
cwnd , ,
, .
4. ,
cwnd, ,
.
cwnd ssthresh, TCP !
, .
, ,
, !

!
.
,
, , . ., !
.

,
, (,
. .) . !
,
.
, , !
ssthresh, 1/2 , .

www.books-shop.com

419

cwnd

, , !
!
(Round Trip Time,
!
, .
. , ! !


!
sz, .
,
cwndn+i

cwndn +

+ sz

. 6.16 !
. ,

ssthresh.

. 6,16. %
%


. RFC
"Requirements for Internet Hosts Communication Layers", TCP

, . ,
.

%RRNVVKRS

piracy@books-shop.com

420

6.

UNIX

!
. ,
,
.
( !
),
.
, !
: , ,
. !
, TCP !
. , !
!
, , ,
,
( ) .
, , . !
.
(fast retransmit).
, ,
. , ,
,
, ,
, .
.
!
!, . !
,
.



!
BSD UNIX.
BSD UNIX,
!
. " BSD UNIX" !
, !
UNIX BSD.
!,
.
,

www.books-shop.com

,
" BSD UNIX.
3.
,
, , , !
.
AF_INET. !
. !
TCP/IP, !
: (IP!) !
( ).
!
sockaddr. !
sockaddr_in :
struct
short
u_short
struct
char

{

IP

!
.
, ,
, UNIX System
V, , !
.

TCP. ,
. , . 6.17,
" !
BSD UNIX. ",
!
UDP.
,

!


accept(2) ,
.
,
. , !
,

, ,
. !

www.books-shop.com

422

6.

UNIX

, .

!
(IP! ). !
(" ")
!

.

. 6.17.
, !
. , !
, , ,
IP!
!
,

IP!
"" ,
!

www.books-shop.com

423

,

.

ftinclude
linclude

ftinclude <stdio.h>
<fcntl.h>
<netdb.h>
/* ,
#define
1500
argv)
int
char
{

int s, ns;
int pid;
int nport;
struct sockaddr_in serv_addr,
struct hostent
char
/*
nport = PORTNUM;
nport =
/* ,
SOCK_STREAM,
{

}
/*3
=
=
=
/*
sockaddr

}

"
/* .
, 5. ,

www.books-shop.com

424

6.

UNIX

}

while (1)
{
int addrlen;

addrlen =
/* . ns

(struct sockaddr

{
accept

}

" =
/*

}
{
int nbytes;
int



close
/*
while
= recv(ns, buf,
!=0)
{
buf,
0);
}
exit (0)

}
.

www.books-shop.com

425

ttinclude
<stdio.h>
<fcntl.h>
<netdb.h>
idefine

,
1500
argv)

char
int
{

int s
int
int
;
struct sockaddr_in
struct hostent
char
/*B ,
.

=
=
/* */
{

"
/*
if
(struct sockaddr
{

/*0
buf,

www.books-shop.com

426

6.

UNIX

if (recv(s, buf, sizeof(buf), 0) <0)


{

}

:

close

TLI
BSD UNIX !
, !


(Transport Layer Interface, TLI),
.
UNIX System V Release 3.0 1986 .
UNIX,
STREAMS, !
.
STREAMS, !
, ,
. !
STREAMS !
, UNIX libnsl.a


(, TCP)
(, UDP).
. 6.18 6.19

. ,
, "
BSD UNIX.
3 .
.
, !
. !
,

. ,
.

www.books-shop.com

427


netbuf, :
struct netbuf {
unsigned int maxlen;
unsigned int len;
char
}

. 6.18. TLI %

buf , ,
maxlen , a len , . .
.
sockaddr, !

!

www.books-shop.com

6.

428

UNIX

, , , netbuf !
TCP/IP.

. 6.19. TLI

netbuf ,
. !
, !
. !

:

!
. :

char
int

fd, int
*ptr, int

int f i e l d s ) ;

struct_type , !
. :

www.books-shop.com

429

struct_type

T_BIND

struct t_bind

T_CALL

struct t_call

T_DIS

struct t_discon

T_INFO

struct t_info
struct
struct t_unitdata

T_UDERROR

struct t_uderr

Co , , !
.
!

f i e l d s ,
:
fields

T_ADDR

addr t_bind, t_call, t_unitdata,


t_uderr
opt t_call,

udata

t_uderr,
t_call,

t_unitdata,

. , !
, netbuf maxlen .
, !
, !
. ,


!

d, , !

.
. 6.18
!

!

,
. :

int

<tiuser.h>
<fcntl.h>
char

int

struct

%RRNVVKRS

piracy@books-shop.com

430

6.

UNIX

path , !
, , /dev/tcp
of lags !
(2). !

info, :
addr

%
. %1 , , %2 ,
.
TCP ( )

options

. %1
, , %2 , %

.

(Transport Service Data Unit, TSDU). ,
(. .
). %1 , %
, %2 , %
. TCP %
, tsdu 0. %
, UDP .
%
(Expedited Transport Service Data Unit, ETSDU). %
,
(. . ). %1 ,
, %2 ,
. TCP ,
UDP % .

connect


. connect %
. %1 ,
, %2 , %
. TCP UDP .

discon

, connect,
. TCP UDP .

servtype

, .

%
, T_COTS_ORD
,

. TCP
T_COTS_ORD, a UDP CLTS.

www.books-shop.com


,
.

3
BSD UNIX . !


:
int

const struct t_bind *req,


struct t_bind

fd . req
, ret !
, .
t_bind, !
:
struct
unsigned

addr

, %
.

req:
req == NULL
req != NULL
== 0
req ! = NULL
len > 0

%


,
,


,


ret. ,
, , ret.
!
!
!
.

:
<tiuser.h>
int

fd, const struct t_call


struct t_call

,
. !
t call, :

www.books-shop.com

432

6.

UNIX

struct netbuf

struct netbuf opt

struct netbuf udata , %
(
)
int
sequence


!
: , !
, . , TCP,
UDP !
. rcvcall NULL,
.

!
,
(, ).
!
!

.
#include <tiuser.h>
int

fd, struct

, call,
, !

, ,
, , , !
. sequence call
.
t_listen(3N), , accept(2),
, !

, !
.
:
ftinclude<tiuser.h>
int

fd,

int connfd,

struct t_call

fd , ( ,

connfd ,
. !
(. .

fd ! !
.


.

www.books-shop.com

433

t_accept(3N)

!) , !
.
!
:
t_snd(3N) !
. :
ttinclude <tiuser.h>
int t_rcv(int
char *buf, unsigned nbytes, int
int t_snd(int fildes, char *buf, unsigned nbytes, int flags);

f l a g s t_snd(3N) !
:
T_EXPEDITED
T_MORE


, , %

, TCP ,
,

t_rcv(3N)
f l a g s .
!


. :
ttinclude
int
int

fildes, struct t_unitdata *unitdata,


int *
fildes, struct t_unitdata

unitdata, !
:
struct netbuf addr
struct netbuf opt
struct netbuf udata


t_close(3N). , , ,
, .
t_close(3N) :
ttinclude
int
f d . !
, ,

www.books-shop.com

434

6.

UNIX

close(2) . !
( ) ,
, , .
, . , ,
!
, .
,
.
!1 . !
, 0.
, !
t_errno, , errno
. , !
,
void

char

t_error(3N) !
errmsg,
, , !
t_errno. t_errno TSYSERR,
, !
errno.
!
!. ,
. ,
, . !
,
,

",

tinclude
finclude
<arpa/inet.h>
iinclude <fcntl.h>

/* ,
ttdefine
1500

int
char

www.books-shop.com

435


int tn,
int pid, flags;
int nport;

struct sockaddr_in
struct
struct
struct t_call
.

{

*/
nport =
/*
nport =
= AF_INET;
=
=
=
=
= (char
,

=

(struct

*)0) < 0)

exit

" :
/* t call
,
if
=
(struct
t_alloc(tn,
{

}
=
=
= 0;

= 0;

www.books-shop.com

436

6.

UNIX

{

(t_listen(s, call) <0)
{

}
,
clnt_addr = (struct

=
(struct t_info *)
<0)
{

}
/*
if
(struct t_bind
(struct
*)0) <0)
{

}

if
{

ntn, call) <0)

{
t

{
int nbytes;
,
* /
while

buf,
sizeof(buf),

!=0)

{
t_snd(ntn, buf,

)
t

www.books-shop.com

}
: ,

}
}

ttinclude
ttinclude
ttinclude
ttinclude <fcntl.h>
ttinclude
1500
argv)
char
int
{

int tn;
iht
struct sockaddr_in
struct hostent
char
struct t_call
/*B ,
.
{

}
.

}

(struct t_bind
(struct t_bind *}0) < 0}

exit

}
" :
inet

www.books-shop.com

438

6.

UNIX

/* ,

=

=
/* t_call
,
if ( (call =
(struct
t_alloc(tn,
{

}
=
=
= (char *)
= 0;
= 0;

call, (struct t_call *)0)==1)
{

}
*/
buf,
if (t_rcv(tn, buf,
<0)
{

exit
}

:

!
,
t_close(3N).
, t_close(3N) !
, . !
, TCP, !
, , TCP
, . ,
TCP,

t_rcvrel(3N),
(orderly
release). , !
,
, , , TCP.

www.books-shop.com

439
t_rcvrel(3N) :

ttinclude

;
fd);


!
, , !
.
f d .

t_rcvrel(3N). !
, ! ,
.
, ,
t_rcv(3N)
TLOOK.
, , !
,
.

, !
, . 6.6.
6.6. ,

T_ORDREL

T_ERROR

T_UDERR

,
. ,
, ,

%RRNVVKRS

piracy@books-shop.com

440

6.

UNIX


, , !
. , !
, , ,
,
!
, . .
.
, !
:

if
{

== T_LOOK

==

exit

t
exit

(t

!
!
, !
.
, !
,
.
, !
,
,
.
, , ,
NFS, (Remote Procedure
Call,

www.books-shop.com


!
, .
, !
. ()
, . .

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


, !
,
.

!
, !
, .
RPC
, , ,
:
1. ! , !
(stub). "", , !
, !. !
, ,
. ,
. , !
, ,
. !
(marshalling).
2. .
, , !
. ,
,
TCP/IP.
.
!
.

www.books-shop.com

442

6.

UNIX

(, !
).
4. !, !
, .
5.

, .

!, !
, .
6. !
, , ,
( , ) !
,
, ,
, . !
: , !
( )
.
!,
.
, RPC,
!
(), ,
. !

()
. :
, !
, !


! .
.
, (, !
).

' , ,
!
( )
, ,

, . ,
,



Pascal, Windows NT!

www.books-shop.com

443

, ,
. ,
. !
, RPC,
, , , !

(binding)
,
, .
, :


. !
, !
,

.
RPC
. ,
.
, !
(, )
. !
,
,
.
, , !
, , !
.

, !, !


( !

, !
, !
. ! !

. ,
, !

, , !

(
,
.

www.books-shop.com

444

6.

UNIX

,

.
,

,
.

!
. U N I X ,
,
. .
.
!
, , , !
.
, UDP
!
. , , !
. , !
TCP, ,
TCP!.

, !
. !
. ,
, ,
, ? ,
,
. !
(!) !
, ,
,

. .
,
:

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

www.books-shop.com

445

!
. ,

.

!
, .
.
, !
,
(,
, . .)
RPC !
,
, .
, RPC Sun Microsystems
:



IEEE
ASCII

RPC
.

!
. , RPC ,
, .
, ,
.

Sun
Microsystems !
TCP
!
. UDP
!
:

!

8 .
. !
TCP !
,

www.books-shop.com

446

6.
.

, TCP
:


8
, ! !
. ,
TCP,
, . ,
,
,
Remote Procedure Call Protocol
version 2",
32! !
, .
! . ,


(!). !
, ,
.
!
, .
(TCP) !
, .
, , !
,
?

RPC !
!. ,
, RPC
. !
,
.
RPC ,

!
, .

www.books-shop.com

447

. , ,
.
RPC Sun Microsystems.
:
rpcgen(l)
!
!
.
XDR
Data Representation),
!
,
.
, .
!
.
.
: !

( ),


main

( ) .

log.x !
:


.
, .
log.x
!
, ,
.
, RLOG, !
( ),


.
program LOG_PROG {
version LOG_VER (
RLOG (string)

1;

} = i;
} =

rpcgen(l) log.h, , , !
:

www.books-shop.com

448

6.

UNIX

/*
* Please do not edit this file.
* It was generated using rpcgen.
ttifndef
<rpc/rpc.h>
ftdefine
ftdefine

RLOG
extern int

long)

/*
extern int
/*
*/

. RLOG,
,
!
!
.
int

RPC !
. !
.
!
,
!
.

.
.

(, ). !
,
:
log.
<rpc/rpc.h>
#include
<sys/stat.h>


static int result;
int

int

www.books-shop.com

449

result =


result ==
!
,
j
! 0 APPEND); < 0! return

=
if

!= len!
result =

else
result

0;

,
, ,
,
, .

.
client.c

argc, char
{
CLIENT
char*server,
time t

server =


if (
r

%RRNVVKRS

piracy@books-shop.com

450

6. UNIX
/* */
mystring = (char *)malloc(100);
/*0 */
bintime = time((time_t *)NULL);
clnttime = ctime(&bintime );
sprintf (mystring, "%s ",

clntime);

/* .
*/
if ( ( r e s u l t = rlog_l(&mystring, cl)) == NULL) {
fprintf(stderr, "error2\n");
clnt_perror(cl, server);
exit (3) ;
}
/*B */
if (*result !=0 )
fprintf(stderr, " \"!;
/" */
clnt_destroy(cl);
exit(0);

.


log svc.e

server.nowhere.ru !

$ logger

Hog !
.
RPC . 6.20. !
:
1. ,
!
.


.

.
1) !

.

www.books-shop.com


. !
. , !
,
2.
, ,

!
, , .


server.nowhere.ru .
3. r l o g _ l

,
. , ,
( XDR)

,

. !
logger ( !
). , (
), r l o g _ l


XDR, !
UDP.
,
.

. 6.20. RPC

www.books-shop.com

6.

UNIX

BSD UNIX

U N I X . UNIX, TCP/IP
BSD U N I X .
UNIX !
, :



,
,

!
.
,
OSI.



, , !
. , !
, TCP/IP
TCP. , , !
,
. !
( ). ,
, !
(,
Ethernet).
!
. ( ) !
, !
3 " BSD U N I X .
!

. !
!
!
. , , , !

!.
(. . ) !
.

!

www.books-shop.com

BSD UNIX

453

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

BSD U N I X ,
, , !
.

socket, , . 6.21.

!

(so_proto).

www.books-shop.com

454

UNIX


. !
(,

!
. !
m b u f , . 6.21. !

.
!
. , , ,

!,
(, read(2)
(

.
!
. , TCP
.

(
!
: , !
, ,
.
, , !
.
!
, .
, ,

,
, 5.
.
. 6.22.

. 6.22. %

www.books-shop.com

BSD UNIX

455

!
pr_init

pr_fasttimo

200

500 ,
. , TCP
! .
pr_drain
!
!
.

!
. ,
.
,
.


. .

!
. 6.7.
6.7. pr_usrreq()

close(2)

accept(2)
bind(2)

listen(2)
send(2),
fstat(2)
getsockname(2)
ioctl(2)

PRU ABORT
ACCEPT
PRU BIND
PRU CONNECT
PRU LISTEN
PRU_SENSE
PRU SOCKADDR
PRU PEERADDR
PRU CONTROL

pr_input
pr_output
!


.
pr_ctlinput

pr_ctloutput

, !
mbuf: !
mbuf
, ,
, .

www.books-shop.com

456

6.

UNIX

pr_flags
, .
, ,
,


!
.

,
.
, !
.
, !
, .
, !
. 6.23. !
, .
, loopback
,
, . .

. 6.23.

www.books-shop.com

BSD
. !
. , !
, !
. , !
(broadcast) , ,
.
, !
,

if_init
if_reset

!
!
.
,
lags. . 6.8.
6.8.

IFF_BROADCAST

IFF_LOOPBACK

IFF_NOARP

IFF_UP !
. , !
(broadcast), , Ethernet,
IFF_BROADCAST !
(

). !

!,

(),
( ifa_dstaddr). ,
, a
ifa_dstaddr
. !
IFF_RUNNING
(!
, ), .

www.books-shop.com

458

6.

UNIX

!

$
inet

1500
netmask ffffffOO broadcast

, !

leO
i f _ f l a g s , if_mtu (Maximum
Transmission Unit, MTU) , !
,

inet
n e t m a s k
broadcast (ifa_broadaddr).
, !
. ,
(if_ipackets),
(if_ierrors),

(if_oerrors)
(if_collisions).
!
:
$

in

Name
leO

Mtu
823
1500

Net/Dest
127.0.0.0
194.85.160.0

Address
127.0.0.1

168761
1624636

0
1042

Opkts
168761
110166

Oerrs

1933

Collis

382604

!
, , !
.
, ,
. 6.24. !


, , !
(routing).
,
(, IP) !
.
,
, !
. !

, ! , !
, . , !
.

www.books-shop.com

BSD UNIX

459

!
(, Ethernet), !. !
, ,
, , !
! !

. 6.24. UNIX (internetwork)

(IP) !
, . !
, (
), 0. !
. ,
!
, ,
.
, . 6.25, !
(

, IP! .
, , !
, !,
. !
, ! !

, , ,
.

%RRNVVKRS

piracy@books-shop.com

460

6.

UNIX

). rt_dst. !
, rt_gateway, , !
, .
rt_flags ( ), !
. rt_use
, a rt_refcnt !
( ). , rt_ifp !
,
.

. 6.25. %

, !
(direct) (indirect).
rt_dst
. ,
, .
, !
,
, . !
, , !
, . ,
, , !
. !
.
,
, ,
,
,
. !
,
.

www.books-shop.com

BSD UNIX

. 6.26.

, !
Ethernet.
!
, !
: ""

,
.

. 6.26.

, , RTF_GATEWAY
. !
, !
,

!
: rtalloc
,
rtredirect
!

REDIRECT).

IP!
!
ARP (Address Resolution Protocol), !
.

www.books-shop.com

462

rtalloc
.

struct rtentry
struct

6.

UNIX


route,
:
*ro_rt



()

( ,
).
. , TCP
.
rtredirect

!

, !
.
, ,
,
, ,
. . 6.27.

. 6.27. %
%

TCP/IP

ICMP REDIRECT IP! !
IP! ()
.

www.books-shop.com

BSD

. , !
( 0), !
. , ,
, !

.

,
, ,
, . !
,
. , !
,
rt_gateway .
.
UNIX !
, .

,
. !
!
ioctl(2).

SIOCDELRT.
,
,
RIP (Routing Information Protocol)
,
!
(RIP, OSPF, BGP).
, !

$
Routing Table:
Destination
127
default

Gateway

Flags

Ref

Use

0
3
0

5054
30926
47150

Interface

(localhost)
.
( 194.85.160.50)
(194.85.160.0). ,
, , "
", ,

!
.

www.books-shop.com

464

6.

UNIX

TCP/IP

TCP/IP, ,
(Protocol Control Block, PCB), TCP/IP
Internet PCB, inpcb,

inpcb . 6.28.

. 6.28. TCP/IP
TCP UDP
, ,
IP! (inp_laddr

www.books-shop.com

BSD UNIX

465

TCP ,
, ( !
, . .)
,
TCP UDP.
, .
IP , !

,
,
().

BSD UNIX (. 6.29).

. 6.29. BSD UNIX

www.books-shop.com

466

6.

UNIX

IP
!
, !
.
,
IP. !
IP.
ip_input

. !


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

!
. IP Protocol
, , !


. IP !
pr_input

.
, , !
, , ,
.
(forwarding)
:

!

.


( IP). ,
SCO UNIX

www.books-shop.com

BSD UNIX
.
, ,

.
!
, , !
,
REDIRECT.
ip_output

!
.
IP
, ,
! . !
ICMP
. ICMP
. 6.9.
6.9. ICMP

DESTINATION UNREACHABLE



:

2.
3. ,

(Don't Fragment)

SOURCE QUENCH

. %
, %

%. :

2. % , . .
%

TIME EXCEEDED

, ( route, !
), (, !

). !

D (multicast) !
(Multicast backbone,
!
, !, . . ,
, .
,
, /.

www.books-shop.com

468

6.

UNIX

. , !
.
,
.


(UDP TCP). ,
.
UDP
,

, ( , IP)
. !
, !
UDP.
, IP!
UDP,
udp_input

.
!
. !
, "" .
.
!


,
/ .
,
. , ,
, !
, / . !
, , !
, ,

,
, .

PORT UNREACHABLE.

udp_input ,
!

().
, IP !
UDP.
.
" " !
inetd, !
( FTP Telnet). !
.

www.books-shop.com

BSD UNIX

469


sendto(2),
PRU_SEND. !

!
. send(2),
, !

, !
. !
ip_output

TCP, !
, UDP.
, .
, !
.
TCP .

, !
, !
. !
TCP , , !
500
.
(retransmit timer). !
, . !
, !
. , !
, . !
,
( ), !
, .
(timer backoff)
.


. , TCP,

.
.
!
, .

%RRNVVKRS

piracy@books-shop.com

470

6.

UNIX


( ). !
,
. , , !
( !
), (. . !
), .
( ),
,
, . !
( ),
(window probe), , .
, !
! , !
, . , !
, !
. ,
. !
, ! .
, ,

, !
, !
, , ! .
,
TCP keepalive,
( , ),
(RST). RST,
. , ,
.
,
(2MSL
). TCP
, , !
FIN. , !
.
FIN, !
. !
TIME!WAIT,
. , !
, close(2) , !
. ,
.

UNIX System V
BSD UNIX !
UNIX System V. !

www.books-shop.com

471

UNIX System V

.
UNIX System V STREAMS,
5.
/, STREAMS,
!
,
( ) ,
.
STREAMS , !
, .
STREAMS
: !
, . . 6.30 !
TCP/IP UNIX System V.
, , IP
, ,
( Ethernet
FDDI), (TCP
UDP), TCP UDP , !
,

FTP
a
! (

. 6.30. TCP/IP STREAMS


,
,
TCP/IP, ,

www.books-shop.com

6.

472

UNIX

!
. , !
,

!
.
!
(Transport Provider Interface, TPI). !
,
,
(Data Link Provider Interface,
, ,
STREAMS, , !
OSI. , !

, , .
.
TCP/IP

OSI

telnetd, talk
%*
TCP,

IP

FDDI

TPI

. 6.31. %
%

TPI
TPI
OSI
(connection mode), (connectionless
mode). !
,
, ,
.

,
OSI.
!
STREAMS.

www.books-shop.com

473

UNIX System V

TPI , !
.
, TPI !
(transport provider) (transport user).
(transport primitive),
, :

!

!
, . !

!
.


, .


.
6.10. TPI

BIND REQ

T_BIND_ACK

PROTO

.
%

.


, %
. %

.

ADDR_length

f set

, %

.
%
,
, %
%
.
M_PCPROTO, %
. ,
,
T_BIND_REQ.

M_PROTO :
T_BIND_ACK

f set

,

www.books-shop.com

6.

474

UNIX

()

UNBIND REQ

M PROTO

.


%

.

CONN REQ

M PROTO

.

.

%
.

M_DATA, %
, .
, TCP %
.

, .

:

DEST_length
%


offset

PROTO

CONN

M PROTO

.
%
%
, %
%
.

%
M_DATA,
,
.

,
, ,
.

:

SRC_length

OPT_length

OPT_offset

www.books-shop.com

475

UNIX System V

6.10 ()

.
%
%
, %
%
.

%

,
.
PROTO %
,
.

:
PRIM_type
,


OPT_length
f set

T_CONN_CON

.
%
%
.

.



, %
.
%
, %
, ,
, .

:
T_CONN_CON
RES_length

set

OPT_length

offset
PROTO

www.books-shop.com

6.

476

UNIX
6.10 ()

DISCON REQ

M_PROTO

DISCON IND

M_PROTO

ORDREL REQ

M_PROTO

ORDREL IND

M_PROTO

.

.


,
%
.

M_DATA, %
,
M_PROTO :
PRIM_type


.
%
%
, %
,
%
.
M_PROTO,

%
, .
M_PROTO :
T_DISCON_IND


"" .


, %
. %
, %

.
"" .
%
%

, , %
.

, %
. %
PROTO.

www.books-shop.com

477

UNIX System V

6.10 ()

REQ

M PROTO

.
%

%
%
.
M_PROTO,

%
.

, %
.

PRIM_type
DEST_length


PROTO

offset

M PROTO

.
%

, %

.



%
.

, ,
.

SRC_offset
OPT_length
offset


M PROTO

www.books-shop.com

6.

478

UNIX
6.10 ()

UDERROR




, %
%
.
%
, , ,
.

:
T_UDERROR_IND
DEST_length
DEST_offset


f set

ERROR_type

.


,

(Transport Interface Data Unit,

%
TSDU.


%
.
%

lag, ,

TSDU. %

TSDU. %


. ,
TCP .
.
%

, %
TIDU.
M_PROTO,



.

%
TSDU.

M PROTO

M_PROTO

www.books-shop.com

479

UNIX System V

6.10 ()

EXDATA REQ

M PROTO

.

%
.
TCP
t_snd(3N) flags,
T_EXPEDITED , ,
MORE.

EXDATA

M PROTO

.
T_DATA_IND,
.
.
%
, ,
, %
. ,
, %
% ,
. %
M_PCPROTO %

CORRECT prim.

ERROR ACK

M PCPROTO

.
,
, ,
. %
, %
,
, . %

%
, ,
TLI UNIX.
M_PCPROTO :
PRIM_type


TLI_error
TLI
UNIX error
UNIX

INFO REQ

M PCPROTO


.

%
,
. %
PCPROTO.

%RRNVVKRS

piracy@books-shop.com

480

6.

UNIX

6.10 ()
[

T_INFO_ACK

.


%
. %

%
, %
t_open(3N), "%

.
M_PCPROTO :
T_INFO_ACK
TSDU_size
%

TSDU
ETSDU_size
%

ETSDU
%
CDATA size
,
. %
connect
t_open(3N)
DDATA size

,
.

info

ADDR size

.
addr %

OPT size

. %
options

size
%
TIDU
SERV type

, %

servtype

info

t_open(3N)
CURRENT state

PROVIDER_flag

M_PCPROTO

www.books-shop.com

481

UNIX System V

6.10 ()

.

. %
M_PROTO,
:

OPT_length


,
:
T_NEGOTIATE ,
. %
,
,
;
_ , %
, %
, ;
T_DAFAULT
.
.
%
, %
.
,

REQ

OPTMGMT

PROTO

M PCPROTO

OPTMGMT REQ.



TPI.
TPI, .

TPI
TCP! . 6.32.
5 !
STREAMS. ,
,

getmsg(2). , , !
!
, ( ,
,

getmsg(2).

www.books-shop.com

482

6.

UNIX

. 6.32. TLI TPI



:

www.books-shop.com

UNIX System V

int

{
struct
struct
struct
struct
struct
struct
char
int

483

struct t_call *sndcall,


struct t_call

T_conn_con
T_ok_ack
T_error_ack
strbuf connect, ack, confirm,
netbuf
addr, opt, udata;

netbuf sndcall*/
addr =
opt =
udata =
strbuf

=
+
+ opt.len;
=
conn req) +
+
buf = (char
= buf;
(

M_PROTO

connreq = (struct T_conn_req
=
connreq>DEST_length =
connreq>DEST_offset = sizeof (struct
buf +=
=
=

buf +=
strbuf (
=
=
=
CONN REQ
&connect,


,


=
= (char
, RS HIPRI.

www.books-shop.com

484

6.

UNIX

flags = RS_HIPRI;

(struct

*)0,

okack = (struct T_ok_ack



if
==
{
/*

(
if (recvcall != NULL)
{
=
opt =
udata =
=

T_conn_con) +
=
+

T_conn_con)
+

buf = (char
= buf;
=
=
=

conncon = (struct T_conn_con


if
==
{
/* , rcvcall

=
=
offset,


}
}
else
{
/*

else

www.books-shop.com

UNIX System V

/*
errack = (struct T_error_ack

}
}

. ,
TCP
, !
.

T_DATA_IND. ,
T_EXDATA_REQ
UDP !

!
. !
,

, .
, !
.
!
, , , ,





.
(, !

) . STREAMS
ioctl(2).

"
STREAMS" 5,
TPI !


. . 6.33
.
STREAMS,
!

I_STR, . . .

, . .

! . M_IOCTL
TPI.

www.books-shop.com

6.

486

UNIX

ioctl(2) :
struct strioctl my strioctl;
=
=
= size;
= (char *)buf

. 6.33.

ioctl(2) s i z e !
TPI, cmd

www.books-shop.com

UNIX System V
,

cmd


T_BIND_REQ. %
ioctl(2) buf %

TI_UNBIND

TI_GETINFO

T_UNBIND_REQ. %


%
ioctl(2) buf %


%
ioctl(2) buf

.

DLPI
DLPI
(data link layer) OSI, !
, !
.
, IP, IPX
CLNS. , !
, !

(, Ethernet, FDDI ATM) !
.
DLPI
:
. !
, !
DLPI,
, TCP/IP, NetWare
!
.
. 6.34 !
. !
STREAMS,
DLPI (. .
DLPI).

www.books-shop.com

6.

UNIX

!
!
. , ,
, ,
. !
!
.

. 6.34.

(Service Access Point, SAP), !
STREAMS . !
, IP IPX, !
, ,
. !
SAP, , !
(DL_BIND_REQ) !
.
!
,
(Physical Point of Attachment, PPA).
DLPI . !
(style 1) ,
!
(
, !
, ,
(. "" 5). !

www.books-shop.com

489

UNIX System V

, (style 2)

!
, , !
,
(, ISDN D).
, DL_ATTACH_REQ, !
.
. 6.35.



DLPI


. 6.35.
DLPI ( !
),
:
1.
2.
3.

. ,

.
!
,
OSI
IEEE 802.
, !

%RRNVVKRS

piracy@books-shop.com

490

6.

UNIX

!
. IEEE 802 !
:
,

(Logical Link Control, LLC),
IEEE 802.2.
,
(Media
MAC), IEEE 802.3
CSMA/CD, IEEE 802.4 Token Bus
Token Ring.

!
Access Control,

IEEE 802.5


!
,
,
. !

, MAC.
CSMA/CD (Carrier
Sense Multiple Access with Collision Detection).
!
" ". ,
, !
. , ,
.
, !
.
, "" . !
CSMA/CD:
1. , , !
, "" .
2. , !
, !
, !
, .
!
, ,
.
CSMA/CD , ,
!

www.books-shop.com

UNIX System V

491

Ethernet 2.0 IEEE 802.3. !


Ethernet,
, . 6.36 6.37.

. 6.36. Ethernet

. 6.37. IEEE 802.3

,
" " (Ethertype) Ethernet !
IEEE 802.3. Ethernet
, . , !
1500
, .
, , !
, !
, , , !
(, Token Ring).
, , ,
"". !
, ""
. !
, !
. , ,
. !
.
, ""
. , .
FDDI, , , !
. !
,

www.books-shop.com

492

6.

UNIX

. ! ,
, !
. ,
, !
.
Token Ring IEEE
802.5

. IEEE 802.5 . 6.38.

. 6.38. IEEE 802.5


LLC
LLC .

HDLC, !
.
LLC . 6.39.
DSAP
(SAP)
. LLC !
SNAP (Sub!Network Access Point),
(Logical SAP, LSAP).

. 6.39. LLC

www.books-shop.com

UNIX System V

493

IP
CSMA/CD
IP LLC MAC.
Ethernet 2.O.

)
a SAP
" ",
Ethertype . IP !
0x0800. Ethertype
.

Ethertype
0x0800
0x0806
0x6003

Length IEEE802.3
Internet IP (Ipv4)
DEC DECNET Phase IV Route
Novell IPX

IEEE 802.3.


SAP !
SNAP Ethertype.
DSAP SSAP , !
. , IP!
1492 .
TCP/IP Token Ring
IEEE 802.5, LLC SNAP,
.


, ,
,
.
,
. 6.40.

!
:
!
. !

!

ig_t,
!
, ,
(Management
Information Base).
,
.

www.books-shop.com

494

6.

UNIX

. 6.40. DLPI
, :
ma j or

www.books-shop.com

UNIX System V

495


(SAP)

BOARD DISABLED

TX BUSY
TX QUEUED


. , %

, %

,

, , ,
SAP
.
:
state

read_q
write_q

bd
next_sap

spdu

SAP.
DLPI.
() SAP
, SAP
, SAP
, SAP

. :
DL_CMACD
IEEE 802.3
Ethernet 2.0
IEEE 802.4
IEEE 802.5
DL_HDLC
ISO HDLC
. %
DL CLDLS
:


ig_t,

SAP
,

www.books-shop.com

496

6.

UNIX

SAP flags, !
:
, SAP IEEE 802.3
, SAP LLC SNAP
PROMISCUOUS , SAP !
(promiscuous mode), SAP %
, %
. , , %

PRIVILEGED
, %

,
, ,
, .
!
ioctl(2).
:
ifOutOctets

ifOutErrors

,
,
(unicast)
(multicast) %
(broadcast)
,
(unicast)
(multicast) %
(broadcast)
,
, %
SAP
,
,

, !
.
(
STREAMS):

SAP, %
.
.

%
SAP

www.books-shop.com

UNIX System V

497
()

DLwput

xxput
. %
DLPI %
. ,
, ,
%



. ,
ioctl(2),

.
,
, ,
SAP. ( MAC)
,


),
. ,
%
SAP %
, . %
DLrecv
%
SAP (.
),
(} , %
,
SAP, .

DLrecv

.
, %
SAP. %
%
.

DLPI
,
,
DLPI. , !

. !
.
!
, !

. !, !
, !
. !,
(style 2),
, ,
,

www.books-shop.com

498

6.

UNIX

!
,
,
, , ,
!
( ). !
, !
, , , . ,
, !
. !
.
, DLPI,
.
.
.
6.12. DLPI
DLPI
DL_BIND_REQ

.
%
%
.
, %
,

. , , %
,
%
(
, ,

SAP,
, %
.

.
%
, %
SAP .

M_PCPROTO, ,
SAP.

www.books-shop.com

499

UNIX System V

6.12 ()
DLPI

DL ATTACH REQ

M_PROTO

%
.
(style 2) %
,
.

%
.

. ,
, .
, %

,

. %
, %
ISDN ( D) ATM
(
SVC
.
%
%
, %
DLPI,
.

.
%

DL_INFO_REQ .
M_PCPROTO, %
, :

,
.
( SDU .)

SDU.

%RRNVVKRS

piracy@books-shop.com

6.

500

UNIX

6.12 ()
DLPI

INFO ACK

DL

DL UNITDATA


DLSAP . ,
SAP %

( ).
f set
DLSAP
,
DLPI. .


.
!
.
,
DLPI.
!
(style 1 style 2).

.
!
DLSAP
REQ

M PROTO

.

%

.



.

,
, .

M PROTO

.

%
, %
.
M_PROTO,


%
. M PROTO %
.

www.books-shop.com

501

6.12 ()
DLPI

.

,
, ,

DL_OK_ACK %
, .
.
,
, ,
.

, , %
, %
, .

%
, ,
DLPI , ,
UNIX.

DL UDERROR IND

.


%
,


, .

UNIX. !
TCP/IP,

.
UNIX System V,
STREAMS.

, !
!
.

www.books-shop.com

502

6.

UNIX

TCP. ,

, , ,
. !
,
.
. !
,
, !
.
!
BSD UNIX UNIX System V. !
, !

,

.

www.books-shop.com



UNIX, ,

. ,
UNIX ,
,
.
, UNIX. !
man , !
. , $ man man,
.
, !
. , !
, (
, ) UNIX: BSD System V.




, %

%

, , ,
..

BSD UNIX

1
2
3
4

1
2
3
7

, !
, .
, Solaris 2.x !
" " :
$ man ! intro
,
. ,
passwd 1 (

) 4 (
, "SEE
ALSO" , !
.

www.books-shop.com



UNIX

. , .
UNIX .
. .: , 1992. , !
,
. !
, .
,
.
Bach M. The Design of the UNIX Operating System. Englewood Cliffs, NJ:
Prentice!Hall, 1986. !
UNIX. !
, , UNIX System V Release 2,
.
. , .

.
, 1986. UNIX
. 1982 ,
. , !
UNIX.
. .
.
, 1985.
man, !
. !
. !
, .
S., McKusick M.K., Karels M.J.,
J.S. The Design and
Implementation of the
UNIX Operating System. Reading, MA:
1989.
. !

UNIX. !
UNIX " ".

www.books-shop.com

505

Vahalia, U. UNIX Internals: the New Frontiers.


River, NJ:
Prentice Hall, 1996. !
UNIX (SVR4.X, Solaris,
Digital UNIX, 4.4BSD, Mach
!
UNIX.
Pate S.D. UNIX Internals. A Practical Approach. Addison Wesley Longman
Ltd., 1996. Santa Cruz Operation,
Inc. UNIX.
UNIX SCO

. !

UNIX.
Stevens, W.R. Advanced Programming in the UNIX Environment. Reading,
MA:Addison!Wesley, 1992. !
UNIX.

.
Stevens, W.R. UNIX Network Programming. Englewood Cliffs, NJ: Prentice
Hall, 1990.
.
.

Internet
UNIX

The Open Group,
UNIX,
, !
. ,
Report,
.
Santa Cruz Operation, Inc.

!
UNIX SCO OpenServer SCO UnixWare, !
, !
SCO. ,
OpenServer UnixWare . !
!
.
Silicon Graphics, Inc.
!
, !

www.books-shop.com

506

UNIX

Silicon Graphics, .

UNIX, IRIX. !
Silicon Graphics !
.
DIGITAL UNIX

Digital Equipment Corporation


DIGITAL UNIX, !
Alpha. !
, !
DIGITAL UNIX,
.
RS/6000 (http://www.rs6000.ibm.

, IBM
UNIX AIX 4.x !
, .
Berkeley Software Design, Inc.

BSDI, !
. !
,
.
UNIX,
.
FreeBSD

, FreeBSD.
, !
.
BSD UNIX .
,
Internet, . !
, !
.
OpenBSD

OpenBSD, !
OpenBSD, UNIX

OpenBSD 2.1 2
1997 . ,
.
NetBSD
, !
BSD UNIX. !
, , !

www.books-shop.com

Internet

507

, , !
.
for Users
!
UNIX, , !
. !
, !
. UNIX,
. online!
,
!
.
World Online
!
Sun Microsystems
, !
, Solaris UNIX !
, , !
.
( . .).
UnixWorld

UnixWorld,
,

UNIX.
Solaris (http://zaphod.cs.uni
sb.de/Corner/soIaris2.html). , !
" " .
FreeBird (http://www.freebird.org).
SCO UnixWare,
UNIX. !
man, !
, !
, UNIX .
Unix Guru Universe

UNIX.
, , !
, , UNIX,
.
UNIX (http://wwwhost.cc.utexas.edu/cc/services/unix/index.html).
, !

(Academic Computing and Instructional Technology Services). Ha


!

www.books-shop.com

UNIX

, ,
, , .
(http://voyager.crrel.usace.army.mil/~pete/security.html).

UNIX, !

.
CERT

!
CERT (Computer Emergency
Team).
CERT,
, , !
.
SCO UNIX (http://www2.sco.
!
SCO
UNIX. SCO UNIX.
UNIX Vault
!
Internet,
UNIX.

!
UNIX , !
.
,
UNIX.
SCO
!
OLLY !
, ,
Santa Cruz Operation, Inc., !
ftp.sco.com.
UNIX (http://pluto.xTech.
RU/Russian/UnixDoc/).
. " !
UNIX", M. " Linux ",
man.

www.books-shop.com

, 143

, 269
, 398
IP, 389; 398
MAC, 389

394
(), 180
, 199
, 316
, 161
, 42; 154
, 323; 369
, 338
335


, 204
, 204
219
, 51

,
!, 151
, 312
, 316

3
, 80
, 230
290

/
, 18
, 66
, 132
128
UNIX
BSD UNIX, 7
System III, 6
System V, 6
System V Release 4, 7
8
, 18; 197
, 293
, 28; 140
, 313
, 216
, 199
, 187

, 288
, 173; 237
, 51

,
53
, 53
, 147
, 20; 282
, 293

281

DLPI, 487
!
, 488
, 488
TLI, 426
TPI, 472
, 473
, 47
, 16

, 128; 242
,
, 20; 26; 142
, 142
s5fs, 285
,
, 56

, 73
, 73

%RRNVVKRS

piracy@books-shop.com


, 82
, 60
, 64
, 64
, 71

, 63
, 63
, 184
, 80
, 57
, 65
, 74

, 69
, 69
, 77
, 264

, 454
, 325
, 298
, 221

, 459
, 460
, 386; 394; 458
, 458
, 399
, 20; 144; 282
, 8
OSI, 391

, 387
, 387
, 387

, 490
,
490

, 154; 156; 227

,
207
, 95
,
, 177; 287
, 177
, 177

,
, 416; 418
, 295; 297
, 218

!, 151
, 197
, 199
, 150
,
207
, 258
, 198; 404
, 202; 198
, 52
, 54
, 115

STREAMS, 350
, 370
, 356
IP, 466
TCP, 469
485
UDP, 468
, 378
, 373
, 357
, 361
/, 18
18
, 18

, 55
, 51
, 51
, 389; 401
, 140
, 32
, 30
, 222

IP, 389; 393


, 493
LLC, 492
TCP, 404
, 406
" ", 414
, 416
,
, 420

www.books-shop.com

511

UDP, 402

383; 464
, 386
, 405
, 464
, 38
, 197; 204
, 41
EUID, 41
Nice Number, 41
41
41
41
41
, 189
, 189; 233
, 189
, 18; 216
, 173; 237
,
154
, 193; 236
, 147
, 221
, 194; 221
, 241
, 177

115
, 222
, 86; 223
, 223
, 223
42; 154
, 154; 226
, 191
,
, 86
, 348
, 348
, 348
, 20

, 280
, 258
, 42; 154

, 199; 211
, 199

, 22; 134
, 22

, 173
, 198
, 199
, 253
, 260
, 456

SIGBUS, 138
SIGALRM, 220
SIGCHLD, 158
SIGHUP, 175
SIGINT, 160; 175
46; 161
160; 175
SIGSTOP, 161; 195
SIGSTP, 175
SIGTERM, 46
175; 195
175; 195
217
, 161
, 238
, 167
, 166
, 160; 166
, 237

FIFO, 22; 243


, 245
, 128; 242
, 265
, 258
, 253
, 248; 357
, 277

183
, 16; 94
421
220
269; 421
143
141
140
143
271
124
125
125
exec(2), 42, 230
exit(2),
235
143

www.books-shop.com

512

141
140
143
129
42, 226
363; 371
173
getpgrp(2),
380; 463; 485
140
134
421
126
243
250
249
msgrcv(2), 250
250
122
128; 242
363; 370
126; 314; 363
273; 421
recvfrom(2), 273
255
semop(2), 255
273; 421
273
149
149
149
149
shmat(2), 259
260
259
166
socket(2), 266
144
316
134
134
229
158
127; 314; 363
127

, 121
, 97
, 57
, 25; 264; 453
, 274
, 420
, 265
, 234
, 248
, 251

11
IEEE 802.3, 491
10
11
XPG3, 11
, 202
,

345
281
427
149
207; 229
proc, 190
queue, 356
region, 207; 229
167
168
334
, 335
stat, 144
user, 190
vfs, 297
294
, 281
, 51

, 200
, 458
, 469
, 217
, 142
, 346
, 347
, 347
, 39

, 325
, 488

www.books-shop.com

513

, 298
, 488

(RPC), 440
, 441
, 444
, 410
, 442
, 445
, 444

, 80
, 364
, 86
, 174; 237
, 342
, 22; 340
, 48; 325
, 22

87
84
86
29
86
29; 86
cmp, 82
cp, 83
cut, 85
83
83
file, 86
find, 85
321
57;

349
83
head, 84
kill,
ld(l), 106
In, 83
57; 149; 349
83
83
84
83
nice, 86
84
ps, 87
re
86
83
83

84
to//, 84
85

, 20
BSD
288
System V, 280
specfs, 333
, 293
, 296
, 26
,
, 307
, 123; 306
, 130
, 20

, 35; 141
Sticky bit, 36
36
36
, 309
311
310
, 130
28; 140
, 285
, 143, 303
, 143; 303
, 303
, 30
, 20; 144; 282
,
, 47
,
22; 47

COFF, 112; 205


ELF, 108; 205
, 107
, 491
, 394

atexi1(3C), 120
152
153
152
275

www.books-shop.com

514
152
164
syslog(3), 183
t_accept(3N), 432
431
1_close(3N), 433
431
432
t_look(3N), 439
429
t_rcv(3N), 433
t_rcvrel(3N), 438
433
433
438
433

114

I
IEEE 802.3, 491
IP, 389

M
3

P
PDU, 389
10
Programmer's

R
440

, 387

A
ANSI, 11

COFF, 112; 205


Computer Research Group, 5

s
Sticky bit, 36
426; 471
11

TCP, 404
TCP/IP, 383; 464

E
ELF, 108; 205
Ethernet, 491

UDP, 402
UNIX System Group, 4

FIFO, 22; 243


, 244

XPG3, 11

www.books-shop.com

Вам также может понравиться