|
Computer Science 322 Operating Systems Mount Holyoke College Spring 2008
|
|
Lab 0: Getting Reacquainted with C and Unix
Due: 10:00 AM, Monday, February 4, 2008
- Send me mail at jteresco@mtholyoke.edu with a brief (a
couple sentences) indication of your level of experience with the
Unix operating system and its variants, plus a list of other
operating systems you have used. Also include a list of programming
languages you have used and your proficiency in each, and anything
else you'd like me to know about your background coming in. (1
point)
- (3 points total) We will be using several Unix-based systems
within the Computer Science department. Log into and familiarize
yourself with your CS Unix accounts.
- Log into a Linux system in the Clapp 202 lab. Boot into
Ubuntu (the Linux distribution we used) if they're in Windows
or shut down when you arrive.
Open a terminal window and execute this command:
uname -a > linux.txt
This will execute the command uname -a, which prints a
variety of information about the system you are on, and redirects
the output, which would normally be printed in your terminal
window, to the file linux.txt.
- Log in remotely to the Linux server, babyred.mtholyoke.edu. On babyred, you will use the same
password you use for the lab Linux systems and you will have
access to the same files you have in your account on Clapp 202
Linux systems. Use a Secure Shell (ssh) client, either from the
Linux command line or from elsewhere. Secure shell clients are
standard on most modern Unix-based systems (including Mac OS X)
and are readily available for Windows systems.
In your terminal window that is logged into babyred,
execute this command:
uname -a >> linux.txt
This is the same as what you did on your local Linux system, except
that we are using >>
to redirect output. The only difference
here is that instead of creating a brand new file linux.txt
(thereby overwriting the previous contents of the file), the command
will append the output of uname -a to the end of the file linux.txt.
- We will also be using a small cluster of systems running
other variants of Unix, including FreeBSD and Solaris. The head
node of this cluster is named mhccluster.teresco.org.
The cluster has its own usernames/passwords and file space. Log
in remotely to the head node with ssh.
In your terminal window that is logged into mhccluster,
execute this command:
uname -a > cluster.txt
You now have a file cluster.txt, with some system information
about the cluster head node.
Look at the contents of the files linux.txt and cluster.txt. Which information is different? Can you guess what
some of the information in the two files might mean?
- Identify the function of and experiment with these Unix Commands:
ls cd cp mv rm mkdir pwd
man chmod cat more grep head tail
ln find rmdir wc diff tar
Give a one sentence description of each command in a file unix.txt.
- Emacs (emacs from the Unix command line) is a powerful
text editor. You will want to become familiar with it. Identify
the function of and experiment with these Emacs Commands:
C-x C-s C-x C-c C-x C-f C-x C-w C-g C-a C-e
C-d C-_ C-v M-v C-s C-r M-%
C- before a key means hold down Ctrl and hit that key.
M- indicates the "Meta" key, which on most systems is Esc. To issue a Meta command, hit the Esc key, release
it, then hit the key for the command you wish to issue. Use the
keystrokes rather than the menus. It will save you time in the
long run!
Include a brief description of each Emacs keystroke in your file
unix.txt.
Learn these commands - you will use them often. Hints can be
found in the Unix and Emacs web pages linked from the course
website. Ask others in the lab if you're not sure how to do
something in the Unix environment. Share your tips and tricks with
each other.
Note: when logged into the CS Lab Linux systems, Emacs will open in
its own window and allow you to use the mouse to move the cursor
and to operate the menus. When logging in remotely, you need to
forward your X11 display to your screen. To do this from the CS
Linux systems, you will need to add the -Y flag to your ssh
command:
ssh -Y mhccluster.teresco.org
Verify that you can display an Emacs window from mhccluster
to one of the CS Linux systems. To get your prompt back (by
running Emacs - or any command for that matter - in the
background), follow your command line with an &. This will
allow you to work in Emacs and your terminal window concurrently.
- Create a directory in your accounts both on the cluster and
on the CS Lab Linux systems to store your work for this class
(something like "322" or "cs322" might be a good
choice). Change the permissions on the directory so only you
have read or write access to it. Ask a classmate to verify that
she cannot see the contents of this directory on each system.
Append the output of an ls command that shows the
appropriate permissions to both the linux.txt file (for the
directory on the Linux side) and the cluster.txt file (for
the directory on the cluster). Hint: something like ls -l
cs322 is probably the command you want.
- Copy the C program here that computes the late
penalties for this course to your cluster account. Compile and run
it, redirecting your output to a file late.txt. (1 point)
- Copy the file /cluster/home/terescoj/shared/make-example.tar to your cluster
account. It is a "tar file" of a small C program that
demonstrates the use of multiple source files and Makefiles.
Extract the files (tar xvf make-example.tar) and compile the
program with make. In a plain text file called make.txt, briefly describe how make uses the rules in the
Makefile to produce the executable main. (1 point)
- Write a C program that takes an arbitrary number of command-line
parameters, each of which should represent an integer value. Print
out the sum of the values provided. Call your C program argadder.c and include a Makefile that guides compilation of
your program into an executable argadder. (3 points)
Hint: See main.c in the make example, and note that the
parameter argc to the main function is a count of how many
command-line strings are included in the argv array of strings.
Also, argv[0] is not the first parameter, it is the program name
itself, and this array entry for the program name is included in the
value of argc.
To transfer files from your Linux lab account to the cluster, you can
use the scp ("secure copy") command. It works much like the
standard cp command, except that you can specify hostnames for
the source and/or destination files. For example, to transfer the
file linux.txt from your Linux lab account to the cluster in a
subdirectory cs322, open
a terminal window and change to the directory that contains the file
(say, cs322) and execute the command:
scp linux.txt mhccluster.teresco.org:cs322
Alternately, you could log into mhccluster and issue the command
in the opposite direction, with the same net effect:
scp babyred.mtholyoke.edu:cs322/linux.txt .
The "." in the command indicates that the destination for the
copy is your current working directory.
To submit this lab, use the turnin utility on the cluster head
node, using the directions on the course home page. Please include
the files linux.txt, cluster.txt, unix.txt, late.txt, make.txt, argadder.c, and Makefile in
your submission.
Please use the exact filenames specified (for this lab and all
semester) to make my job easier when gathering your submissions
together for grading. You don't want to annoy your grader with
misnamed or missing files just before he grades your assignment.