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

Slides:



Advertisements
Similar presentations
File Management in C. What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary.
Advertisements

Week 4 – Functions Introduction. Functions: Purpose Breaking a large problem into a series of smaller problems is a common problem- solving technique.
File Management in C. A file is a collection of related data that a computers treats as a single unit. File is a collection of data stored permanently.
Files in C Rohit Khokher. Files in C Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two.
Linking & Loading CS-502 Operating Systems
Chapter 11: Data Files & File Processing In this chapter, you will learn about Files and streams Creating a sequential access file Reading data from a.
CSCI 171 Presentation 12 Files. Working with files File Streams – sequence of data that is connected with a specific file –Text Stream – Made up of lines.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Data files –Can be created, updated,
 2007 Pearson Education, Inc. All rights reserved C File Processing.
UNIX Chapter 01 Overview of Operating Systems Mr. Mohammad A. Smirat.
Chapter 11 C File Processing Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
OS Spring’03 Introduction Operating Systems Spring 2003.
Guide To UNIX Using Linux Third Edition
OS Organization. OS Requirements Provide resource abstractions –Process abstraction of CPU/memory use Address space Concurrency Thread abstraction of.
Copyright Arshi Khan1 System Programming Instructor Arshi Khan.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
1 Homework Introduction to HW7 –Complexity similar to HW6 –Don’t wait until last minute to start on it File Access will be needed in HW8.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Lone Leth Thomsen Input / Output and Files. April 2006Basis-C-8/LL2 sprintf() and sscanf() The functions sprintf() and sscanf() are string versions of.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
File Handling In C By - AJAY SHARMA. We will learn about- FFile/Stream TText vs Binary Files FFILE Structure DDisk I/O function OOperations.
School of Computer Science & Information Technology G6DICP Introduction to Computer Programming Milena Radenkovic.
SAPC Hardware Pentium CPU (or 486) 4M usable memory no hard disk; boot from floppy no keyboard or monitor or mouse COM2 serial port: used for console i/o.
LINUX System : Lecture 7 Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
Linux/UNIX Programming APUE (Process Control) 문양세 강원대학교 IT 대학 컴퓨터과학전공.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
Introduction to Systems Programming (CS 0449) C Preprocessing Makefile File I/O.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
Chapter 11 File Processing. Objectives In this chapter, you will learn: –To be able to create, read, write and update files. –To become familiar with.
 2000 Prentice Hall, Inc. All rights reserved Introduction Data files –Can be created, updated, and processed by C programs –Are used for permanent.
Chapter 12 Files (reference: Deitel ’ s chap 11) chap8.
UNIX Unit 1- Architecture of Unix - By Pratima.
Chapter 7 : File Processing1 File-Oriented Input & Output CHAPTER 7.
1 CHAPTER6 CHAPTER 6. Objectives: You’ll learn about;  Introduction  Files and streams  Creating a sequential access file  Reading data from a sequential.
chap8 Chapter 12 Files (reference: Deitel ’ s chap 11)
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
ME-2221 COMPUTER PROGRAMMING Lecture 18 FILE OPERATIONS Department of Mechanical Engineering A.H.M Fazle Elahi Khulna University of engineering & Technology.
 2007 Pearson Education, Inc. All rights reserved. 1 C File Processing.
FILES IN C. File Operations  Creation of a new file  Opening an existing file  Reading from a file  Writing to a file  Moving to a specific location.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
Operating Systems Introduction Moti Geva
Operating System Basics
Topic 2: Hardware and Software
SLC/VER1.0/OS CONCEPTS/OCT'99
Operating Systems Lecture 2.
TMF1414 Introduction to Programming
Protection of System Resources
Chapter 7 Text Input/Output Objectives
Linking & Loading.
CS 3305 System Calls Lecture 7.
CS-3013 Operating Systems C-term 2008
Manipulating File IO in Visual C++
FILE HANDLING IN C.
Operating Systems Lecture 2.
File Input and Output.
File Handling.
Accessing Files in C Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Linking & Loading CS-502 Operating Systems
Fundamental of Programming (C)
Operating Systems Lecture 3.
LINUX System : Lecture 7 Lecture notes acknowledgement : The design of UNIX Operating System.
Operating Systems: A Modern Perspective, Chapter 3
C Preprocessing File I/O
Linking & Loading CS-502 Operating Systems
Quick Review EECS May 2019.
CSc 352 File I/O Saumya Debray Dept. of Computer Science
Presentation transcript:

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

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

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

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)

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

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)

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);

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)

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

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)

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)

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

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

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

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

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

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”.