IWS (Instructional Work Servers) There are 4 instructional Unix servers: –ceylon, fiji, sumatra, and tahiti Accessing the servers: –Terminal Programs:

Slides:



Advertisements
Similar presentations
Introduction to the Omega Server CSE Overview Intro to Omega Basic Unix Command Files Directories Printing C and C++ compilers GNU Debugger.
Advertisements

Linux, it's not Windows A short introduction to the sub-department's computer systems Gareth Thomas.
Utilizing the GDB debugger to analyze programs Background and application.
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
1 Introduction to UNIX Ke Liu
Working with Files How to create, view, copy, rename and print files.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
CS1020: Intro Workshop. Topics CS1020Intro Workshop Login to UNIX operating system 2. …………………………………… 3. …………………………………… 4. …………………………………… 5. ……………………………………
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
What is Unix? A multi-user networked operating system –“Operating System” Handles files, running other programs, input/output Just like DOS or Windows.
IWS (Instructional Work Servers) There are 4 instructional Unix servers: –ceylon, fiji, sumatra, and tahiti Accessing the servers: –Terminal Programs:
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
What is Unix? A multi-user networked operating system –“Operating System” Handles files, running other programs, input/output Looks like DOS…but more powerful.
A Mini UNIX Tutorial. What’s UNIX?  An operating system run on many servers/workstations  Invented by AT&T Bell Labs in late 60’s  Currently there.
"Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous.
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”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
Introduction to Unix Bent Thomsen Institut for Datalogi Aalborg Universitet.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Introduction to Shell Script Programming
Introduction to Unix Bent Thomsen Institut for Datalogi Aalborg Universitet.
Unix Basics Chapter 4.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction Unix-like system is everywhere Linux Android for smartphones Google Chrome OS for Chromebook Web.
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
Linux+ Guide to Linux Certification, Second Edition
HTML Hyper Text Markup Language A simple introduction.
Creating your first C++ program
Carnegie Mellon Linux Boot Camp Jenna MacCarley, Peter Pearson, Shashank Goyal 9/19/2015.
TAMU CSCE 313 (the basics). Basic Unix/Linux programming Accessing CS systems  PuTTY (putty.exe) – a Telnet and SSH client  Common hosts: unix.cs.tamu.edu.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
ENEE150 – 0202 ANDREW GOFFIN Introduction to ENEE150.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
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.
Unix and Samba By: IC Labs (Raj Kidambi). What is Unix?  Unix stands for UNiplexed Information and Computing System. (It was originally spelled "Unics.")
Introduction To UNIX. FAQReferencesSummaryInfo Resources Introduction Learning Objectives Log on User Interface Commands List of Commands Useful Info.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Introduction to Programming Using C An Introduction to Operating Systems.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
The Kernel At a high level, the kernel in an operating system serves as the bridge between applications and the actual data processing of the hardware.
 Last lesson, the Windows Operating System was discussed along with the Windows command shell  Unix is a computer operating system, that similarly manages.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
What is Unix? A multi-user networked operating system –“Operating System” Handles files, running other programs, input/output Just like DOS or Windows.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
1 Week 8 Creating Simple Shell Scripts. 2 Chapter Objectives  In this chapter, you will :  Learn how to create Shell Scripts  Commenting / Making Portable.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
CMSC 104, Version 8/061L03OperatingSystems.ppt Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux.
CS 120 Extra: The CS1 Server Tarik Booker CS 120.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Learning Unix/Linux Based on slides from: Eric Bishop.
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors Locate seg faults and bus errors Prepared by Dr. Spiegel.
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
CS1010: Intro Workshop.
UNIX The Basics Source:
Andy Wang Object Oriented Programming in C++ COP 3330
Compilation and Debugging
Compilation and Debugging
The Command Prompt Commands are the way to “do things” in Unix
Intro to UNIX System and Homework 1
IWS (Instructional Work Servers)
IWS (Instructional Work Servers)
Web Programming Essentials:
Getting Started: Developing Code with Cloud9
TA: Maya Rodrig Our C++ guru: Nic Bone
What is Unix? A multi-user networked operating system
Video Notes.
Presentation transcript:

IWS (Instructional Work Servers) There are 4 instructional Unix servers: –ceylon, fiji, sumatra, and tahiti Accessing the servers: –Terminal Programs: telnet (insecure; cannot be used) ssh (via the TeraTerm or Putty programs from Windows) –Start -> Program Files -> Desktop Tools -> TeraTerm –File Transfer Programs ftp (insecure; cannot be used at UW) \\ \ from Start -> Run menu –e.g -- \\fiji\zanfur Secure file transfer (from C&C) –Xwindows Run xgo from the command prompt Come to the ACM tutorial! This tutorial provided by UW ACM Questions to

