Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linux/UNIX Programming APUE (Introduction) 문양세 강원대학교 IT 대학 컴퓨터과학전공.

Similar presentations


Presentation on theme: "Linux/UNIX Programming APUE (Introduction) 문양세 강원대학교 IT 대학 컴퓨터과학전공."— Presentation transcript:

1 Linux/UNIX Programming APUE (Introduction) 문양세 강원대학교 IT 대학 컴퓨터과학전공

2 UNIX System Programming by Yang-Sae Moon Page 2 APUE 강의 목적 UNIX 시스템 프로그래밍 파일, 프로세스, 시그널 (signal), 네트워크 프로그래밍 UNIX 시스템의 체계적 이해 시스템 프로그래밍 능력 향상 APUE (Introduction)

3 UNIX System Programming by Yang-Sae Moon Page 3 APUE 강의 동기 UNIX 는 인기 있는 운영체제 서버 시스템 ( 웹 서버, 데이터베이스 서버 ) 공학 및 상업용으로 응용되고 있음 연구 개발 용으로도 많이 사용됨 ( 특히, Sun 의 경우 학교 ( 미국 등 ) 에서 애용함 ) 최근 리눅스가 임베디드 시스템 및 모바일 디바이스에 많이 활용되고 있음 시스템 프로그래밍 OS 자원을 이용한 프로그래밍 Unix 시스템 호출 사용 파일, 프로세스, IPC, 네트워킹, … DBMS, compiler, groupware, debugger, … APUE (Introduction)

4 UNIX System Programming by Yang-Sae Moon Page 4 UNIX 시스템 구조 Hardware CPU, Memory, Disk, Peripherals Kernel Process Management File Management Memory Management Device management System Call The programmer's functional interface to the UNIX kernel Commands, Utilities, Application programs Kernel services using library routines or system calls APUE (Introduction)

5 UNIX System Programming by Yang-Sae Moon Page 5 시스템 호출 (System Calls) (1/2) APUE (Introduction) Process System call interface File ManagementIPCProcess Management

6 UNIX System Programming by Yang-Sae Moon Page 6 Application programs talk to the operating systems via system calls. The programmer's functional interface to the UNIX kernel. APUE (Introduction) 시스템 호출 (System Calls) (2/2)

7 UNIX System Programming by Yang-Sae Moon Page 7 User Mode vs. Kernal APUE (Introduction) Kernel Address of kernel open() Address of kernel write() Address of kernel close() kernel code for open() {... } Kernel system call code open(char *name, int mode) { <Execute trap instruction, switching to kernel code > } User process C runtime library User code result=open(“file.txt”, O_RDONLY);

8 UNIX System Programming by Yang-Sae Moon Page 8 System Calls & Library Functions (1/2) System Calls Well defined entry points directly into the kernel Documented in section 2 of the UNIX man pages (/usr/man/man2) Look like C functions which can be called from a user's program – just need to include the appropriate header 예 ) read(), write() Library Functions The library function is often more elaborate than the system call, and usually invokes the system call (System call 보다는 좀 더 사용하기 쉽고 편리하게 제작 ) 예 ) fprintf(), fscanf() APUE (Introduction)

9 UNIX System Programming by Yang-Sae Moon Page 9 System Calls & Library Functions (2/2) APUE (Introduction) application code C library functions system calls hardware (hard disk…) user process kernel

10 UNIX System Programming by Yang-Sae Moon Page 10 C I/O Library Functions 표준 입력 함수 (standard input function) scanf(), getchar() 표준 출력 함수 (standard output function) printf(), putchar() 표준 파일 입력 함수 fscanf(), fgets(), fgetc() 표준 파일 출력 함수 fprintf(), fputs(), fputc() APUE (Introduction)

11 UNIX System Programming by Yang-Sae Moon Page 11 파일 입출력 (1/2) 파일 입출력 과정 파일 열기, 읽기 / 쓰기, 파일 닫기 파일 열기 : fopen #include FILE *fp; fp=fopen(" 파일 이름 ", " 입출력방식 "); 입출력 방식 r: 읽기 전용 w: 쓰기 전용 a: 추가 (append) 수록 r+: 읽기쓰기겸용 w+: 쓰기읽기겸용 a+: 읽기추가겸용 APUE (Introduction)

12 UNIX System Programming by Yang-Sae Moon Page 12 파일 입출력 (2/2) 파일 입력 함수 fscanf(), fgets(), fgetc() 열린 파일에서 내용을 읽어 들이는 함수 파일 출력 함수 fprintf(), fputs(), fputc() 열린 파일에 내용을 기록하는 함수 파일 닫기 fclose() APUE (Introduction)

13 UNIX System Programming by Yang-Sae Moon Page 13 파일 출력 예제 (fgets.c) (1/2) APUE (Introduction)

14 UNIX System Programming by Yang-Sae Moon Page 14 파일 출력 예제 (fgets.c) (2/2) APUE (Introduction)

15 UNIX System Programming by Yang-Sae Moon Page 15 파일 입출력 예제 (fcopy.c) (1/2) APUE (Introduction)

16 UNIX System Programming by Yang-Sae Moon Page 16 파일 입출력 예제 (fcopy.c) (2/2) APUE (Introduction)

17 UNIX System Programming by Yang-Sae Moon Page 17 시스템 프로그래밍 준비 APUE (Introduction) 에디터 컴파일러 디버거 make We already knew “vi”. We may use “cc” or “gcc” You should learn either “gdb” or “dbx”. We already learned about “make” and “Makefile”.


Download ppt "Linux/UNIX Programming APUE (Introduction) 문양세 강원대학교 IT 대학 컴퓨터과학전공."

Similar presentations


Ads by Google