Notes on using Solaris 2.9 in Austin 320


Table of contents


Bringing up the machine

The computer should already be turned on. If it does not appear to be turned on, first check the monitor, and turn that on. If there is still no response, press the power button on the keyboard. It is in the upper right-hand corner.

Please do not turn off the computer or reboot it. Doing so will leave the file system in an inconsistent state.

Logging in

Your login id is given to you by your instructor or the system administrator. It is the same as your ECU mail id. Your password will be different, though.

Your login id works for both Windows and Solaris. Your initial password needs to be changed on both systems.

  1. Initial login to Solaris. Log in at one of the machines in the lab by typing your user id, a carriage return, and then your assigned password and a carriage return. A small window will appear asking you to change your password. Move the mouse into that window. Type your old password, then your new password twice. Choose a new password that has at least 8 characters in it. You will be logged out automatically. Try to log in again using your new password.

    If you are asked for your LDAP password, then you made a mistake typing your password. Just type a carriage return and start again.

  2. Initial login to Windows. The Windows machines are located in Austin 321. Log in using your user id and initial password a1b2c3d4. You will need to change your password.

Note.When you first log in, you might be given a choice of Common Desktop Environment (CDE) or Gnome. Choose Gnome.


Logging out

Please log out when you leave. To log out, select the Actions menu at the top of the Gnome screen, and select logout.


Storage of your files

When you log in, your current directory will be set to your home directory. (You might be more familiar with the term folder, which is the same thing as a directory.) 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. They are not stored on the computer on which you are working. You will see the same home directory for both Windows and Solaris. You can store files there using one operating system and get them using the other.

Please do not be extravagent with disk usage. You can use the du command to find out how much space you are using. Command du -s -k will print a single usage number, the number of kilobytes that you are using in the current directory.


Command line interface

You are probably familiar with point-and-click computing using an end-user operating system such as Microsoft Windows or MacOS. Graphical user interfaces can be very convenient, but there is another form of interface to the operating system that also has some advantages. Solaris is a version of Unix. Unix is an operating system that was developed by programmers for programmers, and it provides a command-line interface that can be a versatile tool. Commands can easily be combined with one another to perform tasks that have not been built into any single piece of software.

To use the command line interface, open a terminal window. (Right-click the mouse on the background, and select New Terminal.) You type commands in the terminal window, one per line. Type the return key at the end of the line to perform the command.

The up arrow key will allow you to repeat prior commands. Type !c to repeat the most recent command that begins with c.

A Unix command typically starts with the name of the command, then has options (normally starting with a dash) and then a list of file names. For example, command

  ls -l -a horse.cc
runs the ls command with options -l and -a, on file horse.cc.

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*


Redirecting the standard input and standard output

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 <infile >outfile
to read standard input from infile and to write standard output to outfile. You can redirect just the standard input or just the standard output if desired.

Put & after a command to run it in background. This causes the terminal not to wait for the command to finish. You can continue to use the terminal while the command runs.


Search path

A command is really just the name of a file that contains the executable code for the command. For example, the ls command runs the file /bin/ls. The command interpreter searches for files to run by looking at a variable called PATH. It is a sequence of directories separated by colons. You can see the value of your PATH variable by typing command

  echo $PATH

You can set your path using the export command.

  export PATH=".:/bin:/usr/local/bin:/usr/ccs/bin"

sets the path so that first the current directory (.) is searched, then /bin, then /usr/local/bin, then /usr/ccs/bin.


Bringing up tools

You can get some tools by selecting the Applications menu at the top of the screen.


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. For a C++ program, give the program a name that ends on extension .cc or .cpp. For example, you might call your program prog1.cc.


Aliases

You can define aliases that shorten commands. For example,

  alias handin="~cs2610-001_fall03/bin/handin cs2610-001_fall03"
causes command handin
  handin 1 assn1.cc
to be an abbreviation for
   ~cs2610-001_fall03/bin/handin cs2610-001_fall03 1 assn1.cc