Logging In Which server you use (almost) doesn’t matter – all four allow access to your files Although your Windows and Unix usernames (and passwords) are the same, they are two separate accounts –Your z: drive is not your Unix account Connecting: –We’ll connect to the Unix machines via ssh –After connection, you are presented with a login prompt –After logging in, you’re placed in your home directory (where your personal files are located)

The Command Prompt Commands are the way to “do things” in Unix A command consists of a command name and options called “flags” Commands are typed at the command prompt In Unix, everything (including commands) is case-sensitive [prompt]$ fiji:/u15/awong$ ls –l -a unix-tutorial Command Prompt Command (Optional) flags (Optional) arguments Note: In Unix, you’re expected to know what you’re doing. Many commands will print a message only if something went wrong.

Two Essential Commands The most useful commands you’ll ever learn: –man (short for “manual”) –info They help you find information about other commands –man or info retrieves detailed information about –man –k searches the man page summaries (faster, and will probably give better results) –man –K searches the full text of the man pages fiji:/u15/awong$ man –k password passwd(5) - password file xlock(1) - Locks the local X display until a password is entered fiji:/u15/awong$ passwd

Directories In Unix, files are grouped together in other files called directories, which are analogous to folders in Windows Directory paths are separated by a forward slash: / –Example: /u10/hctang/classes/cse326 The hierarchical structure of directories (the directory tree) begins at a special directory called the root, or / –Absolute paths start at / Example: /u10/hctang/classes/cse326 –Relative paths start in the current directory Example: classes/cse326 (if you’re currently in /u10/hctang ) Your home directory is where your personal files are located, and where you start when you log in. –Example: /u10/hctang

Directories (cont’d) Handy directories to know ~ Your home directory.. The parent directory. The current directory ls –LiSts the contents of a specified files or directories (or the current directory if no files are specified) –Syntax: ls [ … ] –Example: ls backups pwd –Print Working Directory

Directories (cont’d further) cd –Change Directory (or your home directory if unspecified) –Syntax: cd –Examples: cd backups/unix-tutorial cd../class-notes mkdir –MaKe DIRectory –Syntax: mkdir –Example: mkdir backups class-notes rmdir –ReMove DIRectory, which must be empty –Syntax: rmdir –Example: rmdir backups class-notes

Files Unlike Windows, in Unix file types (e.g. “executable files, ” “data files,” “text files”) are not determined by file extension (e.g. “foo.exe”, “foo.dat”, “foo.txt”) Thus, the file-manipulation commands are few and simple … rm –ReMoves a file, without a possibility of “undelete!” –Syntax: rm –Example: rm tutorial.txt backups/old.txt

Files (cont’d) cp –CoPies a file, preserving the original –Syntax: cp –Example: cp tutorial.txt tutorial.txt.bak mv –MoVes or renames a file, destroying the original –Syntax: mv –Examples: mv tutorial.txt tutorial.txt.bak mv tutorial.txt tutorial-slides.ppt backups/ Note: Both of these commands will over-write existing files without warning you!

Shell Shortcuts Tab completion –Type part of a file/directory name, hit, and the shell will finish as much of the name as it can –Works if you’re running tcsh or bash Command history –Don’t re-type previous commands – use the up-arrow to access them Wildcards –Special character(s) which can be expanded to match other file/directory names * Zero or more characters ? Zero or one character –Examples: ls *.txt rm may-?-notes.txt

Text - editing Which text editor is “the best” is a holy war. Pick one and get comfortable with it. Three text editors you should be aware of: –pico – Comes with pine ( Dante ’s program) –emacs/xemacs – A heavily-featured editor commonly used in programming –vim/vi – A lighter editor, also used in programming Get familiar with one as soon as possible!

Text - printing Printing: –Use lpr to print Use –h (no header) and –Zduplex (double-sided) to save paper –Check the print queue (including Windows print jobs!) with lpq –lprm to remove print jobs (including Windows print jobs) –For the above commands, you’ll need to specify the printer with –P Check out enscript (quizlet: how do you find information about commands?) to print text files nicely! –WARNING: Do NOT use enscript with postscript files!

The Unix Philosophy A large set of primitive tools, which can be put together in an infinite number of powerful ways An example: –Three separate tools are necessary to develop software: Text editor Compiler Debugger (You will need this, unless “j00 R l33t”) –MSVC is an “IDE” (“Integrated Development Environment”) All three tools are found in one shrink-wrapped box –Although there are IDE’s for Unix, for this course, you will most likely use (mostly) separate tools: Text editor: emacs/xemacs or vi/vim Compiler: g++ Debugger: gdb This tutorial provided by UW ACM Questions to

