Dr. T. Doom Lab.1 CEG 433/633 - Operating Systems I OS Course Assignments Lecture foils are available on-line:

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Chapter 3 Loaders and Linkers. Purpose and Function Places object program in memory Linking – Combines 2 or more obj programs Relocation – Allows loading.
Separate compilation Large programs are generally separated into multiple files, e.g. tuples.h, ray.h, ray.c, tuples.c main.c With several files, we can.
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
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.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Guide To UNIX Using Linux Third Edition
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
1 Some basic Unix commands u Understand the concept of loggin into and out of a Unix shell u Interact with the system in a basic way through keyboard and.
Computer Science 210 Computer Organization Modular Decomposition Making a Library Separate Compilation.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Unix Basics Chapter 4.
Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Creating your first C++ program
Programming With C.
CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
ENEE150 – 0202 ANDREW GOFFIN Introduction to ENEE150.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
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.
CMSC 104, Lecture 111 Introduction to C Topics l Compilation l Using the gcc Compiler l The Anatomy of a C Program l 104 C Programming Standards and Indentation.
Basic of UNIX For fresh members of SPARCS
CMSC 1041 Introduction to C Creating your first C program.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
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.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
Chapter Linux Basics. Acknowledgements This presentation was prepared by – Banyat Settapanich – Bahran Madaen This presentation will be updated later.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
Lecture 1: Introduction UNIX programming environment –Editors –Remote shell setup –C compilers –Debugger –make.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
系統程式 System Programming 羅習五 國立中正大學資訊工程學系 Class: EA-001 (05) ext.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Multiple file project management & Makefile
Makefiles Caryl Rahn.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Editor, Compiler, Linker, Debugger, Makefiles
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Topics Compilation Using the gcc Compiler
C Basics.
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
C Programming Lecture Series
Unix Programming Environment
Creating your first C program
Appendix F C Programming Environment on UNIX Systems
Video Notes.
Makefiles, GDB, Valgrind
SPL – PS1 Introduction to C++.
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Presentation transcript:

Dr. T. Doom Lab.1 CEG 433/633 - Operating Systems I OS Course Assignments Lecture foils are available on-line: WSU’s CaTS UNIX system: paladin.wright.edu Student information is available in the directory: –~w001ted/pub lab assignments are available as: –~w001ted/pub/ceg433/labs/labXX/labXX.worksheet.txt All lab assignments must: –be turned in complete and on-time (include all required files)  labXX.makefile  labXX.typescript (man script)  labXX.readme –compile without warning or error using your makefile on paladin.wright.edu (Solaris 2).  The compiler must be invoked with the -Wall flag

Dr. T. Doom Lab.2 CEG 433/633 - Operating Systems I Grading Guidelines To earn any points, your program must compile on paladin (with -Wall flag and no warnings or errors), with the makefile you submit (using "make -f labXX.makefile") to the target executable file "labXX" (where XX is the two digit lab number). Implementation/Worksheet (4 points possible): Required: a compiling program / worksheet 4 All features implemented perfectly / all answers correct. 2 Some features implemented / some answers correct. 0 No features implemented / no answers correct. Bugs (2 points possible): Required: most features implemented 2 No bugs found, complete error checking done. 1 A bug found: documented in readme, demonstrated in typescript. 0 An undocumented bug found. Documentation (3 points possible): Required: a compiling program. 2 Extensive README: Discussion of design and implementation decisions,concepts learned, bugs found and corrected, remaining bugs, etc. Demonstrate mastery. 1 Code documentation: o File comment header - including your name and at least. o Descriptive comment blocks in code file for program and all functions, including: purpose, arguments and flags, return values, and errors handled. o In-code comments (preferably comment blocks for code blocks). Excellence (1 point possible): Required: No points deducted above. Implementation is concise and elegant, code is easy to read (descriptively named variables, all lines less than 80 columns, etc.), extremely well documented, all possible errors handled and demonstrated in typescript. Generally excellent work.

Dr. T. Doom Lab.3 CEG 433/633 - Operating Systems I OS Programming in C/C++ C programs can easily access the services of the UNIX operating system System calls: routines that make operating system services available to programmers –creating/deleting files, allocating memory, sending signal to processes In C, system calls are used in the same way you use ordinary C program modules (functions) A variety of libraries have been developed to support programming in C –libraries are collections of related functions –many libraries functions access basic OS services through system calls –default location is generally /usr/lib

Dr. T. Doom Lab.4 CEG 433/633 - Operating Systems I OS Programming in C/C++ Lines that begin with # are pre-processor directives #define: used to define symbolic constants (a macro) –provides mapping from symbolic name to replacement text (macro expansion). Improves readability and modification. Header files for a library contain function prototypes and macros. –When several macro definitions are used in different modules they are typically collected together in a single file called a header (or include) file (these files use the.h extention by convention). –A function prototype is a declaration that tells the compiler what type a function returns, how many argument a function expects, and what the types of the arguments are. This allows the compiler to detect and flag inconsistencies in the use of the function #ifndef ALLOC #define ALLOC(type,num) ((type *) malloc(sizeof(type) * (num))) #endif

Dr. T. Doom Lab.5 CEG 433/633 - Operating Systems I OS Programming in C/C++ Include files are loaded by the preprocessor using the #include directive. –Angle brackets are used for include files located in the “standard” location (generally /usr/include) –#include –Double quotes are used for other locations: –#include “/user/doom/soft/include/doomC.h” –Another way to specify directories to be searched for header files is to use the -I option to the C compiler –#include “doomC.h” –cc -I /user/doom/soft/include If you have difficulties with a system call, check the man page and/or the header file –The “technical” details are available in the header files.

