系統程式 System Programming 羅習五 國立中正大學資訊工程學系 Class: EA-001 (05)2720411 ext.

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Utilizing the GDB debugger to analyze programs Background and application.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Environment & tools Assistant Anssi Jääskeläinen Visiting hours: Tuesdays Room: 6606
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
21-Jun-15Advanced Programming Spring 2002 Advanced Programming Henning Schulzrinne Dept. of Computer Science Columbia University.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Lecture 2: Miscellaneous UNIX/C concepts –Key based authentication and remote shell –Portable C programs and C standards –Debugger –Make –Some commonly.
Guide To UNIX Using Linux Third Edition
CSE : Programming in C Instructor: Lei Wang Office: Dreese Lab 474 Office Hour: Friday.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
CS 11 C track: lecture 1 Preliminaries Need a CS cluster account cgi-bin/sysadmin/account_request.cgi Need to know UNIX ITS.
Homework Reading Programming Assignments
Copyright 2001 Oxford Consulting, Ltd1 January Storage Classes, Scope and Linkage Overview Focus is on the structure of a C++ program with –Multiple.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 5 Acknowledgements: The syllabus and power point presentations are modified versions.
Operating Systems 作業系統 熊博安 國立中正大學資訊工程學系 EA-101, EA001.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Programming With C.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
C Tutorial Session #2 Type conversions More on looping Common errors Control statements Pointers and Arrays C Pre-processor Makefile Debugging.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Some Basics && GDB overview Ram Sheshadri –
CS 590 Programming Environments with UNIX. Computer Lab Account Course Homepage
LINUX System : Lecture 1 Course Overview Bong-Soo Sohn Associate Professor School of Computer Science and Engineering Chung-Ang University.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
Advanced Unix Programming Introduction. Course Info Course Book: Advanced Programming in the UNIX Environment, 2 nd Edition by W. Richard Stevens and.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Discussion Week 1 TA: Kyle Dewey. Project 0 Walkthrough.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
CMSC 2021 CMSC 202 Computer Science II for Majors Spring 2003 Mr. Frey (0101 – 0104) Mr. Raouf (0201 – 0204)
Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.
COP 3530 Spring 12 Discussion Session 1. Agenda 1.Introduction 2.Remote programming 3.Separate code 4.Compile -- g++,makefile 5.Debug -- gdb 6.Questions?
Program in Multiple Files. l all C++ statements are divided into executable and non-executable l executable - some corresponding machine code is generated.
Adv. UNIX:pre/111 Advanced UNIX v Objectives of these slides: –look at the features of the C preprocessor Special Topics in Comp. Eng.
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
NCHU System & Network Lab Lab #6 Thread Management Operating System Lab.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
Lecture 1: Introduction UNIX programming environment –Editors –Remote shell setup –C compilers –Debugger –make.
系統程式 System Programming
C++ Functions A bit of review (things we’ve covered so far)
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 7: User-Defined Functions II
Advanced UNIX progamming
Editor, Compiler, Linker, Debugger, Makefiles
Introduction to C Topics Compilation Using the gcc Compiler
C Basics.
MSIS 655 Advanced Business Applications Programming
C Preprocessor(CPP).
Unix Programming Environment
Introduction to C Topics Compilation Using the gcc Compiler
Advanced UNIX progamming
Introduction to C Topics Compilation Using the gcc Compiler
Appendix F C Programming Environment on UNIX Systems
CISC 361 Operating Systems Midterm Review
What Is? function predefined, programmer-defined
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
Makefiles, GDB, Valgrind
SPL – PS1 Introduction to C++.
SPL – PS3 C++ Classes.
Presentation transcript:

系統程式 System Programming 羅習五 國立中正大學資訊工程學系 Class: EA-001 (05) ext Office: EA-517 本份投影片及本學期投影片,大量參考自 熊博安教授所製作的「系統程式」教學投 影片

Text and Reference Book Advanced Programming in the UNIX Environment, 2nd Edition, W. Richard Stevens, Stephen A. Rago, Addison Wesley, 2005, 開發代 理 (927 pages), “APUE” in short 2 nd Edition1 st Edition3 rd Edition

About Rich Stevens On Wikipedia: ▫ “Stevens died in 1999, at the age of 48. In 2000, he was posthumously awarded the USENIX Lifetime Achievement Award.”

About Rich Stevens Stevens 先生不幸逝于 1999 年 9 月 1 日,至于死因家 人不便透露,不过有三种说法: ▫ 攀岩 ▫ 滑翔意外 ▫ 滑雪 感謝 Stevens 帶給我們這麼好的一本課本!

Text and Reference Book Linux System Programming, Robert Love, O'Reilly Media, 2007

Syllabus (暫定) TopicChapter Dates Overview 1 2/20 ~ 3/12 week(s) Files, Dirs, Stdio, Sys Info 3  6 3/6 ~ 4/126 week(s) Mid-Term Exam 4/15~4/19 Process Environment7 4/24 ~ 5/32 week(s) Process Control8 5/8 ~ 5/101 week(s) Signals10 5/15 ~ 5/171 week(s) IPC15 5/22 ~ 5/312 week(s) ?(threads)?(11,12) 6/5~6/142 week(s) Final Exam 6/17 ~ 6/21