Compilation To compile a program: –g++ –Recommended: g++ -Wall –ansi -g –o *.cpp -Wall – Warnings: ALL -ansi – Strict ANSI compliance -g – Add debugging symbols to the executable (ie, make it debuggable!) Quizlet: what does *.cpp mean? What’s an “executable”? –In Windows, double-clicking on an icon runs a program E.g. double-click on C:\Windows\notepad.exe –In Unix, you can run your executable from the command line! Type the executable name at the prompt, just like a command –In fact, commands are actually executables However, you may need to specify the path to your executables –./ runs in the current directory Example: fiji:ehsu% g++ -Wall –ansi -g –o hello hello.cpp fiji:ehsu%./hello

“Compilation” or “The Big Lie” Does this picture look familiar? –You saw this in 143! These are the discrete steps to program “compilation” Hitting the ‘!’ button in MSVC or typing a “ g++ *.cpp ” to build (not “compile”) your program hides all these separate steps. Question: would you want to do this entire process (ie, pre- process and compile every file) every time you wanted to generate a new executable?.h.cpp.h compiler linker ANSI lib compiler.exe file other libs.cpp Pre-proc

Selective Recompilation and Makefiles Answer: –No. You only want to compile those files which were changed (or were affected by a change in another file [quizlet: when might this happen?]). We can reuse the.o/.obj files for files which weren’t modified. You could do this yourself… –g++ –g++ *.o But you could also use the make command and a Makefile ! –Create a Makefile to keep track of file dependancies and build options –The make command will read the Makefile and compile (and build) those files which have dependancies on modified files!

Makefile Syntax Makefiles consists of variables and rules. Rule Syntax: : The may be files and/or other targets There must be a tab (not spaces) before The first rule in a Makefile is the default for make Variable Syntax: = All variable values default to the shell variable values Example: –BUILD_FLAGS = -Wall -g -ansi

Example Makefile # Example Makefile CXX=g++ CXXOPTS=-g –Wall -ansi -DDEBUG foobar: foo.o bar.o $(CXX) $(CXXOPTS) –o foobar foo.o bar.o foo.o: foo.cc foo.hh $(CXX) $(CXXOPTS) –c foo.cc bar.o: bar.cc bar.hh $(CXX) $(CXXOPTS) –c bar.cc clean: rm -f foo.o bar.o foobar

Writing Code What causes a bug? –What you meant != what you wrote Coding right the first time is making “what you meant” align with “what you write” –Invariants – assert() invariants to discover when your program’s state has changed unexpectedly –Error handling and notification – Fix or report errors. Your program should never be in a bad state –Code review –Use a debugger! See next slide …

Debugging How do you remove a bug? –Read the code. If you don’t understand it, the bug will happen again –Examine the state of the program at key points in the code Print statements in the code (suggestion: wrap debug output with #ifdef DEBUG ) Use a debugger to view the state of your program with greater flexibility/control Debugger advantages –Compile your code only once –Monitor all the values in the code –Make changes while executing the code –Examine core files that are produced when a program crashes In other words, debuggers are tools which allow you to examine the state of a program in detail! –In fact, debuggers can (and should) be used to understand and improve your code

Debugging Techniques Goal: Isolate the problem, then fix it –Don’t try random things, looking for a solution If you don’t understand it, it’ll be back This method takes a long time You don’t learn anything from it –Look for the problem, not the solution Figure out two points in code that the problem is between, and close the gap from there.

GDB - The GNU DeBugger To run gdb (a text-based debugger): –gdb [ [ ]] Executable program file Crashed program’s core dump –You must compile with -g for debug information! Within gdb: –Running gdb: run [ ] Run program with arguments quit Quit the gdb debugger help [ ] Access gdb’s internal help –Examining program state: info [locals|args] Prints out info on [local variables|args] backtrace[ ] Prints the top frames on the stack p[rint] Print out

GDB continued –Controlling program flow s[tep] Step one line, entering called functions n[ext] Step one line, skipping called functions finish Finish the current function and print the return value –Controlling program flow with breakpoints c[ontinue] Continue execution (after a stop) b[reak][ ] Set a breakpoint d[elete] [ ] Deletes breakpoints by number [r]watch Sets a watchpoint, which will break when is written to [or read] –Modifying program state set Set a variable to jump Resume program execution at

Compilation with g There are actually three g++ s installed on the instructional machines –Version is the one we’ll be using for 326 –Version 2.96 is the default To use version 3.0.3, you need to call g g is located in /uns/bin, which is not part of your standard Unix environment

Setting Up Your Environment To set up your Unix environment, you’ll need: – csh/tcsh : Edit (or create) your.mycshrc file setenv PATH {$PATH}:/uns/bin –bash : Edit (or create) your.bashrc file export PATH=$PATH:/uns/bin To get the full benefit of /uns, you can run the /uns/examples/setup-tutorial script It’s a good idea to look at what’s in /uns/bin – there are many useful tools there: –xemacs –ddd –And much, much more …

More Information - In the Dept In the department –Your neighbors! –info and man –uw-cs.lab-help newsgroup –.login,.cshrc, and /uns/examples to see how other people have things set up –Course staff - office hours, Why do you think we get paid the big bucks? =)

