C0 | Documentation
About Downloads Tutorial References Courses

C0 at Carnegie Mellon in Qatar

Navigating your account in Linux

Open up a Terminal window to access the Linux command prompt. (Unlike typical graphical interfaces for operating systems, here you are entering commands directly to the OS and can change hundreds of options to give finer control of what you're doing.) On the Linux machines in the computer lab 1032, you can access a Terminal window using the Applications --> Accessories menus.

Once you open the terminal window, enter the following command to login to the machine that is configured for C0 ssh 15122-1.qatar.cmu.local. If the machine is acting slow, you can replace 15122-1 with 15122-2 or 15122-3 or 15122-4.

Your terminal window will give you a prompt and you will be in your home directory in your Andrew account. Type ls (to list files) to see what files and directories are there. Back in the day, we used to call folders "directories". To move to another directory, use the cd command (for "change directory"):

$ cd private

ACADEMIC INTEGRITY NOTE: You should store your program files inside the private directory (or a subdirectory inside this directory) since this directory is automatically set to prevent viewing by other users. Remember that you should protect your code from being viewed by other students as part of the academic integrity policy for this course.

Since you will write a number of programs for this course, it pays to make a subdirectory inside the private directory. Once you cd into the private directory, make a new directory named 15122:

$ mkdir 15122

Let's confirm that our directory now exists. You can see what files and directories are in the current directory like this:

$ ls

Now go into this directory using cd again:

$ cd 15122

To go back up one directory if you need to, use this command:

$ cd ..

You can go up two directories and down another directory (e.g. public) like this:

$ cd ../../public

If you ever get lost while you change from one directory to another, you can use pwd to find your present working directory. Or if you want to go back to your home directory, simply type:

$ cd

You can also access any directory from your home directory using the shell variable $HOME or the "tilde" character ~. For example, you can get to your 15122 directory from any directory on Andrew by typing this:

$ cd $HOME/private/15122

or this:

$ cd ~/private/15122

Finally, you should download and print the Linux quick reference page below for a more complete list of basic Linux commands. Some quick examples:

  • ls -lha: List all files (including hidden files) in long, human-readable format
  • rm: Remove a file (Be careful! It won't ask for confirmation)
  • cp: Copy a file --To copy a file from the parent directory (..) to the current directory (.): cp ../file.txt .
  • mv: Move a file

LOGGING OUT: Remember that you must log out from the computer in the lab. Closing the terminal window is not enough! To log out, go to the System menu and choose Log Out. You don't want others accessing your account if you leave yourself logged in.

COURTESY NOTE: In the computer lab, if you don't use your lab computer for a set period of time, the screen saver will launch and you can't access the terminal unless you type your password in. Some students have left the computer this way so they can "reserve" the machine for themselves later. If we find a machine in screen saver mode and no user at that terminal, we will automatically log you out so you may lose work if you're not careful. Please be considerate of others and don't lock the terminal.

More information:

Editing programs

You can use any editor you wish to write and edit your programs but we highly recommend you try out emacs since this editor can do much more than just help you edit your code (as you will see).

To set up emacs to edit C0 files and to get access to the C0 tools, you can run this script (it will edit your $HOME/.emacs file and your PATH in your $HOME/.cshrc file):

$ source /afs/qatar.cmu.edu/usr8/srazak/public/setup-c0.csh

If you use a different shell than csh, you will need to adjust your path accordingly. See your TA or CA if you need more help.

When you want to edit a program now, you can enter emacs specifying the file name you want to edit. You should be in the directory where the file is or should be (to keep things simple for now). For example, to open the file test.c0 in emacs, you'd go to the directory where this file should be stored and enter:

$ emacs test.c0

If the file exists, it will be loaded into the emacs editor. If the file does not exist, you will get a blank editor to start typing in the code. The configuration file .emacs you edited earlier will add color coding to your c0 programs. Keywords will show up in one color, variables in another, etc. This will make it easier to edit your program code.

To exit emacs, press C-x, C-c (In emacs keyboard shortcuts, capital C stands for Ctrl and capital M stands for "meta", which is usually Alt or Esc.). To get proficient at using emacs, you should, at minimum look at the first two links below.

What the script does

The script that you ran with source does two important things. If the script doesn't work, or if you're setting up C0 on your home computer, you can do both of these things yourself. First, the script adds /usr/local/cc0/bin to the $PATH a shell variable (like $HOME) that tells your shell where to look for programs to run. In particular, if you're using the default shell, tcsh, the script adds the following line to $HOME/.cshrc:

setenv PATH ${PATH}:/usr/local/cc0/bin

If you're not using tcsh, you'll need to edit the $PATH variable a different way. Type echo $0 at the command line to see which shell you're using. If tcsh is printed, you're using csh. If bash or zsh or something else is printed, you can use a search engine to find out how to edit the $PATH environment variable in your shell.

Second, the script sets up Emacs to use C0. To do this yourself, run /afs/andrew/course/15/122/c0-mode/configure and copy the lines it prints out into your ~/.emacs file.

More information:

Using the C0 tools

The setup-c0.csh script above has already updated your PATH for your account so the system can find the C0 compiler, interpreter, and debugger without you having to explicitly give the full path to the compiler's location.

Let's compile and run a simple C0 program. First copy the example file into your directory:

$ cd $HOME/private/15122
$ mkdir hello
$ cd hello
$ cp /afs/andrew.cmu.edu/course/15/122/examples/hello.c0 .

Now run the C0 compiler on the C0 source file hello.c0 to produce the binary executable "hello":

$ cc0 hello.c0 -o hello

You can now run your program like so:

$ ./hello

REMEMBER: Don't forget to save and compile your source code after making changes! Otherwise, you will find yourself very confused when your executable is doing something different than your source code.

You can use coin, the C0 INterpreter, to quickly evaluate C0 statements without having to compile and run a complete program.

$ coin
--> 2*2;

Coin will then show you the result of "4". To stop a long-running command in coin, you can press Ctrl+C. To exit coin, you can type #quit.

You can use "Code", the C0 DEbugger, to step through the execution of a C0 program, line by line:

$ emacs hello.c0
C-c C-d

You should see each line of the main method be highlighted in emacs. As you press return, the next line will be highlighted. Any output will be shown at the bottom of your emacs buffer.

More information:

Accessing your account and files using ssh

You can always access your files on the Linux server in the lab (room 1032) when the lab has no classes scheduled. In addition, you can access your files via ssh in several ways. ssh (secure shell) a protocol for securely logging into remote servers like the Andrew system.

Windows machines: Download a free ssh client like PuTTY. When you log in, specify the server unix.qatar.cmu.edu. Once you login, enter the following command to login to the machine that is configured for C0 ssh 15122-1.qatar.cmu.local. If the machine is acting slow, you can replace 15122-1 with 15122-2 or 15122-3 or 15122-4.

Mac and Linux machines: Open up a terminal window and run this command:

ssh -X -l yourusername unix.qatar.cmu.edu

and enter your password when prompted to log in. (Your machine might ask if you want to add the server to a list of known hosts; if so, answer yes.) Once you login, enter the following command to login to the machine that is configured for C0 ssh 15122-1.qatar.cmu.local. If the machine is acting slow, you can replace 15122-1 with 15122-2 or 15122-3 or 15122-4.

How SSH Works. SSH sends characters from your machine to a remote machine to be run -- the text output is sent back across the network to be shown in your terminal. The X forwarding option (-X) sends mouse movements and graphics such as your emacs window, as well.

AFS Kerberos Tickets

As you can see when you run pwd, your files are stored on a filesystem called AFS. To make sure you are authorized to access files, AFS uses a security framework called Kerberos. When you login, the kinit command is silently called for you to initialize kerberos and obtain security "tickets".

To see what tickets you currently have, run:


Notice that these tickets expire after about a day. What happens when they expire? You can't write to your files anymore. Inside emacs, this might produce strange errors such as "file is read-only". If your tickets expire, you will need to renew them, as follows (you can do this in a separate terminal window so that you don't lose your work in emacs):


written by Tom Cortina, 1/12/11
updated by Rob Simmons, 8/22/12
updated by Jon Clark, 8/27/12
updated by Saquib Razak, 1/14/13