Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linux/UNIX Programming

Similar presentations


Presentation on theme: "Linux/UNIX Programming"— Presentation transcript:

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

2 APUE 강의 목적 Linux/Unix 시스템 프로그래밍 Linux/Unix 시스템의 체계적 이해 시스템 프로그래밍 능력 향상
APUE (Introduction) Linux/Unix 시스템 프로그래밍 파일, 프로세스, 시그널(signal), 네트워크 프로그래밍 Linux/Unix 시스템의 체계적 이해 시스템 프로그래밍 능력 향상

3 APUE 강의 동기 Linux/Unix는 인기 있는 운영체제 시스템 프로그래밍 서버 시스템(웹 서버, 데이터베이스 서버)
APUE (Introduction) Linux/Unix는 인기 있는 운영체제 서버 시스템(웹 서버, 데이터베이스 서버) 공학 및 상업용으로 응용되고 있음 연구 개발 용으로도 많이 사용됨 최근 임베디드 시스템, 모바일 디바이스, 클라우드 시스템에 많이 활용되고 있음 시스템 프로그래밍 OS 자원을 이용한 프로그래밍 Linux/Unix 시스템 호출 사용 파일, 프로세스, IPC, 네트워킹, … DBMS, compiler, groupware, debugger, …

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

5 시스템 호출 (System Calls) (1/2)
APUE (Introduction) Process System call interface File Management IPC Process Management

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

7 User Mode vs. Kernal Kernel User process open(char *name, int mode) {
APUE (Introduction) Kernel User process Address of kernel close() Address of kernel open() result=open(“file.txt”, O_RDONLY); User code Address of kernel write() open(char *name, int mode) { <Place parameters in registers> <Execute trap instruction, switching to kernel code > <Return result of system call> } kernel code for open() { <Manipulate kernel data> . . . <Return to user code> } Kernel system call code C runtime library

8 System Calls & Library Functions (1/2)
APUE (Introduction) System Calls Well defined entry points directly into the kernel Documented in section 2 of the Linux/Unix man pages 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()

9 System Calls & Library Functions (2/2)
APUE (Introduction) application code C library functions system calls hardware (hard disk…) user process kernel

10 C I/O Library Functions
APUE (Introduction) 표준 입력 함수 (standard input function) scanf(), getchar() 표준 출력 함수 (standard output function) printf(), putchar() 표준 파일 입력 함수 fscanf(), fgets(), fgetc() 표준 파일 출력 함수 fprintf(), fputs(), fputc()

11 파일 입출력 (1/2) 파일 입출력 과정 파일 열기: fopen 입출력 방식 파일 열기, 읽기/쓰기, 파일 닫기
APUE (Introduction) 파일 입출력 과정 파일 열기, 읽기/쓰기, 파일 닫기 파일 열기: fopen #include <stdio.h>   FILE    *fp; fp=fopen("파일 이름", "입출력방식"); 입출력 방식 r: 읽기 전용 w: 쓰기 전용 a: 추가(append) 수록 r+: 읽기쓰기겸용 w+: 쓰기읽기겸용 a+: 읽기추가겸용

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

13 파일 출력 예제 (fgets.c) (1/2) APUE (Introduction)

14 파일 출력 예제 (fgets.c) (2/2) APUE (Introduction)

15 파일 입출력 예제 (fcopy.c) (1/2) APUE (Introduction)

16 파일 입출력 예제 (fcopy.c) (2/2) APUE (Introduction)

17 시스템 프로그래밍 준비 에디터 컴파일러 디버거 make We already knew “vi”.
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"

Similar presentations


Ads by Google