CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

Similar documents
Tutorial 1: Unix Basics

Using the Zoo Workstations

Unit 10. Linux Operating System

Lab 1 Introduction to UNIX and C

Unit 13. Linux Operating System Debugging Programs

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Linux Tutorial #1. Introduction. Login to a remote Linux machine. Using vim to create and edit C++ programs

Getting Started With UNIX Lab Exercises

CSC 112 Lab 1: Introduction to Unix and C++ Fall 2009

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

CS1600 Lab Assignment 1 Spring 2016 Due: Feb. 2, 2016 POINTS: 10

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Intermediate Programming, Spring Misha Kazhdan

CpSc 1111 Lab 1 Introduction to Unix Systems, Editors, and C

Laboratory 1 Semester 1 11/12

Unix Tutorial Haverford Astronomy 2014/2015

Parallel Programming Pre-Assignment. Setting up the Software Environment

Practical Session 0 Introduction to Linux

Lab 1 Introduction to UNIX and C

UoW HPC Quick Start. Information Technology Services University of Wollongong. ( Last updated on October 10, 2011)

Introduction to Unix - Lab Exercise 0

Introduction to the UNIX command line

Introduction to Linux

Physics REU Unix Tutorial

1) Log on to the computer using your PU net ID and password.

CS CS Tutorial 2 2 Winter 2018

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

CS Fundamentals of Programming II Fall Very Basic UNIX

Helpful Tips for Labs. CS140, Spring 2015

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Installing VPN client by Jupiter Networks:

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Getting Started with UNIX

Once you have installed MobaXterm, open MobaXterm. Go to Sessions -> New Session, and click on the SSH icon.

Temple University Computer Science Programming Under the Linux Operating System January 2017

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Guided Tour (Version 3.3) By Steven Castellucci as Modified by Brandon Haworth

15-122: Principles of Imperative Computation

Linux File System and Basic Commands

CMSC 201 Spring 2018 Lab 01 Hello World

Part I. Introduction to Linux

User Guide Version 2.0

History. Terminology. Opening a Terminal. Introduction to the Unix command line GNOME

Compiling C/C++ programs

CMSC 201 Spring 2017 Lab 01 Hello World

Introduction to Linux Spring 2014, Section 02, Lecture 3 Jason Tang

Exercise 1: Basic Tools

Lab 2 Building on Linux

1 Getting Started with Linux.

Refresher workshop in programming for polytechnic graduates General Java Program Compilation Guide

Getting started with UNIX/Linux for G51PRG and G51CSA

Linux/Cygwin Practice Computer Architecture

Lab Working with Linux Command Line

Introduction to Linux. Fundamentals of Computer Science

You can use the WinSCP program to load or copy (FTP) files from your computer onto the Codd server.

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

Introduction to the Command line. Introduction to the command line. Introduction to the Command line. GNU/Linux at South Wales

CSCI 2132 Software Development. Lecture 4: Files and Directories

CSC111 Computer Science II

CS 261 Recitation 1 Compiling C on UNIX

Programming and Data Structure Laboratory (CS13002)

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Firewalls can prevent access to the Unix Servers. Please make sure any firewall software or hardware allows access through Port 22.

Lecture 01 - Working with Linux Servers and Git

UNLV Computer Science Department CS 135 Lab Manual

Lab: Supplying Inputs to Programs

Introduction. File System. Note. Achtung!

CSE115 Lab exercises for week 1 of recitations Spring 2011

The Unix Shell & Shell Scripts

CS19001/CS19002 Programming and Data Structures Lab Autumn/Spring Semester. Introduction. Abhijit Das. January 4, 2015

Getting started with Hugs on Linux

Linux Bootcamp Fall 2015

Introduction to UNIX. SURF Research Boot Camp April Jeroen Engelberts Consultant Supercomputing

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Guided Tour (Version 3.4) By Steven Castellucci

ADOBE DREAMWEAVER CS4 BASICS

Tiny Instruction Manual for the Undergraduate Mathematics Unix Laboratory

Terminal Windows, Emacs, Subversion and Make

Chapter-3. Introduction to Unix: Fundamental Commands

Linux Survival Guide

When you first log in, you will be placed in your home directory. To see what this directory is named, type:

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Mills HPC Tutorial Series. Linux Basics I

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

Computers and Computation. The Modern Computer. The Operating System. The Operating System

1. The Mac Environment in SIE 1222

AMS 200: Working on Linux/Unix Machines

EKT332 COMPUTER NETWORK

Linux Exercise. pwd answer: We call this directory (into which you get when you log in) your home directory.