Reading and sending email

You can read and send email on the lab machines. Your email address is your user id followed by @cs.ecu.edu. Use the pine command to start the Pine email client.


Compiling and running a C++ program: basic method

To compile a C++ program, go to a terminal window. If the program is called prog1.cc, then type

   g++ -Wall 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


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++ -Wall prog1.cc utils.cc
or, if you are compiling all of the .cc files in the current directory,
  g++ -Wall *.cc
Do not list any .h files on the command line.

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.
  1. The first line defines variable FLAGS. Wherever you see $(FLAGS) below, the definition of variable FLAGS is substituted. The flags are used for the g++ command, and are as follows.

    -c Do not link, just create a .o file. When file utils.cc is compiled with this option, the compile creates file utils.o that needs to be linked to other files before it can be run.
    -g Create debugging information so that you can run the debugger on this program.
    -Wall Give all common warnings.

  2. 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.

  3. 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 (go) 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.


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.


Running the debugger

There is a debugger called gdb. To run the debugger for a C++ program, compile the program using option -g. That is, use command line

  g++ -Wall -g prog1.cc
Then use command
  gdb a.out
to run your program. At the prompt, type run to run your program. If you stop the program using ctl-C, you can do debugger command bt to get a trace of the run-time stack, most recently entered frame first. Use commands up and down to move up and down in the stack. (Unfortunately, up moves down and down moves up.) You can print the value of a variable x using command print x.

Command break f causes the program to stop each time it starts function f. There are other commands as well. Type help to see them.

To exit the debugger, use command quit.


Killing print jobs

Please never print a binary file. It will consume a lot of paper. To kill a print job, use command lpq to show the print queue and lprm n to remove print job number n. You can only remove your own print jobs. To remove somebody else's, find a system administrator.

If necessary, you can stop the printer by pulling out the paper trays.


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 ~

Each directory has two special directories in it called . (another name for the current directory) and .. (the directory above the current directory). So command cd .. moves up one directory, and cd ../.. moves up two directories.


Basic Unix commands

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. The lprm command does the same job.

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 r (read) 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

Unix uses a convention that a line is ended by a line feed character (Ascii 10). Windows/DOS uses a convention that a line is ended by a two character sequence, carriage-return line-feed (Ascii 13 then ascii 10). The dos2unix command converts for Windows/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 -k will only show a summary of total usage in the current directory, in kilobytes.

ftp, sftp

Type ftp mach to open an ftp connection to computer mach. You can use commands similar to Unix commands to set the current directory (cd) on the remote machine and list (ls) the contents of the current directory. Use the put command to copy a file to the server and the get command to get a file from the server.

sftp does a similar thing, but opens a secure ftp connection.

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.
-O
Run the code optimizer. This both produces better quality machine code and gives some additional warnings that are only discovered during optimization. It can, however, make using the debugger more difficult.
-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.

passwd

Change your password.

ps

List processes that are running. There are two common versions of this command, /bin/ps and /usr/ucb/ps. They work a little differently. Command /usr/ucb/ps u gives a fairly readable output.

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.


Remote access

Some of the computers in the lab support remote access via secure shell (ssh). You should be able to log into atlantic.cs.ecu.edu or morehead.cs.ecu.edu using your login id, for example. You can get ssh for Windows from the ECU download page (look at the top of the page) or from from ftp://ftp.ssh.com/pub/ssh. Get SSHWinClient....exe, where the ... indicates the current version and build.

Ssh can also be used for file transfer.


Using diskettes

You can transfer files between your computer and the lab computers either using diskettes or using ssh. 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.


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), File->Postscript Print Buffer (to print your file) and Options->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 Options->Syntax Highlighting (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 (or the latest version of emacs), and get emacs-20.5-bin-x86.tar.gz (or the file for the latest version). Be sure to do the transfer in binary mode. You can use Winzip to unpack the archive, or you can get 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.