Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 系統程式 System Programming http://ecourse.elearning.ccu.edu.tw/ 羅習五 國立中正大學資訊工程學系 shiwulo@cs.ccu.edu.twshiwulo@cs.ccu.edu.tw Class: EA-001 (05)2720411 ext. 33116 Office: EA-517 本份投影片及本學期投影片,大量參考自 熊博安教授所製作的「系統程式」教學投 影片

2 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 http://www.apuebook.com/ 2 nd Edition1 st Edition3 rd Edition

3 About Rich Stevens On Wikipedia: ▫http://en.wikipedia.org/wiki/W._Richard_Stevenshttp://en.wikipedia.org/wiki/W._Richard_Stevens “Stevens died in 1999, at the age of 48. In 2000, he was posthumously awarded the USENIX Lifetime Achievement Award.”

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

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

6 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

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

8 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

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

10 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

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

12 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” :帶上講義或課本或筆記

13 System Programming ENJOY THE COURSE!!!

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

15 UNIX programming environment Editors C compilers Debugger Makefiles ▫make

16 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

17 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

18 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

19 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

20 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

21 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

22 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

23 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

24 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

25 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

26 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 http://www.pasc.org and http://www.standards.ieee.orghttp://www.pasc.org http://www.standards.ieee.org

27 IETF Internet Engineering Task Force (IETF) ▫Network designers, operators, vendors, researchers ▫Deals with the Internet ▫Issues RFCs See also http://www.ietf.orghttp://www.ietf.org

28 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

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


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

Similar presentations


Ads by Google