10.
10.1
10.2 Library Routine: void perror (char* str) perror( ) str Error 0
10.3
10.3 int fd; /* */ fd = open (filename, ) /*, */ if (fd = = -1) { /* */ } fcnt1 (fd, ); /* */ read (fd, ); /* */ write (fd, ); /* */... lseek close (fd) ; (fd, ); /* */ /*, */
10.3
10.3 fd1 fd2 fd3
10.3»»»»»
10.3
10.3 fd System call: int open (char* filename, int mode, [int permission])»»»
10.3»»»»»»»»
10.3»»» sprintf (tmpname,.rev.%d, getid( ) ); /* */ /* */ tmpfd = open (tmpname, O_CREAT O_RDWR, 0600); if (tmpfd == -1) fatalerror ( );»»» fd = open (filename, O_RDONLY); if (fd == -1) fatalerror ( );»
10.3 System call: int read ( int fd, char* buf, int count )» charsread = read (fd, buffer, BUFFER_SIZE); if (charsread = = 0 ) break; / * */ if (charsread = = -1) fatalerror ( ); / * */
10.3 System call: int write ( int fd, char* buf, int count )»» /* */ if (standardinput) { charswritten = = write (tmpfd, buffer, charsread ); if (charswritten! = charsread) fatalerror ( ); /* */ }
» 10.3 System call: long lseek ( int fd, long offset, int mode )»» lseek (fd, linestart[i], L_SET); /* */ charsread = read (fd, buffer, linestart [i+1] - linestart [i] ); /* = - */
10.3 System call: int close ( int fd ) System call: int unlink ( char* filename )
10.3
10.3 Utility: monitor [ -t delay ] [ -c count ] { filename }+»»»»»»
10.3»»»»»»»
10.3 System call: int stat ( char* name, struct stat* buf ) int fstat ( int fd, struct stat* buf )»»
10.3
10.3»»
10.3 System call: int readdir(dir *df)»
10.3
10.3
10.3 System call: int chown ( char* filename, int ownerid, int groupid ) int fchown ( int fd, int ownerid, int groupid )»»»»»»
10.3 System call: int chmod ( char* filename, int mode ) int fchmod ( int fd, int mode )»»
10.3 System call: int dup ( int oldfd ) int dup2 ( int oldfd, int newfd )»»»
10.3 System call: int fcntl ( int fd, int cmd, int arg)»»
10.3»
10.3 System call: int ioctl ( int fd, int cmd, int arg)»» System call: int link ( char* oldpath, char* newpath )»»»»
10.3 System call: int mknod ( char* filename, int type, int device )»
10.3 System call: int sync ( )» System call: int truncate ( char* filename, long length ) int ftruncate (int fd, long length )»»»»
10.4
10.4 부모 (init, PID=1) 자식 (getty, PID=4) 로그인처리 자식 (getty, PID=5) 로그인처리 자식 (getty, PID=6) 로그인처리
10.4 부모프로세스 (PID=34) 셸실행 부모프로세스 (PID=34) 셸실행자식프로세스기다림 자식프로세스 (PID=35) 셸실행 : exec() :wait() 자식프로세스 (PID=35) 유틸리티실행 부모프로세스 (PID=34) 셸실행깨어남 : exit() 자식프로세스 (PID=35) 종료
10.4 1 or (sleep) 2 3 4 (wake up),
10.4
10.4
10.4 System call: fork ( ) System call: int getpid ( ) int getppid ( )
10.4 System call: int exit (int status )
10.4 System call: int wait (int* status )»»»»»»»»
10.4 System call: int execl( char* Path, char* arg0,...char* argn, NULL ) int execv( char* Path, char* argv[ ] ) int execlp(char* Path, char* arg0,...char* argn, NULL) int execvp(char* Path, char* argv[ ] )»»»»»
10.4 System call: int chdir ( char* pathname )»
10.4» System call: int nice ( int delta )»»
10.4»»» System call: int getuid ( ) int geteuid( ) int getgid ( ) int getegid( )»»
10.4»»»» System call: int setuid (int id ) int seteuid (int id ) int setruid (int id ) int setgid (int id ) int setegid (int id ) int setrgid (int id )»»»
10.4 ls > ls.out»»»»»»
10.5»»»
10.5»»»»»»»»
10.5»»»» Library Routine: unsigned int alarm (unsigned int count)»»
10.5»»»»»» System call: void (*signal ( int sigcode, void ( *func) ( ) ) )( )
10.5» System call: int pause ( )
10.5»» System call: int kill ( int pid, int sigcode )»»»»»»»»
10.5»»» System call: int getpgrp ( int pid )»»
10.5»» System call: int setpgrp ( int pid, int pgrpid )»»
10.6
10.6 System call: int pipe ( int fd [ ] )»»»»»
10.6» A B C D E
10.6»»»»»»
10.6»»»»»»»