COSC UNIX. Textbook. Grading Scheme

Lab 1: Accessing the Linux Operating System Spring 2009

Perl and R Scripting for Biologists

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

Working with Basic Linux. Daniel Balagué

One of the hardest things you have to do is to keep track of three kinds of commands when writing and running computer programs. Those commands are:

Chapter 2. Basics of Program Writing

Getting started with Hugs on Linux

Transcription:

1 Introduction 1 CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.) This laboratory is intended to give you some brief experience using the editing/compiling/file management tools that are available in the UNIX environment. You will not be required to do any actual programming in this laboratory exercise. However, you will need to follow directions exactly in order to complete the laboratory successfully. While there are usually two ways to accomplish the tasks laid out in this laboratory (either via the windowing environment via point and click or from the command line), we will use the command-line approach for most of this lab. 2 Getting Started Step 1: Obtain your username and password from laboratory teaching assistant. Do not confuse this username/password with your OHIOID and OHIO password, the ones that you use for your email account and for Blackboard. You will need both to successfully complete this laboratory. Step 2: Log on to the workstation that you are sitting at using your CS username/password. When you login for the first time, you may see an error message relating to the desktop. Do not worry about it. Simply click OK. Step 3: Once you have logged in you will see a toolbar on the left with some icons which look familiar to you, including one for the Firefox browser and one for File management. The circle at the top is the Search. Click on this. In the search text box type term to pull up the Terminal icon. Then, using the mouse, drag and drop this icon onto the toolbar at the left. Now the Terminal will be readily available every time you log into one of the lab machines. (You do not need to log into the same machine every time because your desktop configuration and your files are stored on the server and will follow you from machine to machine.) Step 4: Double-click on the Terminal icon and continue with this lab. 3 UNIX Fundamentals UNIX is an operating system just like Microsoft Windows XP and Vista. UNIX is a multiuser operating system. Each machine that you are sitting at may have multiple users. For these laboratory machines, normally, only you will be logged into them. In order to see which other users are using the machine that you are logged into, type who 1

at the terminal prompt and hit enter. The UNIX command shell (the terminal window that you are using) and the windowing environment allow you (i) execute programs, and (ii) view and manipulate files. The UNIX file system consists of directories and regular files. Directories are simply a folder where you place a collection of files. Directories may contain other directories. These other directories are subdirectories of the bigger folder (parent). The root of the entire file system is the directory /. The root of your directory is usually /home/username, where username is your username. 3.1 Listing the Directory From the terminal, you can display all of files (and subdirectories) in your current directory by typing ls (You can also look at your current directory by using the windowing system. It s useful to know how to do both.) With the command ls you can list all of the files matching some pattern in your directory. The wildcard character * can be used to denote any string of characters. So, issuing the command ls *.cc will list all of the files in the current directory with the.cc extension. Similarly, you can give ls the name of a directory to list. Issue the command ls / to see what happens. 3.2 Working Directories The UNIX shell always keeps track of where you are in the file system. In particular, it remembers the location of the current directory that you are working in. This is your working directory. To see your working directory, type pwd This is the command for print working directory. There are two special names for directories in the UNIX shell. The first special name is., which denotes the current working directory. The second name is.. which denotes the parent of the current working directory. 3.3 Changing Directories You can change between directories using the command cd in the UNIX shell. To change to a specific directory, you can issue the command cd directory. For example, cd / changes the directory to the root of the file system. To get back to your home directory, you can always type cd by itself. To get to the parent directory, simply type cd.. The command cd. does nothing (why?). 2

3.4 Creating Subdirectories You can create subdirectories by issuing the command mkdir. For example, the command mkdir CS2400 will create a subdirectory in your home directory called CS2400. 3.5 Coping, moving, and deleting files The commands cp, mv and rm copy, move, and delete files in your directory. 3.6 Manual Pages To find out more information on a given UNIX shell command, simply type man command For example, man cp displays the manual pages for the cp (copy) command. 3.7 Additional UNIX Commands Some other basic UNIX commands that you can enter from your terminal: rm delete a file. mv move (rename) a file. more display a file. 3.8 Lab Answer Sheet After reviewing the previous sections, answer questions 1 8 on the lab answer sheet. 4 Change Your Password Place your cursor on the terminal window. One of the first commands that might want to use is the following: Change your password by using the passwd command. % passwd passwd: Changing password for example Enter login(nis+) password: (ENTER YOUR OLD PASSWORD) New password: (ENTER YOUR NEW PASSWORD) Re-enter new password: (RE-ENTER YOUR NEW PASSWORD) NIS+ password information changed for example NIS+ credential information changed for example Contact John Tysko if you ever forget your password. tysko@ohio.edu 3