Dr. T. Doom Lab.6 CEG 433/633 - Operating Systems I OS Programming in C/C++ Each program must well organized into functional modules –Main is the control module - execution begins and ends with the function main –Functions are used to make both development and maintenance of the program more efficient –Every function should have a clearly defined (and documented) purpose  Necessary conditions (pre-conditions)  side-effects (post-conditions)  return values Generally speaking, a function should consist of 5 to 40 lines of code

Dr. T. Doom Lab.7 CEG 433/633 - Operating Systems I Programming Tools: man, vi, xemacs man –Learn to use the man command; it is the single best tool for solving any UNIX problem  ex: man -k fork  ex: man -s2 sleep –“man man” to start Editors –vi: powerful and ubiquitous, steep learning curve (but worth it) –emacs (xemacs): powerful yet cumbersome (probably worth it) –pico: weak, small learning curve X displays can be piped back to remote machines running an xserver: –(remote system): setenv DISPLAY remotesystemname:0.0 –(host system): xhost +remotesystemname

Dr. T. Doom Lab.8 CEG 433/633 - Operating Systems I Programming Tools GUI - Sun WorkShop –“workshop”: graphical environment for coding and debugging (licensed from Sun), used to be called “SPARCworks” in the SunOS5 days, includes:  cc: C compiler  sbrowser: source browser  analyzer: performance tuner  debugger or dbx: debugger does a good job with forks (follow parent, child, or both)  rsccs: source code management  dmake: distributed make, similar to GNU make but allows concurrency exploitation  etc. In my experience, workshop does not work well remotely.

Dr. T. Doom Lab.9 CEG 433/633 - Operating Systems I Programming Tools: gcc C (C++) compilers –cc (CC): SunWorkShop Compiler –gcc (g++): GNU C Compiler, freeware, cross-platform, ubiquitous Compiler flags –man gcc for details! –-l: specify library on command line (must come after all modules to which it applies) –-L: specify additional directories to by searched for library (default /usr/lib and /lib) –-O: invoke compiler optimizer –-o: specify executable name (default a.out) –-W: specify warning level (implicit, return-type, unused, comment, format, all, etc) –ex: gcc -o lab01 -Wall lab01.c

Dr. T. Doom Lab.10 CEG 433/633 - Operating Systems I Programming Tools: gcc –-c: suppress linking phase (create object files (.o) without treating unresolved references as errors) –ex: gcc -c doomC.c lab01.c (creates doomC.o and lab01.o) –ex: gcc -o lab01 doomC.o lab01.o (creates executable lab01 by linking object files) –-R: specify location of run-time libraries (default /usr/lib) - Absolute pathnames only!  UNIX systems use shared (dynamic) libraries - the library modules are not included in the executable, only the location of the *.so file. Use “ldd” to find out what shared libraries and executable requires.  Do not use the only style LD_LIBRARY_PATH and LD_RUN_PATH environment variables.  The -fPIC flag to gcc can be used to generate position- independent code; combined with the ld -G command, you can create your own shared libraries.

Dr. T. Doom Lab.11 CEG 433/633 - Operating Systems I Programming Tools: Make Make: Keep a set of programs current –C programs depend on a number of files (system header files, user header files, C source files, object files, executable files, etc.) –When a changed occurs to a file that others depend on, you MUST recompile all dependent files. –The “make” program allows your to specify dependency relationships to automate this process –Make looks at at dependency lines in the specified file  default: the files Makefile or makefile in the working directory  explicit: specified using the -f flag to make

Dr. T. Doom Lab.12 CEG 433/633 - Operating Systems I Programming Tools: Make –Each dependency lines specifies a target file that depends on one or more prerequisite files. If any of the files in the dependency list has been modified since the target’s last modification date, then the specified commands are invoked (each line of the commands begins with a TAB) –Syntax: target: prerequisite-list TAB construction-commands lab01: doomC.o lab01.o cc -o lab01 doomC.o lab01.o lab01.o: lab01.h cc - c lab01.c doomC.o: doomC.h cc -c doomC.c clean: rm -f core *.o

Dr. T. Doom Lab.13 CEG 433/633 - Operating Systems I Programming Tools: Make –Implied dependencies: If you do not include a dependency line for an object file, make assumes that it depends upon a compiler or assembler source code file with the same name. BEWARE: using implied dependencies requires that you use MACROS to pass necessary flags  If no dependency file is specified, only implied dependencies are used  If no target is specified, the first dependency in the file is the default CC=gcc CFLAGS=-Wall $(SRC)= doomC.c lab01.c $(OBJ)=($SRC:.c=.o) lab01: $(SRC) $(OBJ) $(CC) -o lab01$CFLAGS $(OBJECTS) #(others are implicit)

Dr. T. Doom Lab.14 CEG 433/633 - Operating Systems I Programming Tools: Debuggers Debuggers –gdb (xgdb, xxgdb - grahical): powerful, freeware, ubiquitous  use help command at gdb prompt for: list, break, run, set args, print, display, up, down, cont –lint: checks programs for potential bugs and portability problems –truss: trace system calls and signals Other useful commands –Standard file commands: cp, mv, grep, diff, file, ls, mkdir, cd, rm, chmod, ln –Know the uses for: |, ||, &, &&, fg, bg, jobs –Useful utilities: script, tar, compress, gzip, which, whereis, apropos, who, w, talk, write, man, man, man