CS16, Summer 2012

Lab Orientation Assignment
(Lab00: part of Hw1)

Goals for this assignment

By the time you have completed this lab orientation part of Pre-lab 1, you should be able to

Step by Step Instructions

Step 0: Create your CoE Account (if necessary)

If you don't already have one, you must create a College of Engineering (CoE) account to use for labs and programming assignments. You must be enrolled in this course in GOLD to do so. If you already have an account, then skip to step 1.

If it doesn't work - see troubleshooting

Step 1: Go to CSIL and find a free computer to use

Finding CSIL: CSIL is located in Harold Frank Hall (HFH). You enter from an outside door. To locate CSIL, find the "main front entrance" to Harold Frank Hall, on the side of the building that faces the ocean. Stand outside the double glass doors, with your back to the building, facing the ocean. The entrance to CSIL is now on your left.

The computers in CSIL are just like the computers in the Cooper Lab, where your weekly Lab sessions (discussion sections) will be held. FYI: the Cooper Lab is located in the Engineering Science Building, room ESB 1003. ESB is located at the corner of campus closest to the airport, furthest away from Isla Vista. ESB is divided into two parts, with a pedestrian bridge overhead. ESB 1003 is in the part of the building closest to the bike path. The door to ESB 1003 is on the ground floor, at the corner that faces the airport. But the Cooper Lab is only available during your weekly scheduled discussion section—it is not open for your use at other times.

By the way, the effective steps of this assignment can be accomplished by connecting to CSIL remotely at csil.cs.ucsb.edu but if you don't already know how to connect remotely to a Linux system, then we prefer that you visit CSIL in person to do this work. Eventually you probably will want to connect remotely though, and at that time we refer you to Professor Conrad's separate advice for connecting to CSIL from Windows or Mac.

The remaining instructions assume you are at CSIL working on one of the computers there.

Step 2: Log on to your account

When you sit down at a computer in CSIL (or Cooper lab), you'll see a prompt that asks you for your username. Enter the username that you created for your College of Engineering computer account. This is probably the same as your UCSBNetID (your umail account), unless you specified something different when you created your account.

When you are asked for a password, enter the password you chose for your College of Engineering account (which is not necessarily the same as your umail password.)

Don't worry if nothing appears on the screen while you are typing your password.

You should find that your username and password are accepted, and you get a "desktop" that looks similar to the Windows or Mac OS desktop. In fact, what you get is neither—the systems in Cooper and CSIL use "Linux", which is a different operating system.

In the rest of this assignment, we'll walk you through a few of the basics of using this desktop. Most things, though will likely be pretty familiar to you, because they aren't that different from Windows or Mac.

If your username/password don't work - see troubleshooting (at address above in Step 0).

If you want to view these instructions at CSIL, a web browser is available there. Use your mouse and find the Applications Menu at the top left of the screen. Select Internet, then Firefox:

   Internet, Firefox

Step 3: Bring up a terminal window

On the Linux systems, we can do a lot of things by pointing and clicking with the mouse, just like on Windows or Mac. But there are also many things we can only do (or do more easily) with the command line.

So, one of the first steps will often be to bring up a "Terminal Window", which is the Linux "command line".

Here's how:

Here's what it should look like (click on a thumbnail to bring up a bigger image)

Selecting the menu option Result
Applications, Internet, System Tools Terminal Window

Step 4: Create some directories

At the command prompt, we are going to type several commands to create folders (called "directories") on Linux in which you can store your programs. The commands are shown in the box below—but first, a little explanation.

Each of the cd commands shown below is a command to "change directory"—that is to move into a different folder on the hard drive.

Each of the mkdir commands "makes a new directory" (i.e. a new folder).

Each of the pwd commands "prints the working directory", i.e. it tells you where you are on the hard drive.

At the command prompt, type each of these commands. What you type is shown in bold. You should get back the output shown (except that the part in italics will be different for each user).

-bash-4.1$ cd
-bash-4.1$ pwd
-bash-4.1$ mkdir cs16
-bash-4.1$ cd cs16
-bash-4.1$ pwd
-bash-4.1$ mkdir lab00
-bash-4.1$ cd lab00
-bash-4.1$ pwd
-bash-4.1$ cd
-bash-4.1$ pwd

Checking if it worked