課程形式 課堂上課( EA001 ) 數位教材( ecourse, cyberCCU )

Program Assignments (暫定) Total 4 program assignments announced on: 1. ?Shell: 3/06 ~ 3/20 2. ???: 3/20 ~ 4/03 3. ???:4/24 ~ 5/01 4. ???: 5/22 ~ 6/05

Grading (暫定) Mid-Term Exam 30% Final Exam30% Program Assignments40% Bonus (Q/A, quiz, attendance, … )

Dates (暫定) Midterm Exam: 4/10 13:30~15:30 Final Exam: 6/19 13:30~15:30 Program Assignments (total 4) ▫To be done individually ▫2 to 4 weeks for each program ▫Backgrounds:  Some data structures,  Some UNIX/Linux operations

Rules NO COPYING of assignments/projects (a single case of copying  BOTH parties will get ZERO point for ALL assignments and projects) NO CHEATING in exams (BOTH parties will get ZERO points for that exam)

Rules (cont ’ d) Class Quiz: ▫Correct Answer  Bonus Points ▫Wrong or No Answer  Deduction Points Class “Attendance”: ▫1 absence  Deduct 5% ▫2 absences  Deduct 10% ▫n absences  Deduct 5n% “Attendance” :帶上講義或課本或筆記

System Programming ENJOY THE COURSE!!!

Unix programming envirunments 本份投影片大量參考自 Ashok Srinivasan 的投影片

UNIX programming environment Editors C compilers Debugger Makefiles ▫make

vi, pico, emacs, etc What is good about emacs? ▫emacs is more than just an editor ▫You can compile and edit within emacs ▫If you know lisp, you can expand its functionality ▫Some useful commands to get started:  C-h t get tutorial  C-g cancel command  C-x C-c quit emacs  C-h help Editors

C compilers gcc, cc, icc, llvm Using ANSI C, the code must pass with flags –Wall –ansi –pedantic with no warning messages Some examples ▫ gcc –g –Wall –ansi –pedantic example1.c ▫ gcc –g –c –Wall –ansi –pedantic example1.c

ddd, xxgdb, gdb The code must be compiled with –g option. The power of a debugger: ▫Finding the line that causes coredump. ▫See example:  Break point, show value, change value, step, next, continue, print ▫Very efficient in debugging sequential code ▫Not very effective in debugging concurrent code (multiple threads, multiple processes) Good software development practice: You must have seen each line of your code execute in the debugger, at least once Debugger

make [-f makefile][option] target ▫A tool to update files derived from other files ▫The default files for make are./makefile,./Makefile,./s.makefile ▫Use the –f option to specify some other file  make –f makefile1 ▫The makefile has three components  Macros: define constants  Target rules: Specify how targets are made  Inference rules: Specify how targets can be made, implicitly. make will first check if a target rule applies, before using inference rules. Make

Header files Usually define interfaces between separately compiled modules May contain macro definitions, preprocessor directives, declarations of types, and function prototypes Should not contain variable definitions or executable code

Conditional Code in Headers Preprocessor directives are used to prevent the body of a header file from being used multiple times. #ifndef MYHEADER #define MYHEADER /* the body of the header file */ #endif

Macros with and without Parameters #define MAX_LENGTH 256 ▫... for (i = 0; i < MAX_LENGTH; i++)... Macros can have parameters ▫ #define max(a,b) (a > b) ? a : b What is wrong with the following? ▫ #define sum(a, b) a + b ▫ #define product(a, b) a*b

Some Unix System Calls #include int system(const char *string); ▫Works as if string is typed into the shell at a terminal ▫Returns the exit status (see man page for waitpid) ▫Usually -1 is returned if there is an error

Portability Standards ▫Source code portability: ANSI/ISO C ▫UNIX standards: POSIX, open group ▫Internet engineering task force (IETF) 32 bit vs 64 bit Byte order ▫ Little endian vs big endian

Source Code Portability Standard programming language ▫Example: ANSI/ISO C  c89, c90, c99, c11 Standard libraries Standard API to operating system ▫Example: POSIX.1 Auto-configuration mechanisms Programmer discipline

Unix Standards POSIX (IEEE STDS 1003.x and ISO/IEC 9945) ▫POSIX.1: System API for C language ▫POSIX.2: Shell and utilities ▫POSIX.5: System API for Ada language ▫POSIX.9: System API for Fortran language See also and

IETF Internet Engineering Task Force (IETF) ▫Network designers, operators, vendors, researchers ▫Deals with the Internet ▫Issues RFCs See also

64-bit vs. 32-bit architecture Pointers cannot be stored as int size_t cannot be stored as int long may not be long enough for size_t and offset_t Datatype32bit64bit char88 short16 int32 long3264 pointer3264 ( long long )64

Byte order Little-Endian ▫ Low-order byte is stored at lowest address Big-Endian ▫ High-order byte is stored at lowest address