More Information - On the Web On the web: – ( comp.unix questions FAQ) – – –ACM Tutorials: –CSE326 webpage cse326/02wi/computing/class_links.html If you’re curious, check out these topics: –Source control (try searching the web for “cvs”) Multiple people working on a file concurrently Easily revert file changes –Profiling (try searching the web for “gprof”) Find and eliminate inefficiencies in code

This concludes the programming-specific part of quiz section Any questions?

C++ Templates - Introduction Templates are cookie-cutters with which the compiler generates real C++ code. Templates themselves do not exist. When a template is used, (that is, specialized for a specific type), it get instantiated. This is when actual machine code is generated. The instantiation creates a version of the template where each placeholder is replaced by its specialization. At this point, the specific version of the template comes into existence and can be compiled. It does not exist otherwise! In a very real way, a template just does a search and replace for each type you specialize the template for. It’s just done for you, behind your back. These template slides are freely stolen from Albert Wong

C++ Templates - Problems Problem: –Because templates do not really exist, they don’t exist to the compiler until they are instantiated! Effects: –Template code will not get compiled until it is used (ie, instantiated). Thus, the compiler will not catch syntax errors until the template is used! –A specialization (a place where the template is actually used) instantiates all relevant templated code before it. If templated code occurs in a different file, it will not get instantiated by that specialization. If templated code occurs later in the same file, it will not get instantiated by that specialization. –Worse yet: implicit template instantiation Only explicitly used templated code will be instantiated. Thus, if templated code occurs in the same file and before the template specialization, it still will not get instantiated by that implicit specialization!

C++ Templates - Possible Problem I Unfortunately, yes. Although b is undeclared, no warnings or errors will be generated. It appears to “compile” because nothing actually instantiates the template, so the compiler never sees the template code. /* Array.hh */ #ifndef ARRAY_HH #define ARRAY_HH template class Array { Array( int i ) { b = “Hello Mom!”; } }; #endif /* ARRAY_HH */ Will this code compile?

C++ Templates - Possible Problem II The link error happens at a.GetCapacity() Nothing from a template gets instantiated until it is either used or explicitly instantiated. Array ::GetCapacity() is used at a.GetCapacity(), but the function definition is not in this file. The definition of the function is in Array.cc, but it is never used there. Thus the definition of Array ::GetCapacity() never gets instantiated and compiled to object code. /* main.cc */ #include using namespace std; #include “Array.hh” int main(void) { Array a(10); cout << a.GetCapacity() << endl; return 0; } Will this program link?

C++ Templates - Avoiding the Problems There are 3 conventions to avoiding template problems: –Write all the code inline in the.h file –Write the code in two files, but #include the implementation file at the bottom of the.h (essentially the same as above) –Write the templated class as you would with a normal class (using a header and implementation file) Create a new source file and #include the implementation file there. Inside this new file, explicitly instantiate all your templates. This new instantiation file is the one that you compile, not the implementation file. Advantages of the third method: –It is not necessary to recompile all the code that uses the template (just the template itself). –The third method instantiates the entire templated class all at once, removing potential link problems.

C++ Templates - The Safe Way To make the previously broken program link properly, explicitly instantiate an integer version of the Array template. Remember, each specialization will require their own line in the instantiation file Compile line: g++ -Wall -ansi main.cc ArrayInst.cc The proper procedure Write the template, separated into a header and an implementation file Create an instantiation file for the template which includes the implementation file. Compile the instantiation file and not the template implementation file. The instantiation file generates the object code for the template. /* ArrayInst.cc */ #include “Array.cc” template Array ; This line forces the instantiation of the Array class template (and all its member functions), for int s.

Other Tools for CSE 326 Shell scripts –A series of shell commands which are read and executed by the shell (like a DOS batch script). –“Shell commands” may be: Executables such as emacs and time Built-in primitives such as ls and for-loops –Search the internet for tutorials or sample shell scripts “tcsh builtin commands” worked well at Google …

Other Tools for CSE 326 (part 2) Awk –A pattern scanning and processing utility. It searches file(s) for specified patterns and perform associated actions. –Search the internet for tutorials or samples “awk tutorial” worked well at Google … Gnuplot –A command-driven function and data plotting program –Try ing the course alias with websites you found; your classmates will thank you!