5 Create Directories The prompt that is being displayed will be the name of the workstation at which you are sitting. To keep your space tidy we will begin by creating some directories. Type mkdir 2400 make the directory 240a under the current working directory Type cd 2400 go into the new directory Type mkdir Labs Type cd Labs Type mkdir lab1 Type cd lab1 This directory is where you should perform all of your work for this lab. 6 Useful UNIX Constructs The UNIX shell has a number of useful features that allow you to manipulate the input and output of files. I/O Redirection: Redirecting the standard output. You can redirect the output of any UNIX command to an output file (file.out in this example) instead of to the screen by placing the symbol > in front of the output file name. For example, the following command will output a list of the files in your current directory and save them to the specified file: ls > file.out Redirecting the standard input. You can redirect your program to take its input from a file (file.in in this example) instead of from the keyboard by using the input redirection symbol <. myprog < file.in Pipes: ls more Script: > script record.out Script started, file is record.out > ls notes1.aux notes1.tex~ notes2.tex > exit exit Script done, file is record.out > more record.out 4

7 The C++ Compiler The C++ compiler in our UNIX environment is free software developed by the Free Software Foundation (GNU). The program is g++. To compile a C++ program using g++, simply type g++ -Wall program.cc If the program file program.cc is complete and correct, the g++ compiler will produce an executable file called a.out. To run your program, simply issue the command./a.out (Note that. is the current directory.) The g++ compiler has many options. To see them, issue the command man g++. You may ignore most of these options for now. However, the following options to g++ may be useful to you. -g: This option compiles your program with useful debugging information included. -o outfile: This option places the result of the g++ in the file outfile. This is one way to change the name of your executable from a.out to something else. -c: This option stops compilation at the object file level. We will use this option later. -O: Optimize the code. This option is incompatible with the -g option. -Wall: This option shows the user all warnings messages that the compiler detected. 7.1 Lab Answer Sheet Complete questions 9 11 on the lab answer sheet. 8 Problem Solving The next few problems will give you some practice using the UNIX editors, the compiler, and some other useful commands. Writing and compiling a simple C++ program First, go to the lab1 directory you created. Use an editor that you feel comfortable using. Good choices are emacs nano or gedit All real programmers meet a new programming environment with a Hello program. We will now write such a program in our new environment. 5

* * * * * * * * * * * * * * * * * * * * * * * * * * program: Lab1 Name : your name Email : Your preferred e-mail address Description: This program prints a message to the screen. Date : today s date * * * * * * * * * * * * * * * * * * * * * * * * * * #include <iostream> using namespace std; int main( ) { cout << "Hello Me! \n How am I today? \n"; You can be creative with your message. return (0); } 1. Name the file whatever you wish an appropriate choice would be lab1.cc 2. Compile lab1.cc by using the command g++ -Wall lab1.cc 3. Issue the command ls and answer question # 12 on the lab answer sheet. 4. Run the executable by typing./a.out (see the output on the screen) 5. Use I/O redirection to save the results of this command as follows. You can redirect the program output to a file called lab1.out instead of to the screen../a.out > lab1.out (warning: do not redirect to lab1.cc) 6. Issue the command ls and answer question # 13 on the lab answer sheet. 7. Type more lab1.out to make sure that you produced the correct output. 8. Answer the remaining questions on the lab answer sheet. 9 Printing the Style Guide Finally open a browser and print out a copy of the CS2400 Programming Standards (written by Dr. Chelberg) for your reference. The URL is http:ace.cs.ohio.edu/~chelberg/classes/361/style-guide.html 6

Optional Reference: Useful Emacs Commands In emacs, special commands are invoked by typing certain key combinations. Control-x == hold down the control key and type x. Meta-x == type ESC and then hit x. Control-x Control-c === Save the current buffer/file and leave emacs. Control-x Control-s === Save the current buffer/file. Control-x Control-f === Find file (start editing a new file). Control-h b === Help - key bindings. Control-x 1 === Delete other windows. (Changes from a split screen environment to a single screen.) Control-x o === Move to other window. Control-s === Search for... Control-space === set mark. Control-w === delete text from mark to the cursor. Control-y === paste text. Meta(ESC)-x compile === compile within emacs. Meta(ESC)-x next-error === find next error after a compile. Meta(ESC)-x goto-line === goto-line. Control-h i == Texinfo 1 portions of this lab assignment provided by Dr. David Juedes and Mal Gunasekara. 7