Using UNIX for the JCT TCP/IP Lab
- 18 Cheshvan 5762 (04/11/2001)
- Now recommend using ssh instead of telnet.
- 20 Adar 5761 (15/03/2001)
- Updated to reflect the situation of this year.
- 18 Cheshvan 5760 (28/10/1999)
- Updated to reflect the situation of this year.
TABLE OF CONTENTS:
- Working in the UNIX lab
- Logging into a Station in UNIX
- Editing Programs in UNIX
- Compiling Programs in UNIX
- Running More Than One Program at a
Time in UNIX
- Copying Programs from the TCP/IP Lab
Web Site in UNIX
- Working from a Microsoft Windows/NT station
For the TCP/IP lab, you will have to know how to do the following on
- log into UNIX computers
- edit programs
- compile programs
- run more than one program at a time
- copy programs from the TCP/IP lab web site
I recommend that you do as much of your work as possible on the
stations in the UNIX room, because the editor will be easier to use,
and because you will be able to use more than 1 window at a time
Nevertheless, you can work in one of the Microsoft Windows labs and
ssh/telnet to the UNIX lab machines (names: shana200, shana201, etc.).
NOTE: although you may work in pairs, it is absolutely
forbidden to give your password to your partner! It is
also forbidden to log into your account and leave, letting
your partner work in your account.
If you have already given your password to your partner,
change it immediately. On UNIX, you can change it via the
passwd command. If you have the same password on
Lev/Midot, you'll also have to change it there.
You can make files in your account accessible to your partner,
via the chmod and/or chgrp commands. Or you
can mail each other copies of your source code. See me if you
have problems with this.
Each station displays a login window. Type in your user name (login
name) and password. If you have forgotten it, go to Nachum Danzig
(Wyler 232) to get a new UNIX password. Currently, his office hours
are Sunday - Thursday 13:30 - 14:30.
I recommend that you use 'emacs' for editing your files.
It has nice support for editing programs, including color-coding
different parts of the program (e.g., comments are in red),
automatically indenting, etc.
- Emacs on-line help
- Note the following conventions:
|Convention ||Meaning ||Example |
|C- ||control key (CTRL)
|| C-s = control-s
||meta key (in the UNIX lab, this is the ALT key).
Alternatively, you can use the ESC (escape) key. But
it works a little differently:
- When using the ALT key, you press it
at the same time as the other key.
- When using the ESC key, you first press
the ESC key, and afterwards the other key.
|M-x = meta-x = |
- press ALT and x at the same time.
- press ESC, and afterwards press x.
||RETURN (ENTER) key
|| To go to line 25 of the file:
M-x goto-line RET 25 RET
- followed by the string "goto-line",
- followed by ENTER,
- followed by the string "25",
- followed by ENTER
- Emacs/Xemacs has its own tutorial.
You can probably access it via the Help menu. Alternatively, you
can access it via typing C-h (control-h)
followed by t.
NOTE: below are other types of emacs help. These also you can
probably access via the Help menu. However, I will list how
to access them via the keyboard.
- After the tutorial, you can get more information about emacs, the GNU
C compiler, and other programs via
emacs' 'info' system. To enter
info, type C-h i.
- In fact, C-h is how you access many help facilities of
emacs. There are many others besides the tutorial and info mentioned
above. Type C-h ? to see the list of help facilities.
- There is also what emacs calls the META key. On
the PCs, the ALT key is the META key.
M-x means META-x.
- To get the colors, click with the mouse on Help --> Options
--> Global Font Lock.
NOTE: in the shiur on 20 Adar 5761, 15/3/2001, I mentioned
another method to get colors. Forget it. This method is
simpler and better. For example, this method automatically
updates the colors; you don't have to type C-l (control-L).
- Besides the normal editing commands, here are some commands that will
probably be useful for this lab:
- C-x 2
- Split the emacs windows into 2 sub-windows.
- M-x goto-line RET number
- Emacs does not display line numbers. Use this command to jump to
a certain line. This is useful, because when the C compiler
detetcs an error, it will say on which line it is.
- M-x compile
- If you are viewing/editing C code and run this command from
that buffer, this will compile it. The default command it
uses is make. If you do not know the UNIX
make command, you can change the command line to a
gcc command line (see below).
The compilation, and any messages it generates, will take
place in other emacs buffer. If there are any error messages,
click on the error message with both the right and left mouse
buttons at the same time, and you'll jump to the line of C
code where the error was reported.
NOTE: if there are 3 buttons on the mouse, click on the
middle mouse button instead of left and right togther.
- Compiling with GNU C compiler (gcc)
- When your entire program is in one source code file, then
trivial. If the name of the file is myprogram.c, then, to compile:
gcc -o myprogram myprogram.c
The -o myprogram option means to store the program in a file
called myprogram (without the '.c' at the end).
- Now let's say that your program is distributed among two files, main.c
and utilities.c, and
that you want to call the program 'communicate'. Then you would use
the following sequence of commands:
gcc -c main.c
gcc -c utilities.c
gcc -o communicate main.o utilities.o
The first 2 lines compile source files but does not link them.
Thus, the output is not ready to run. Instead, it produces
object files that have the same name as the source files, but
with '.o' at the end. The third line links the object files &
produces a ready to run executable. Note that in the previous
example with myprogram.c, the compiling and linking were done
via one command.
- You can compile a gcc program from within emacs. Go the window that
contains the program you want to compile. Then I think you
type M-x compile.
- You can get more information about gcc via emacs info mode, and via
- If you want to write in C++, then use the command g++. This calls
the GNU C compiler, but in a way suitable for C++.
- When you hand in an assignment, you must indicate the exact
command(s) used to compile it.
- See above for compiling the program
from within emacs.
- You may use the UNIX make command if you want. But we
won't have time in this lab to teach you how to use it.
If you compile with gcc, you can use the 'gdb' command to debug.
Read about this command in emacs' 'info' mode.
There should also be a debugger command called 'ddd'. This has a
Of course, you can always use 'printf' or 'fprintf' to display debug and error
This is very simple when sitting at a UNIX station: simply open 2 or
more windows, and run a program in each of them.
Simple. View the program via Netscape. Then save the file in text format.
There are several ways to get documentation about UNIX commands and
functions (including socket functions):
- Gnome Help Browser
- If this does not start automatically, then look at the panel at
the bottom of the screen. There should be an icon with a question
mark on it. Click that. From this browser you can access all (or
almost all) of the other types of documents listed below.
- man pages
- This is the classic UNIX documentation. The 'manual' is divided
into several sections. For example, section 1 are normal user
commands. Section 2 are system calls (including the socket
interface). Section 3 are other standard routines, etc.
Here are different ways to view the man pages:
- From the unix command line, type the 'man' command. Here are
- man xterm -- learn about the xterm (X windows
terminal emulation) program.
- man 2 socket -- learn about the 'socket' function
(which is in section 2 of the manual).
- man 4 socket -- learn about the socket programming
interface (in section 4 of the manual).
- man -k socket or apropos socket--
get a list of all man pages dealing
with sockets (actually, get a list of all man pages whose
summary lines contain the word 'socket').
- Type xman to get an X windows interface to the
'man' command. From there, you can click on 'Getting
Started' to learn how to use xman, or 'Manual Page' to see
the man pages. The sections of the manual are the same as
for the 'man' command above.
- From within emacs, type
M-x RET man RET man_page.
If you want specify the manual section, do it like this:
- Emacs info
- See the section on emacs info above.
Again, I strongly urge you to work in the UNIX lab, or at least from a
UNIX station. But there might be times when that is not practical.
3.1 Logging into a Station on a PC
I assume that you know how to log into a PC. After that, however, you
will have to ssh/telnet to one of the UNIX lab stations (shana200,
shana201, ..., shana220).
I strongly suggest that you use 'ssh' (Secure SHell) instead
of 'telnet'. Ssh has the following advantages over telnet:
- it encrypts data sent between the local and remote hosts.
This means, that even if someone intercepts your password, they'll
have a hard time reading it.
- it verifies that you're really talking to the machine you
intend to talk to. This makes it harder for another machine to
steal the IP # of the remote host.
To use ssh, run the 'putty' command. There might be another SSH
program available on our MS Windows stations as well.
If you cannot use ssh, I suggest that you use the EWAN telnet
program instead of the standard Microsoft telnet program.
Whether you use ssh or telnet, you enter the same user name (login
name) and password as you do when sitting at a UNIX station.
3.2 Editing Programs on a PC
You'll still run emacs. However, you should run it with the
-nw option. This option stands for 'no windowing'; it will
prevent emacs from trying to start up an X window (X is the windowing
system on UNIX). Instead, it will take over your telnet window.
Alternatively, if you know the vi editor, you might want to
There might not be a META key when working like this. In this case,
use the ESCAPE key. See the
for how to use the escape key.
3.2 Compiling Programs on a PC
Same as compiling programs for UNIX.
3.4 Running More Than One Program at a Time on a PC
There are 2 ways:
- You can run the ssh/telnet program more than once.
- Use emacs. Emacs can split the screen of an
ordinary text terminal or of a telnet window. Type
C-x 2 to split the screen into 2. Type
C-x o to move the cursor to the 'other' window.
You can run normal UNIX commands from within emacs. Type
M-x shell to start a UNIX shell. This shell buffer will be
called '*shell*'. To create another shell buffer, you must
rename the first shell buffer via the
M-x rename-buffer command and then typing
M-x shell to start a second shell.
3.5 Copying Programs from the TCP/IP Lab Web Site on a PC
Viewing the program via Netscape or Internet Explorer and then saving
it will save it on the PC (either on the local disk or in your LEV home
directory). But you need the file in your UNIX directory.
You cannot run Netscape from UNIX and have it display on your PC
screen. But, from UNIX you can run 'lynx'. THis is a web browser
that works in text mode, so you can use if from within the telnet
window. After you view the file via lynx, save it; the file will be
in your UNIX home directory.
This document maintained by Haim Roman,