To see if it worked, you can use the file manager on the desktop. Drag any windows that might be covering up the icon that says "Home" on your desktop—it should be near the upper left hand corner of the screen:

Home Directory

When you double click on this, it will bring up your home directory. You should see inside a folder called cs16. If you double click on that, you should see inside of it, a folder called lab00

Note that you could also use mouse clicks and menu options to create these folders, instead of the command line. If you have trouble with the command line, then for today, its ok to do it that way.

Eventually, though, we want you to learn some of the Unix commands also—the reasons it's important to know both will become more clear as you move deeper into the study of programming and Computer Science.

Step 5: Copy a C program file into your account

Next we want to copy a file called firstCProgram.c into the directory that we'll refer to as ~/cs16/lab00.

Remember that "folder" and "directory" are interchangeable words.

As review, here is what ~/cs16/lab00 means:

Open a terminal window, and use the cd command to navigate to the ~/cs16/lab00 directory as you did in step 6. When you type pwd, you should see that you are in ~/cs16/lab00.

Then type the following command at the Unix prompt. This says you want to copy a file from my directory into your ~/cs16/lab00 directory.

cp ~kyledewey/cs16/lab00/firstCProgram.c ~/cs16/lab00
If you get an error message, see "Troubleshooting cp" below before asking anybody for help.

If it works, then you should be able to type the ls command (that's the lowercase letter L as in "list" followed by the letter "s") to see that you now have a file called firstCProgram.c in your directory:

-bash-4.1$ cp ~kyledewey/cs16/lab00/firstCProgram.c ~/cs16/lab00
-bash-4.1$ ls

Troubleshooting cp: If you have trouble, check this:

Step 6: Compile and run the program

Assuming you successfully completed Step 5, and are now in the ~/cs16/lab00 directory and it contains the file firstCProgram.c, we are ready to run the program. Before you do, type the pwd and ls commands (print working directory, and list files). The result should look like this—except you'll see your home directory listed instead of /cs/faculty/pconrad.

-bash-4.1$ pwd
-bash-4.1$ ls
firstCProgram.c -bash-4.1$

If that's ok, then we are ready for the next step. To prepare to run the program, we can use the following command:

make firstCProgram

Try typing that now. It should look like this:

-bash-4.1$ make firstCProgram
cc     firstCProgram.c   -o firstCProgram

If you get something else, see "Troubleshooting make" below before asking the TA for help.

If it worked, then try typing ls. You should see that you now have another file in your account, called firstCProgram. This is the machine language version of your program. To run it, you type the following at the Unix prompt:

Here's an example of what that would look like:

-bash-4.1$ ./firstCProgram
Please enter a fahrenheit temperature: 68
68.000000 degrees F is 20.000000 degrees C
More conversions? Enter 0 for no, 1 for yes: 0

Troubleshooting make: If something goes wrong, check these things

Step 7. Use the turnin program to get credit for this assignment

You will have to use the UCSB Computer Science program named turnin to turn in your programming projects and possibly other assignments for this class. In fact, this will be true for most of your CS classes from now on. So you might as well learn how to use it now, by turning in a copy of the sample program and its executable version. Normally we will just want you to turn in the source code (.c) file, but this time you will turn in the whole lab00 directory.

In a terminal window, navigate to your cs16 directory:

-bash-4.1$ cd 
-bash-4.1$ pwd 
-bash-4.1$ cd cs16 
-bash-4.1$ pwd 

When you are in inside your cs16 directory, you are ready for the turnin step.

Type the following at the prompt:

turnin lab00@cs16 lab00

You should be asked if you want to turn in this program. Respond "yes", and then you should get a message indicating that your efforts were successful!

You've completed the required tasks of this lab orientation assignment, but we suggest you stay (or come back) to do some "Extra Learning" tasks below. At the very least you should learn how to use emacs (or vi or another editor program) to answer some of the Pre-lab 1 questions, and especially to prepare for Lab 1.

Log out of your account before leaving the lab.

Extra Learning

Copyright 2009, Phillip T. Conrad, CS Dept, UC Santa Barbara. Permission to copy for non-commercial, non-profit, educational purposes granted, provided appropriate credit is given; all other rights reserved. Adapted by Kyle Dewey from Michael Costanzo for this quarter.