슬라이드 1

Similar documents
Microsoft PowerPoint APUE(File InO).ppt

Microsoft PowerPoint APUE(File InO)

Microsoft PowerPoint APUE(File InO).pptx

Microsoft PowerPoint - chap2

제1장 Unix란 무엇인가?

제12장 파일 입출력

로봇SW교육원 강의자료

로봇SW교육원 강의자료

untitled

Microsoft PowerPoint - chap12 [호환 모드]

제1장 Unix란 무엇인가?

2009년 상반기 사업계획

10.

<4D F736F F F696E74202D FC6C4C0CF20C0D4C3E2B7C2205BC8A3C8AF20B8F0B5E55D>

chap7.key

PowerPoint 프레젠테이션

Microsoft PowerPoint - Lecture 4-1 Linux File Environment.ppt [호환 모드]

Microsoft PowerPoint - ch09_파이프 [호환 모드]

2009년 상반기 사업계획

PowerPoint 프레젠테이션

Microsoft PowerPoint - 09_FileSystem

PowerPoint 프레젠테이션

6주차.key

PowerPoint 프레젠테이션

<4D F736F F F696E74202D20B8AEB4AABDBA20BFC0B7F920C3B3B8AEC7CFB1E22E BC8A3C8AF20B8F0B5E55D>

슬라이드 1

歯9장.PDF

<4D F736F F F696E74202D FB8DEB8F0B8AE20B8C5C7CE205BC8A3C8AF20B8F0B5E55D>

Microsoft PowerPoint - 09-Pipe

2009년 상반기 사업계획

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Microsoft PowerPoint - lab14.pptx

/chroot/lib/ /chroot/etc/

슬라이드 1

2007_2_project4

PowerPoint 프레젠테이션

Microsoft PowerPoint - 알고리즘_4주차_1차시.pptx

Microsoft PowerPoint - IOControl [호환 모드]

Chapter #01 Subject

KEY 디바이스 드라이버

슬라이드 1

1장. 유닉스 시스템 프로그래밍 개요

ABC 11장

휠세미나3 ver0.4


C++-¿Ïº®Çؼ³10Àå

Chap06(Interprocess Communication).PDF

3. 다음그림은프로세스의 file table 과 v-node 테이블의연결관계예제이다. 위그림을참고하여두개의서로다른프로세스가같은파일을 open 명령을사용하여열었을때의연결관계를도시하시오. 4. 메모리영역은 low-address 부터 high-adress 까지순서대로나열했을

Microsoft Word - Network Programming_NewVersion_01_.docx

Microsoft Word - MPC850 SPI Driver.doc

T100MD+

Computer Programming (2008 Fall)

BMP 파일 처리

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

PowerPoint 프레젠테이션

학번 : 이름 : 1. 다음파일트리구조를가진유닉스시스템이있다고가정하자. / /bin/ /home/ /home/taesoo/ /usr/ /usr/lib/ /usr/local/lib /media 모든폴더에파일이하나도없다고가정했을때사용자가터미널에서다음 ls 명령입력시화면출력

Microsoft PowerPoint - chap6 [호환 모드]

06Àå

Microsoft PowerPoint - Lecture_Note_2.ppt [Compatibility Mode]

2009년 상반기 사업계획

11장 포인터

PowerPoint 프레젠테이션

K&R2 Reference Manual 번역본

untitled

Motor

Microsoft PowerPoint APUE(Intro).ppt

Microsoft PowerPoint - chap9 [호환 모드]

ECE30076 Embedded System Programming - LED Device Driver

금오공대 컴퓨터공학전공 강의자료

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -


SRC PLUS 제어기 MANUAL

이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다. 2

MPLAB C18 C

6.24-9년 6월

chap10.PDF

PowerPoint 프레젠테이션

1217 WebTrafMon II

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CBED0C3E0C7C1B7CEB1D7B7A55C4C656D70656C2D5A69762E637070>

13주-14주proc.PDF

고급 IPC 설비

Microsoft PowerPoint - o8.pptx

PowerPoint 프레젠테이션

untitled

Embeddedsystem(8).PDF

various tricks for remote linux exploits v3.pptx

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

PowerPoint 프레젠테이션

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3

UniStore

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾

int main(void) int a; int b; a=3; b=a+5; printf("a : %d \n", a); printf("b : %d \n", b); a b 3 a a+5 b &a(12ff60) &b(12ff54) 3 a 8 b printf(" a : %x \

Microsoft PowerPoint - 제11강 파일 처리

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

, ( ),, ( ), 3, int kor[5]; int eng[5]; int Microsoft Windows 4 (ANSI C2 ) int kor[5] 20 # define #define SIZE 20 int a[10]; char c[10]; float

교육지원 IT시스템 선진화

Transcription:

/ 유닉스시스템개요 / 파일 / 프로세스

01 File Descriptor file file descriptor file type unix 에서의파일은단지바이트들의나열임 operating system 은파일에어떤포맷도부과하지않음 파일의내용은바이트단위로주소를줄수있음 file descriptor 는 0 이나양수임 file 은 open 이나 creat 로 file descriptor 가새로할당되고, read, write 할때이를이용함 user 가생성하는첫번째파일의 file descriptor 는 3 임 regular file : 0 이상의 data block 을가진일반적인파일 directory : 파일과파일이름을 mapping 시켜주는파일 special file : physical device 를 file system 에 mapping link : 파일을다른이름으로연결 symbolic link : 다른파일을가리키는파일 named pipe(fifo) : process 간의통신을위한파일

01 File Descriptor file descriptor all open files are referred to by file descriptors how to obtain file descriptor return value of open( ), creat( ) when we want to read or write a file, we identify the file with the file descriptor file descriptor is the index of user file descriptor table STDIN_FILENO(0), STDOUT_FILENO(1), STDERR_FILENO(2) (<unistd.h>)

01 File Descriptor file descriptor (cont d) standard input, output, error STDIN_FILENO ( == 0) STDOUT_FILENO ( == 1) STDERR_FILENO ( == 2) defined in <unistd.h> opened by the shell not by the kernel

1. open( ) synopsis #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode);

1. open( ) description attempts to open a file and return a file descriptor flags (defined in <fcntl.h>) O_RDONLY, O_WRONLY or O_RDWR access mode O_CREAT If the file does not exist it will be created O_EXCL When used with O_CREAT, if the file already exists it is an error and the open will fail

1. open( ) int fd; fd = open( /etc/passwd, O_RDONLY); fd = open( /etc/passwd, O_RDWR); fd = open( ap, O_RDWR O_APPEND); fd = open( ap, O_RDWR O_CREAT O_EXCL, 0644);

1. open( ) synchronization #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #define LOCKFILE "lockfile" #define DELAY 10000000 void delay(void) { int i; for (i = 0; i < DELAY; i++); }

1. open( ) int main(void) { int fd, i; while ((fd = open(lockfile, O_WRONLY O_CREAT O_EXCL, 0644)) < 0) { if (errno!= EEXIST) { perror("open"); exit(1); } } for (i = 'a'; i <= 'z'; i++) { putchar(i); fflush(stdout); delay(); } close(fd); unlink(lockfile); return 0; } [comeng:/export/home/prof/yshin/lec/3 5 ] a.out abcdefghijklmnopqrstuvwxyz

2. lseek( ) synopsis #include <sys/types.h> #include <unistd.h> off_t lseek(int fildes, off_t offset, int whence); description repositions the offset of the file descriptor fildes to the argument offset

2. lseek( ) whence SEEK_SET access mode SEEK_CUR The offset is set to its current location plus offset bytes. SEEK_END The offset is set to the size of the file plus offset bytes.

2. lseek( ) hole allows the file offset to be set beyond the end of the existing end-of-file of the file If data is later written at this point, subsequent reads of the data in the gap return bytes of zeros return value success : the resulting offset location as measured in bytes from the beginning of the file error : -1

2. lseek( ) off_t curpos; curpos = lseek(fd, 0, SEEK_CUR); lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_END); lseek(fd, -10, SEEK_CUR); lseek(fd, 100, SEEK_END);

2. lseek( ) #include <unistd.h> #include <fcntl.h> int main(void) { int fd; fd = creat("holefile", 0644); write(fd, "hello", 5); lseek(fd, 10, SEEK_CUR); write(fd, "world", 5); lseek(fd, 8192, SEEK_SET); write(fd, "bye", 3); } close(fd); return 0;

2. lseek( ) result $ ls -l holefile -rw-r--r-- 1 kim stud 8195 Jul 18 21:37 holefile $ od -c holefile 0000000 h e l l o \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 w 0000020 o r l d \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 0000040 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 * 0020000 b y e 0020003 $ du holefile 8 holefile

3. read( ) synopsis #include <unistd.h> ssize_t read(int fd, void *buf, size_t count); description attempts to read up to count bytes from file descriptor fd into the buffer starting at buf

3. read( ) If count is zero, read() returns zero and has no other results return value On success, the number of bytes read zero indicates end of file On error, -1 is returned

4. write( ) synopsis #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); description writes up to count bytes to the file referenced by the file descriptor fd from the buffer starting at buf

4. write( ) return value the number of bytes written zero indicates nothing was written On error, -1

5. read() & write() #include <unistd.h> #define BUFFSIZE 8192 int main(void) { int n; char buf[buffsize]; while ((n=read(stdin_fileno,buf,buffsize))>0) if (write(stdout_fileno,buf,n)!=n) printf("write error\n"); } if (n<0) exit(0); printf("read error\n");