CSCI 112
Lab 1 - Introduction to Linux and C
I want to make
sure you all meet your GTA and learn about his/her program submission system.
Objectives:
- Meet with your Graduate Teaching Assistant (GTA) in
person and learn what he has to say. The intro to the lab will
cover: 1) GTA's teaching policies and expectations, 2) a brief comparison
of C and Java, 3) basic rationale for using C/Linux/gcc/submit, etc.
- Get up and running using your account on the Linux
operating system on a computer in the lab.
- Use the
a2ps
command to get hard
copy of source files.
- Use an editor (
pico
, emacs
or vim
).
- Use
gcc
to compile your program.
Readings:
- Read about Linux and a chosen editor on one of the Web references page.
- Some commands you may
want to read about are: ls,
cp, rm, mv, ps, chmod, mkdir, cd, ps, finger, ssh,
ftp, gcc, and man.
- The emacs family has some nice features for programming, but
you can use another text editor if you like. I think pico is quite friendly for the first-time
users.
- Read these 3 sets of Power Point slides: Makefile, Hello World, TA's materials on lab submission system
Deliverables: (DUE
BY THE END OF YOUR 2nd LAB MEETING!)
- A hard copy of your answers to a set of Linux Questions
(shown below).
- Submittal of your helloworld.c
Makefile and answers files.
Lab Rules
-
Everyone should work individually on each lab,
unless you receive explicit instructions from GTA to collaborate. I
do not mind you discussing the logical solution to
problems BEFORE the lab, but not exchange of code of any type is allowed.
-
If
your GTA allows some level of collaboration on the particular assignment -
please make sure to communicate quietly, so you would not disturb other
students.
- If there are any readings listed on the lab page, you
must read them PRIOR to lab. It is the easiest way to avoid becoming
lost about what to do and how to do it.
- The lab assignments are due at the time stated next to
the Deliverables. This may vary, so be sure to check this for each lab.
- The work you do in lab will show up on the related
exams. It is strongly recommended that you do all assignments.
- Late assignments will not be accepted so make sure that
you are prepared when coming to the lab.
- There is a lot of work to do in CSCI112. Remember, this
is where you build a strong programming foundation, so do not fall behind.
- Sometimes, the labs may be slightly changed by your TA,
if something is not working, etc. If you have done your lab before the lab
period (what I would actually recommend!), make sure that you submit
proper file. You want to be 100% sure that you submitted the right thing -
show up for your labs and talk to your TA!
- For purpose of this lab - you all need to have a
directory, named csci112
created at the root of your esus account. It
should have sub-directories named with lab numbers (i.e. lab1, lab2, etc.) Number of lab
directories should match number of websites with lab assignments (e.g.
this is lab1).
You are expected to keep all your files in csci112 directory until two
weeks after the end of the current semester.
TO DO (for today's
lab)
- Be sure your computer is running Linux. If not, reboot
into Linux.
- Log in to your account
- Go to a directory you will use for csci112. (Create a
separate one if you have not already done so,
make sure to name it csci112).
- Create a sub-directory called lab1 to use for today's lab
and change to that directory.
- Start up the editor of your choice
- $
pico
(for the pico editor)
- $
emacs
(for the emacs editor)
- $
vim
(for the vim editor)
The emacs family has some nice features for
programming, but you can use another text editor if you like. I think pico is
quite friendly for first-time users.
- Answer the following questions as briefly as possible
by typing the answers into the word processor buffer.
Make sure your answers are
numbered and appropriately ordered.
- What
does the shell prompt look like on your account?
- Type
ls. What did happen and
why?
- Explain
how you made a directory called csci112.
- Explain
how you made csci112 your current working directory.
- From
your csci112 directory, describe three separate ways to go back to your
home directory.
- Navigate
our Linux system enough to estimate the number of students currently
"logged in" on esus. Write down the
number and explain how you determined it.
- Save
this file with the name answers.txt.
- Now, build a program in C to do the following (
See the HelloWorld
. The file is in PDF format on purpose,
as I do not want you to use "copy-paste" option. Sorry, life is brutal
sometimes... :) )
:
- Print
out the phrase "Hello World!"
- Once you have written
your program in a text editor, save it as helloworld.c
- Create a simple Makefile for
your program (
See the MakeFile)
. Hint: Find out
what is a difference between "gcc -o
..." and "gcc -c ..." (See the WebRefs).
- Compile the program
using
make helloworld
command.
- If errors were
reported, fix the program and re-make it until it compiles without errors.
- Execute the compiled
program (by typing
helloworld
, or $PWD/helloworld
).
- Open your answers.txt file with your text
editor and verify that it looks correct.
- Now print hard copy of your source file (i.e. helloworld.c), your Makefile, and your answers.txt
file by
typing:
a2ps -P orca helloworld.c Makefile
answers.txt
- Hand in your hard copy to
the TA. Be sure to identify each page with your name and staple multiple
pages together.
- Submit your assignment.
LAB 1 ENRICHMENT
- Try changing the helloworld
program so it says "Happy New Year!" instead of "Hello
World!".
- Try printing a line of astericks
*************** before and after the "Happy New Year" message.
- If you wanted to use the C++ compiler instead, replace gcc with g++.
- Figure out what is the difference between "./helloworld" and "helloworld" commands, and when both commands act in the same
way.