Unix Programming Lecture 01

Download Unix Programming Lecture 01

Post on 13-Nov-2014

544 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

<p> OS UNIX .</p> <p> 1 UNIX , . 1.</p> <p>. 1. UNIX (kernel). , . , . / (, , ), , . , , , , UNIX. , , . : , . . . , . . , . (open), (read) (close) , (2), read(2) close(2) . int fd; char buf[80]; fd = open("file", O_RDONLY); /*O fd*/</p> <p> OS UNIX .</p> <p>read(fd, buf, sizeof(buf)); /* buf 80 */ close(fd); /* */ 2.</p> <p>. 2. UNIX : 1. 2. 3. / , , . (2), read(2), write(2) , . , , / . ( ), . , , /. ( ). : (, ) , </p> <p> OS UNIX .</p> <p> . , . , (scheduler), (, , /). , , . , /, . . . , , , " ". , ( , ), . : , . . . / / (, , . .). , .</p> <p> UNIX UNIX , . , , , CD-ROM, , , . UNIX "" , , . , , , , UNIX, . UNIX (), (file system). , . (root directory), "/". (), , . UNIX , "/". , </p> <p> OS UNIX .</p> <p> "/" ( , CD-ROM ), . ( mode), , : , , . , . , . UNIX 6 , : (regular file) (directory) (special device file) FIFO (named pipe) (link) , . . , . , , . . . . , , , . , . , , , . . 3 . , . ( mode), .</p> <p>17374 12838 34324 /home/user 43454</p> <p>. .. file01 file02</p> <p> inode</p> <p> OS UNIX .</p> <p>. 3. . UNIX (character) (block) . , . , . , . FIFO , . FIFO SystemV UNIX, . . , . , . . , , , , . (hard link). , 1(1) , file01 (. 3). $ In file01 /home/user/file02 , , , . . , (first second) , . . ( ). , . , . , , , , . , . , , . 1(1) -s : $ In s file01 /home/user/symfile01 , . .</p> <p> OS UNIX .</p> <p> . TCP/IP. , BSD UNIX , , , . UNIX : (user owner) (group owner). , - , . . , . , , , . Is -/. - -, : 1 2 3 4 5 6 7 8 rw- r-- r-- 1 andy group 235520 Dec 22 19:13 pride,tar rw- rwr r-- 1 andy student 3450 Nov 12 19:13 exams, quest - , . chown(l), - chgrp(l) - , . , . , ( ), , , ( ) . UNIX , : User access Group access Other access (u) (g) , () ( )</p> <p>UNIX : Read (r) Write (w) Execute () (superuser) . chmod(l). .</p> <p> OS UNIX .</p> <p> . , . ( ) , . (, ) "" , . , (. . ) cd (1). . , , , . r x , r, . , , "" , , , . , , (FTP-), "", . . , , , . , . , , - , , . , , . , , Sticky bit . , . , - . chmod(l). 1. t Sticky bit S Set UID, SUID DID S Set GID, SGID GIO 1 </p> <p> OS UNIX .</p> <p> Sticky bit ( save text mode) UNIX . (, ). (. . ) , . ( ) SUID SGID , . ( ) . , . SUID SGID , . , , , , , . SUID - , SGID . , , . , , , / , . ( ) . , . , , . , . , . UNIX . . . . , , , . : shed ( ), vhand ( ), bdfflush ( ) kmadaemon ( ).</p> <p> OS UNIX .</p> <p> init, UNIX. init , (/etc/init), . - , ( ), . UNIX: , , . . . , , . , . , , . , ls(l) . (login shell), UNIX. , login shell . , , ( ) . . : , , . , . shell, , . , ps(l). ps(l) , shell. UNIX , . 1. Process ID (PID) PID, . 2. Parent Process ID (PPID) , . 3. (Nice Number) , . , , .</p> <p> OS UNIX .</p> <p> (TTY) (RID) (EUID) , . ( ). , . . , , . , SUID, , (, ). , (RGID) (EGID) , . . , ( SGID). ps(l) (process status) , , . UNIX fork(2). , fork(2) , . , . , , fork(2). , PID. , . , . . , (2). , . , , /, , . UNIX , , fork(2), , (2), . . 1. , ( shell) ls(l). 2. (shell) fork(2), shell. 3. , shell (2), , shell. 4. ls(l) shell, ls(l) . 5. ls(l) "". .</p> <p> OS UNIX .</p> <p> . 4.</p> <p>. 4. fork-and-exec. , fork(2) (2). . UNIX fork(2). fork-and-exec, (2). "" init(lM), . " " , , init(lM). - . . , , . , 0, SIGFPE, , +, SIGINT. kill(l): kill sig_no pid sig-no , a pid , .</p> <p> OS UNIX .</p> <p> , , . : 1. . , , , 0 , . 2. . , . 3. , . , SIGINT , , "". , SIGKILL SIGSTOP , . kill(l) 15 SIGTERM, , . SIGTERM. SIGKILL(9) , : $ kill -9 pid , . : -. , , . , , . , NFS (Network File System), , , . , SIGINT SIGQUIT. , , , . , , . . , , . , . , . , , . (raw interface).</p> <p> OS UNIX .</p> <p> , . , , . , , . . /etc/passwd. , , (). , . , /etc/shadow. , /etc/group , . , /etc/passwd. , /etc/passwd . (, ), /etc/passwd , .</p>