Notes on using Solaris in Austin 320
Table of contents
Bringing up the machine
Solaris is currently available either on the Sun workstations
(porky, buckwheat, stymie, spanky, alfalfa and darla) or
on the Dell computers (csci02 to csci20). Do not use csci00 or
csci01.
The Suns are permanently running Solaris. The Dells are dual
boot machines. If you start on a Dell, it might be running Windows NT.
To start Solaris, type ctl-alt-del, then click on ok if a message box
comes up. Click on shutdown, and select restart. When the
blue boot screen comes up, type 3. Wait for the computer to boot and
for a window to come up asking you to log in.
Please do not turn off the computer or press the reset button.
Doing so will leave the file system in an inconsistent state.
Logging in
Your login id is given to you by your instructor. If you do not know it,
the most likely id is your first initial followed by your last name, up
to a maximum of eight characters total. Use only lower case letters for
your login id. Your password is normally set to the first eight digits
of your social security number, but that is not always done.
On the Suns, you will be put into the OpenWindows window manager.
On the Dells you will be offered an option to use OpenWindows or
the Common Desktop Environment (CDE). I recommend CDE.
You should be able to change your password using command nispasswd.
If you get a complaint that your credentials are incorrect, you will
need to wait until some bugs in the system setup are fixed before
you can change your password. The lab staff apologizes.
Storage of your files
When you log in, your current directory will be your
home directory. Any files that you store there will
remain there until you delete them.
The lab uses a network file server. Whichever computer you are on,
you will see the same view of your files. The file system is currently
stored on csci00.
Please do not be extravagent with disk usage. You can use the du
command to find out how much space you are using.
Bringing up tools
If you right-click the mouse on the background, you get a menu.
Some of the tools are that can be started from this menu are as
follows.
- terminal or command tool
produces a terminal for interacting
with the system using text-based commands. It is under
programs under open windows, and under tools
under CDE.
- netscape or web browser brings up a web browser.
- text editor brings up a basic text editor.
It is under programs under open windows, and under
applications under CDE.
- mail tool or mailer brings up the mail tool.
- file manager brings up a graphical file manager.
You can drag the icon of a file to a text editor to edit it.
Logging out
To log out, click the right mouse button on the background and select
exit or logout.
Editing a program
Edit a program using either the system text editor or another text
editor such as vi or emacs.
Notes on using emacs are available below.
Be sure to save your program before you try to compile and run it.
Give it a name that ends on extension .cc or .cpp. For example, you
might call your program prog1.cc.
Compiling and running a C++ program:
basic method
To compile a program, go to a command tool or terminal window. If the
program is called prog1.cc, then type
g++ prog1.cc
If there are errors, you will be notified. If not, then you will
just see another prompt. The compiler creates a file called a.out.
To run your program, just type command
a.out
Stopping a rogue program
You can forcibly stop your program by typing ctl-C (control and c)
in the terminal window where you started the program. Use this
when your program is apparently in an infinite loop.
If you need to stop a process that is running in background,
use command /usr/ucb/ps u
to get the process number of the process, and
kill -9 n
to kill it, where n is the process number. Be sure that
you are killing the right process.
Putting programs in separate directories
It is a good idea to put each program in a separate directory (or folder).
To create a directory called assn1,
you can use the file manager, or you can just type command
mkdir assn1
To make assn1 your current directory, use command
cd assn1
You can find out your current directory using command
pwd
or command dirs.
File names and paths
To refer to a file called foo in directory dir, write dir/foo.
Notice that you use a forward slash (/), not a backslash (\).
You can refer to your home directory as ~
Using makefiles to build programs automatically
If you have a multipart program, you can compile it by listing all of
the parts on the g++ command line. Suppose that you have a program that
is written in two modules, prog1.cc and utils.cc. Then you can
compile it using command
g++ prog1.cc utils.cc
Do not list any .h files.
You will find it more convenient to use the make utility.
Using a text editor, create a file called Makefile in the directory
where your program is written. Here is a sample makefile.
FLAGS = -c -g -Wall
go:
g++ -o go prog1.o utils.o
prog1.o: prog1.cc utils.h
g++ $(FLAGS) prog1.cc
utils.o: utils.cc
g++ $(FLAGS) utils.cc
The lines of this file have the following meanings.
- The first line defines FLAGS. Wherever you see $(FLAGS) below,
the definition of variable FLAGS is substituted. The flags are:
-c (do not link, just create the .o file), -g (create debugging
information) and -Wall (give all common warnings).
- The lines
go:
g++ -o go prog1.o utils.o
tell how to build the target called go. This will build an
executable program called go by linking together the compiled versions
of prog1.cc and utils.cc. IMPORTANT NOTE: The line after go:
begins with a tab. It MUST begin with a tab, not with a space.
- The lines
prog1.o: prog1.cc utils.h
g++ $(FLAGS) prog1.cc
tell how to build target prog1.o, the compiled version of prog1.cc.
The first line says that prog1.o must be rebuilt whenever either
prog1.cc or utils.h are changed. The second line, which must
begin with at tab, is a command that will rebuild prog1.o.
To build your program, use command
make
This build the first target in file Makefile. To build target
prog1.o instead, type
make prog1.o
To run your program, just type
go
since you said to put the executable in a file called go.
Basic Unix commands
In a Unix command, you can use * to stand for any file name or
part of a file name. For example, to list only files whose names
begins with a q, you type
ls q*
Commands typically read from the standard input and
write to the standard output. Both are normally the
terminal. You can redirect them, though. Use
cmd outfile
to read standard input from infile and to write standard output
to outfile. You can only redirect one or the other if desired.
Put & after a command to run it in background. This cause
the terminal not to wait for the command to finish.
Here are a few useful commands. Use the man command to find
out more about them.
- cancel
- cancel n cancels print job n. Use command lpq to see
what is in the print queue. The printer in room 320 is called
peetie.
- cd
- cd dir makes dir be your current directory.
- chmod
- chmod u+r f gives you read permission to file f.
You can use permissions w (write) and x (execute). You can also take
away permission using chmod u-r. You can give or take away permission
to/from yourself (u), or everybody else (o), or everybody (a).
- cp
- cp A B creates a copy of file A, and calls the copy B
- dirs
- Show the current working directory.
- dos2unix
- This command converts for DOS format to Unix format. It writes
the result to standard output. To write to a file, just redirect
the standard output to the file. For example, use
dos2unix myfile >mynewfile
- du
- Show disk usage. du -s will only show a summary of total usage
in the current directory.
- ftp
- Type ftp mach to open an ftp connection to computer
mach.
- gcc
- gcc is the C compiler. It is similar to the C++ compiler, g++.
- g++
- g++ is the C++ compiler. Use g++ options mprog.cc
to compile program myprog.cc. Common options are as follows.
- -c
- Only create myprog.o, an object-language file that can be linked
to other object-language files.
- -g
- Produce information for a debugger to use.
- -o file
- Put the compiled version into file file.
- -Wall
- Give common warnings. Without this option, warnings are suppressed.
- grep
- grep s f searches file f for occurrences of string s
- kill
- kill -9 n will destroy process number n.
- lpr
- lpr f prints file f.
- ls
- Command ls shows the names of the file and directories
in the current directory. Use ls -l to get a detailed listing,
showing permissions and modification times. The ls command normally
does not show files whose name begins with a dot. To see all files,
use ls -a.
- make
- make runs the make utility to build a program.
- man
- man c shows a manual page for command or
function c.
- mkdir
- mkdir A creates a new directory called A.
- more
- more f shows file f on the terminal.
- mv
- mv is used to rename or move a file. Use mv A B to move file
A to file or directory B.
- popd
- popd removes the top directory from the directory stack.
See pushd.
- ps
- list processes that are running.
- pushd
- The shell maintains a stack of directories. Command
pushd dir pushes directory dir on the top of the stack.
The top is always the current directory. Command pushd swaps the
two topmost directories. See popd.
- pwd
- Show the current working directory (full path).
- rm
- rm f destroys file f.
- rmdir
- rmdir dir destroys directory dir. It can only
be used to remove an empty directory.
- telnet
- telnet mach can be used to open a terminal to machine
mach.
Using diskettes
You can transfer files between your computer and the lab computers
either using diskettes or using ftp. To use a diskette, open a
file manager, and click on check for floppy or
open floppy. Your diskette
will be mounted as /floppy/name, where name is the
label of your diskette.
Be careful using diskettes. They use the DOS file system. Text
files in DOS follow the convention that each line ends with the
two character sequence CR LF, where CR is the carriage-return character
(ascii 13) and LF is the line-feed character (ascii 10). The Unix
convention is that each line ends on just LF. You can use
command dos2unix to convert from DOS form to Unix form, and
unix2dos to convert back.
WARNING. Diskettes often experience problems and become
unreadable. Do not store your only copy of anything on a diskette
unless you don't really mind if you lose it.
To use ftp, just do an ftp from your computer to one of the lab
computers.
Using the emacs text editor
Emacs is a versatile and extensible text editor. It is available
under Unix or for personal computers running Microsoft windows.
See getting emacs for windows to get emacs
for a windows machine.
Emacs offers some advantages for developing programs. One is
that it will automatically indent programs. (Type a tab on a line
to indent that line.) Another is that, when you type a right brace,
emacs shows you the matching left brace, which helps find mismatched
brace problems very quickly.
Emacs also allows you to have several files open at once, which is
convenient for working on a program that consists of several files.
Start emacs by giving command
emacs&
in a terminal window.
There is a one line minibuffer at the bottom of the screen.
It is used to communicate with the user.
ctl-X means hold down the ctrl key while typing X. esc is the
escape key. Emacs is case-sensitive, so s is not the same thing as S.
For the ctl keys, just hold down ctl, not ctl and shift.
You can use menus at the top of the emacs buffer to open and save
files. Some useful ones are Files-open file (to open a file),
Files-save-buffer (to save your work),
Tools-Postscript Print Buffer (to print your file) and
Mule-Set Font/Fontset (to change the font).
You can get a C++ program to be shown with colors to indicate
reserved words, types, etc. by selecting Help-Options-Global Font Lock.
Here are a few of the keyboard commands.
- ctl-space
- Put the mark at the current cursor location.
- ctl-A
- Go to the start of the line.
- ctl-D
- Delete the current character.
- ctl-E
- Go to the end of the line.
- ctl-G
- Abort the current command.
- ctl-H c
- Describe the command that is performed by the keystroke that you give
after ctl-H c.
- ctl-K
- Delete the part of the line after the cursor. If the line has
no nonblank characters, remove the line.
- ctl-O
- Open a new line.
- ctl-R
- Search the file backwards. Type in the word to search for.
Use ctl-R ctl-R (typing it twice) to search again for the previous string.
Each time you hit ctl-R, you will find the next occurrence of a match.
- ctl-S
- Like ctl-R, but seaches forward. Use ctl-S ctl-S to repeat the
last search.
- ctl-W
- Delete all text between the cursor and the mark.
- ctl-X b
- Switch to another buffer
- ctl-X ctl-C
- Quit.
- ctl-X ctl-F
- Start editing a file.
- ctl-X o
- Switch to the other buffer that is being displayed.
- ctl-X ctl-S
- Save the current buffer.
- ctl-X s
- Save all modified buffers.
- ctl-X 4 f
- Open a file in another window.
- ctl-Y
- Paste back the result of the last kill (from the clipboard).
(Emacs keeps a stack of clipboards. If you type esc y after ctl-Y,
you get the next thing down on the stack. Keep typing esc y to see
more on the stack.)
- esc w
- Copy the text between the cursor and the mark to the clipboard.
- esc x
- Give a long command. You type the command in the minibuffer.
- esc %
- Do a replacement. You will be asked at each occurrence whether
to do the replacement. Type y to replace, n to skip, q to quit.
Getting emacs for windows
To get emacs for windows, do an ftp to prep.ai.mit.edu, and go
to directory /gnu/windows/emacs/20.5, and get emacs-20.5-bin-x86.tar.gz
(or the latest version)
in binary mode. You will also need the tar and gunzip utilities
from the utilities directory, as well as the README file and the
emacs list files in emacs-20.5-lisp.tar.gz. If you want multilingual
support, get emacs-20.5-leim.tar.gz. Follow the instructions
in the README file.