This text is available online at: http://cs.likai.org/teaching/getting-started In this article, you will find some general tips for doing programming assignments for courses in the CS department. A number of these courses expect your code to run on csa2 or csa3, which runs BU Linux. The undergraduate lab provides you with Linux machines where you can program and gsubmit your homework, but you may prefer to work from the comfort of your own home. Here we present some suggestions for establishing a workflow for doing programming assignments from home. The suggestions mentioned here are merely, well, suggestions. They are believed to be working well for most people. Feel free to try something else if that suits you better. Working from home and transferring files overWe assume that you have Internet at home. Depending on the link speed, some options may work better for you than others. Most programming assignments expect your code to run on Linux, so you want to have access to the same GCC compiler and tools from home and be able to test your code as you edit files. If you use Windows...Your programming assignment is assumed to use the POSIX API as opposed to Win32. Therefore, the key is to adapt Linux into your Windows workflow. You will still need to know how to use some basic Linux commands, which you can find explained in the "Using Linux primer" section below. You have the following options:
For transferring files:
If you use Mac OS X...Mac OS X already comes with most Unix tools and provides POSIX API, so you don't need anything special. The instructions for Linux below also works for you. You would probably be using a Terminal.app or iTerm.app for terminal emulator. Make sure you have X11 and Xcode installed. You should still test your code on csa2/csa3 prior to submission to make sure everything works. You have the option to have two working copies of the assignment, one on your local machine and one on csa2. You can keep them synchronized with the "rsync" command below, described in the "If you use Linux..." section. For editing source code on Mac OS X, I personally use Carbon Emacs. You can always use Xcode (only for editing; please do not submit Xcode project files). If you have other recommendation, let me know. If you use Linux...The ssh command allows you to run command line programs on another computer, with the remote input and output directed to the local terminal. You can use that to connect to csa2/csa3 and run many Linux commands (such as those mentioned in the "Using Linux primer" section below). These commands run on and use the filesystem on csa2/csa3, and they never touch files on your local machine. In this case, you don't need to worry about transferring files from your computer over to csa2/csa3. ssh csa2.bu.edu If the login name on your local computer differs from your CS account, then you should use "cslogin@csa2.bu.edu" whenever you specify the host name, where cslogin is the login name of the CS account. If you have a fast Internet connection, e.g. live on-campus and is connected to ResNet, you can enable SSH X11 forwarding, so you can run programs that involves a graphical user interface. You will need to enable X11 forwarding by passing the -X flag to ssh, like this. ssh -X csa2.bu.edu If you have a slower connection, e.g. DSL, it may work for you if you use compression by additionally passing the -C flag to ssh. But the connection may still cause the programs to run sluggishly. If you don't want to depend upon a fast Internet connection, you may choose to work on your local machine, then transfer files using the scp command. For example, copying hello.c to my home directory (~/) on csa2, I type: [liulk@localhost ~]$ scp hello.c csa2.bu.edu:~/ You can recursively copy a directory by supplying the -r flag. See "man scp" for more information. Man pages are discussed in the "Using Linux primer" section below. It is a quick way to obtain reference material to a command, system call, or Standard C Library functions. If you have two working copies, one on your local machine and one
on the CS cluster, that you'd like to synchronize frequently, use the
rsync command. For example: [liulk@localhost ~]$ rsync --rsh ssh -av ~/path/to/source csa2:~/path/to/destination This avoids the need to transfer unmodified files. The trailing slash "/" at the end of the path is significant; in most cases, you want to make sure the slash is either both absent (preferred) or both present in the source and destination paths. Again, "man rsync" gives you the complete reference to the "rsync" command. Both scp and rsync commands are available on Cygwin and Mac OS X as well. Alternatively, on Linux, you can use gFTP (command is "gftp"), which allows you to transfer files over SSH2 graphically. This is not available if you use Cygwin or Mac OS X. Using Linux primerSince Linux underlies the main infrastructure in the CS department, and most faculty members and teaching fellows use Linux, you're going to be most effective with your homework if you learn how to use Linux. You're also more likely to get support. Mac OS X and Cygwin under Windows provide many of the same tools as Linux does, many things in this section also applies to these scenarios. We assume you can get to a command line, either by starting a terminal window (e.g. GNOME Terminal, Konsole, XTerm) or by SSH into csa2/csa3. You will get a prompt that looks like this: You may see a slightly different prompt, but it's no big deal. It should end with a dollar sign (bash) or percentage sign (tcsh) depending on your shell. Most commands discussed here should work, unless otherwise noted. Navigating around the file systemThe command prompt keeps track of where you are in the file system (called the "current working directory"). When you run a command and give it a relative path (a path that doesn't begin with a slash), the path is relative to the current working directory. You can see what's in a directory by issueing the "ls path" command. If path is missing, it lists the current directory. For example: [liulk@localhost ~]$ ls You can navigate the working directory by issuing the "cd" command, like this. [liulk@localhost ~]$ cd tmp The tilde "~" is a shorthand for the home directory, and ".." is the parent directory for any directory. You can also type in a partial command or file name and hit the tab key for auto-completion, as illustrated below. [liulk@localhost liulk]$ cd Music/ Continue typing 'ik' and then hit tab again. Note: tcsh doesn't print out completion candidates. It only beeps. [liulk@localhost Music]$ ls Mike\ Link\ Harvey\ Taylor\ -\ Beat\ Elementals/ This should save you a lot of typing. At any point, you can do "cd ~" to return to your home directory. You can pass the "--color" argument to "ls" to make the listing color coded. This way, you can tell easily what type of file it is. [liulk@localhost ~]$ ls --color Green signifies an executable. Blue is a directory. Normal files are not colored. You can also pass the "-l" argument to "ls" to do a long listing, showing permission, owner, file size, date, and time. I'll leave it for you to try. You might find "--color" and "-l" very tedious to type. You can alias ls to 'ls --color' by editing your bashrc file (if you use bash) or your cshrc file (if you use tcsh). Getting helpThe most essential command you will find is "man" which displays a manual page for any command or system call you will need. You will find this command indispensible. The syntax is "man command", for example: [liulk@csa2 ~]$ man cat Will bring up the manual page for the "cat" command. This works for standard library functions and system calls too, like: [liulk@csa2 ~]$ man malloc Once in "man", you can use arrow keys to navigate line by line, as well as using "page-up" and "page-down" keys. The "home" and "end" keys may not work. But you can type in "g" (lowercase g) to go to the beginning, or "G" (uppercase g) to go to the end. Type "q" to quit. If "page-up" and "page-down" keys don't work for you, try "b" (going backward) for page-up and "f" (going forward) for page-down. Sometimes a library function has the same name as a command. Man pages are organized into sections. Section 1 is for command line user programs, section 2 is for system calls, section 3 is for Standard C Library functions. For example, there is an "exit" shell command (to quit a shell or a shell script), an "_exit()" system call (probably you will never use this), and an "exit()" standard C library function (wraps around _exit() by calling some clean-up routines before terminating the current process). Type in "man sectionnum command" to specify the correct manual page. When in a man page, the top left (and top right) corner shows which section the current manual page is from. In this case, I was looking at the printf command in section 1, not the printf() Standard C Library function. Use "man 3 printf" to get to the printf() man page for the Standard C Library function.The "man" command is also available on Cygwin and Mac OS X. Most man pages can also be found on the web, for example: linux.die.net. Text editors that you may tryLinux has many wonderful text editors that has syntax highlighting. Note: this section does not apply to Cygwin nor Mac OS X. GNOME Text Editor can be launched by typing the "gedit" command. KDE Writer can be launched by typing the "kwrite" command. Both of them are compared side by side as follows: As you can see, KDE Writer also supports block folding. Both of them can open multiple files in tabs. I personally use Emacs, but it takes a while to customize it to your own liking and be used to it. I use it to enforce consistent code indentation and to highlight trailing spaces in a line. Dealing with TAR (or TAR.GZ) filesFrom time to time, teaching staff may want to distribute a number of files together. It is easier to collect all the files into a (tape) archive file and distribute just that file. The whole archive file may be compressed to reduce its size, and the compression method can be seen from the file name. File names ending in .tar.gz or .tgz are gzip compressed; .tar.bz2 or .tbz2 are bzip2 compressed; or simply .tar are uncompressed. To extract,
The "?xvf" tells the tar program what to do: 'z' means it's gzip compressed, 'j' means it's bzip compressed. 'x' means to extract, 'v' means to be verbose, and 'f' provides a file name (otherwise tar program reads from standard input). If the archive file contains a large number of files and you do not want to see any of them, remove 'v' from the command. If you want to only look at the content of the archive file to see which files are in it,
The 't' character means to 'test' the archive. If you want to create your own archive file, collect all the files into a directory. You may call the directory any name you want, but let's call it "the-dir" below.
Note that the convention is to derive the archive file name based on the directory name you created. The character 'c' means to create an archive. You can find out more about the tar program in its man page, man tar. The "tar" command is also available on Cygwin and Mac OS X. Conclusion
|




