This chapter is devoted to the hours of fourth week.We continue to give more information about the fundamentalcommands of the Unix operating system. We also give some introductory information about the system's bootup sequences.This could be given in chapter 3 and perhaps it would be morepedagogical. However we have preferred to start at a singleuser level and then to introduce multiuser structure.
Working with Unix
Unix is a powerful system for those who know how to harness itspower. In this chapter, We'll try to describe various ways to useUnix's shell, bash, more efficently.
Wildcards
In the previous chapter, you learned about the file maintencecommands cp, mv and rm. Occasionally, you want to deal with more than one file at once --- in fact, you might wantto deal with many files at once. For instance, you might want to copyall the files beginning with data into a directory called ~backup. You could do this by either running many cp commands, or you could list every file on one command line. Both ofthese methods would take a long time, however, and you have alarge chance of making an error.
A better way of doing that task is
to type:
/home/larry/report# ls -F
1993-1 1994-1 data1 data5
1993-2 data-new data2
/home/larry/report# mkdir ~/backup
/home/larry/report# cp data* ~/backup
/home/larry/report# ls -F ~/backup
data-new data1 data2 data5
/home/larry/report#
As you can see, the asterix told cp
to take all of the files beginning with data
and copy them to ~/backup.
Can you guess what
cp d*w ~/backup
would have done?
What Really Happens?
Good question. Actually, there are a couple of special charactersintercepted by the shell, bash. The character "*", an asterix, says ``replace this word with all the files that willfit this specification''. So, the command cp data* ~/backup, like the one above, gets changed to cp data-new data1 data2data5 ~/backup before it gets run.
To illustrate this, let me introduce a new command, echo. echo is an extremely simple command; it echoes back, or prints out, any parameters. Thus:
/home/larry# echo Hello!
Hello!
/home/larry# echo How are you?
How are you?
/home/larry# cd report
/home/larry/report# ls -F
1993-1 1994-1 data1 data5
1993-2 data-new data2
/home/larry/report# echo 199*
1993-1 1993-2 1994-1
/home/larry/report# echo *4*
1994-1
/home/larry/report# echo *2*
1993-2 data2
/home/larry/report#
As you can see, the shell expands the wildcard and passes allof the files to the program you tell it to run. This raises aninteresting question: what happens if there are no files thatmeet the wildcard specification? Try echo /rc/fr*og and bash passes the wildcard specification verbatim tothe program
Other shells, like tcsh, will, instead of just passing
the wildcard verbatim, will reply No match. Here's the
same command run under tcsh:
mousehouse>echo /rc/fr*og
echo: No match.
mousehouse>
The last question you might want to know is what if I wantedto have data* echoed back at me, instead of the list offile names? Well, under both bash and tcsh, justinclude the string in quotes:
/home/larry/report# echo "data*"
data*
/home/larry/report#
OR
mousehouse>echo "data*"
data*
mousehouse>
The Question Mark
In addition to the asterix, the shell also interprets a questionmark as a special character. A question mark will match one, andonly one character. For instance, ls /etc/?? will display all two letter files in the the /etc directory.
Time Saving with bash
Command-Line Editing
Occasionally, you've typed a long command to bash and,before you hit return, notice that there was a spelling mistakeearly in the line. You could just delete all the way back andretype everything you need to, but that takes too much effort!Instead, you can use the arrow keys to move back there, deletethe bad character or two, and type the correct information.
There are many special keys to help
you edit your command line,most of them similar to the commands used in
GNU Emacs. Forinstance, Control t
flips two adjacent characters.( Control t means hold down the key
labeled ``Ctrl'', then press the ``t'' key. Then release
the ``Ctrl'' key. )
Command and File Completion
Another feature of bash is automatic completion ofyour command lines. For instance, let's look at the following example of a typical cp command:
/home/larry# ls -F
this-is-a-long-file
/home/larry# cp this-is-a-long-file shorter
/home/larry# ls -F
shorter this-is-a-long-file
/home/larry#
It's a big pain to have to type every letter of this-is-a-long-file whenever you try to access it. So,create this-is-a-long-file by copying /etc/passwd to it ( cp /etc/passwd this-is-a-long-file ). Now, we're going to do the above cp command very quickly and witha smaller chance of mistyping.
Instead of typing the whole filename, type cp th and press and release the Tab. Like magic, the rest of the filename shows up on the command line, and you can type in shorter. Unfortunately, bash cannot read yourthoughts, and you'll have to type all of shorter.
When you type Tab, bash looks at what you'vetyped and looks for a file that starts like that. For instance,if I type /usr/bin/ema and then hit Tab, bashwill find /usr/bin/emacs since that's the only file thatbegins /usr/bin/ema on my system. However, if I type /usr/bin/ld and hit Tab , bash beeps at me.That's because three files, /usr/bin/ld}, /usr/bin/ldd},and /usr/bin/ld86 all start with /usr/bin/ld on my system.
If you try a completion and bash beeps, you can immediatelyhit Tab again to get a list of all the files your startmatches so far. That way, if you aren't sure of the exact spellingof your file, you can start it and scan a much smaller list of files.
The Standard Input and The Standard Output
Let's try to tackle a simple problem: getting a listing of the /usr/bin directory. If all we do is ls/usr/bin,some of the files scroll off the top of the screen. How can wesee all of the files?
Unix Concepts
The Unix operating system makes it very easy for programs to usethe terminal. When a program writes something to your screen, itis using something called standard output. Standard output,abbreviated as stdout, is how the program writes things to a user.The name for what you tell a program is standard input(stdin). It's possible for a program to communicate with the userwithout using standard input or output, but most of the commands wecover in this book use stdin and stdout. For example, the ls command prints the list of the directoriesto standard output, which is normally ``connected'' to your terminal.An interactive command, such as your shell, bash, reads yourcommands from standard input. It is also possible for a program towrite to standard error, since it is very easy to make standardoutput point somewhere besides your terminal. Standard error (stderr)is almost always connected to a terminal so an actual human will readthe message.
In this section, we're going to examine three ways of fiddling withthe standard input and output: input redirection, output redirection,and pipes.
Output Redirection
A very important feature of Unix is the ability to \bf redirect}output. This allows you, instead of viewing the results of acommand, to save it in a file or send it directly to a printer.For instance, to redirect the output of the command ls /usr/bin},we place a > sign at the end of the line, and say what file wewant the output to be put in:
/home/larry# ls
/home/larry# ls -F /usr/bin > listing
/home/larry# ls
listing
/home/larry#
As you can see, instead of writing the names of all the files,the command created a totally new file in your home directory.Let's try to take a look at this file using the command cat.If you think back, you'll remember cat was a fairly useless command that copied what you typed ( the standard input ) to theterminal ( the standard output ). cat can also print a file to the standard output if you list the file as a parameter tocat:
/home/larry# cat listing
...
/home/larry#
The exact output of the command ls /usr/bin} appeared in the contents of listing. All well and good, although it didn'tsolve the original problem. ( For impatient readers, the commandyou might want to try is more.
However, there's still a bit more to talk about before we get there. )However, cat does do some interesting things when it's outputis redirected. What does the command cat listing > newfile} do?Normally, the > newfile says ``take all the output of thecommand and put it in newfile}.'' The output of the command cat listing} is the file listing} .So we've invented a new ( and not so efficient ) method of copying files.
How about the command cat > fox? cat by itself reads in each line typed at the terminal (standard input) and prints itright back out (standard output) until it reads Ctrl d. Inthis case, standard output has been redirected into the file fox. Now cat is serving as a rudimentary editor:
/home/larry# cat > fox
The quick brown fox jumps over the lazy dog.
(press Ctrl d )
We've now created the file fox that contains the sentence ``The quick brown fox jumps over the lazy dog.'' One last use ofthe versitile cat command is to concatenate files together. cat will print out every file it was given as aparameter, one after another. So the command cat listing foxwill print out the directory listing of /usr/bin, and thenit will print out our silly sentence. Thus, the command catlisting fox > listandfox will create a new file containing thecontents of both listing and fox.
\Input Redirection
Like redirecting standard output, it is also possible to redirectstandard input. Instead of a program reading from your keyboard,it will read from a file. Since input redirection is related tooutput redirection, it seems natural to make the special characterfor input redirection be <. It too, is used after the commandyou wish to run.
This is generally useful if you have
a data file and a command thatexpects input from standard input. Most commands
also let youspecify a file to operate on, so < isn't used as much
inday-to-day operations as other techniques.
The Pipe
Many Unix commands produce a large amount of information. Forinstance, it is not uncommon for a command like ls /usr/bin to produce more output than you can see on your screen. In orderfor you to be able to see all of the information that a commandlike ls /usr/bin , it's necessary to use another Unix command,called more. ( more is named because that's the promptit originally displayed: --more--}. In many versions of Linuxthe more command is identical to a more advanced command thatdoes all that more can do and more. Proving that computerprogrammers make bad comedians, they named this new program less. ) more will pause once every screenful of information. For instance, more < /etc/rc} will display the file /etc/rc} just like cat /etc/rc would, except that more will let you read it. more also allows the command more /etc/rc, and that's the normal way of invoking it.
However, that doesn't help the problem that ls /usr/bin displays more information than you can see. more < ls /usr/bin won't work --- input redirection only works with files, not commands! You could dothis:
/home/larry# ls /usr/bin > temp-ls
/home/larry# more temp-ls
...
/home/larry# rm temp-ls
However, Unix supplies a much cleaner way of doing that. You can
just use the command ls /usr/bin | more. The character "|" indicates a pipe. Like a water pipe, a Unixpipe controls flow. Instead of water, we're controlling the flowof information!
A useful tool with pipes are programs called filters. A filter is a program that reads the standard input, changes it insome way, and outputs to standard output. more is a filter--- it reads the data that it gets from standard input and displaysit to standard output one screen at a time, letting you read thefile. more isn't a great filter because its output isn'tsuitable for sending to another program. Other filters include the programs cat, sort, head,tail. For instance, if you wanted to readonly the first ten lines of the output from ls, you coulduse ls /usr/bin | head.
Multitasking
Using Job Control
Job control refers to the ability to put processes ( anotherword for programs, essentially ) in the background and bringthem to the foreground again. That is to say, you want to be able to make something run while you go and do other things, buthave it be there again when you want to tell it something or stopit. In Unix, the main tool for job control is the shell --- it willkeep track of jobs for you, if you learn how to speak its language.
The two most important words in that
language are
fg, for foreground,
and bg, for background. To find out
how they work, use the command yes at a prompt.
/home/larry# yes
This will have the startling effect of running a long column of y's down the left hand side of your screen, faster than youcan follow. ( There are good reasons for this strange command toexist. Occasional commands ask for confirmation --- a "yes"' answer to a question. The yes command allows a programmerto automate the response to these questions. To get them to stop,you'd normally type Ctrl c to kill it, but instead you shouldtype Ctrl z this time. It appears to have stopped, but therewill be a message before your prompt, looking more or less likethis:
[1]+ Stopped yes
It means that the process yes has been suspended in the background. You can get it running again by typing fg at the prompt, which will put it into the foreground again. If youwish, you can do other things first, while it's suspended. Try afew ls's or something before you put it back in the foreground.
Once it's returned to the foreground, the y's will start coming again, as fast as before. You do not need to worry thatwhile you had it suspended it was ``storing up'' more y'sto send to the screen: when a program is suspended the whole programdoesn't run until you bring i back to life. ( Now type Ctrl c to kill it for good, once you've seen enough ).
Let's pick apart that message we got
from the shell:
[1]+ Stopped yes
The number in brackets is the job number of this job, and will be used when we need to refer to it specifically. ( Naturally, sincejob control is all about running multiple processes, we need some wayto tell one from another ). The + following it tells us thatthis is the ``current job'' --- that is, the one most recently movedfrom the foreground to the background. If you were to type fg, you would put the job with the + in the foreground again.( More on that later, when we discuss running multiple jobs at once ).The word Stopped means that the job is ``stopped''. The job isn'tdead, but it isn't running right now. Linux has saved it in a specialsuspended state, ready to jump back into the action should anyonerequest it. Finally, the yes is the name of the process thathas been stopped.
Before we go on, let's kill this job
and start it again in adifferent way. The command is named kill
and can be used inthe following way:
/home/larry# kill %1
[1]+ Stopped yes
/home/larry#
That message about it being ``stopped'' again is misleading.To find out whether it's still alive ( that is, either running or
frozen in a suspended state ), type jobs:
/home/larry# jobs
[1]+ Terminated yes
/home/larry#
There you have it --- the job has been terminated! ( It's possiblethat the jobs} command showed nothing at all, which just meansthat there are no jobs running in the background. If you just killeda job, and typing jobs shows nothing, then you know the killwas successful. Usually it will tell you the job was "terminated''. ) Now, start yes} running again, like this:
/home/larry# yes > /dev/null
If you read the section about input and output redirection, you knowthat this is sending the output of yes into the special file /dev/null. /dev/null is a black hole that eats anyoutput sent to it ( you can imagine that stream of y's comingout the back of your computer and drilling a hole in the wall, ifthat makes you happy )
After typing this, you will not get
your prompt back, but youwill not see that column of y's either.
Although output isbeing sent into /dev/null},
the job is still running in theforeground. As usual, you can suspend it
by hitting Ctrl z. Do
that now to get the prompt back.
/home/larry# yes > /dev/null
"yes" is running, and we just typed Ctrl z ]
[1]+ Stopped yes >/dev/null
/home/larry#
Hmm ... is there any way to get it to actually run in the background,
while still leaving us the prompt for interactive work? The command
to do that is bg:
/home/larry# bg
[1]+ yes >/dev/null &
/home/larry#
Now, you'll have to trust me on this one: after you typed bg, yes > /dev/null began to run again, but this time in the background. In fact, if you do things at the prompt, like ls and stuff, you might notice that your machine has been slowed down alittle bit ( endlessly generating and discarding a steady stream ofy's does take some work, after all! ) Other than that, however,there are no effects. You can do anything you want at the prompt,and yes will happily continue to sending its output into the black hole.
There are now two different ways you
can kill it: with the
kill command
you just learned, or by putting the job in the foreground againand hitting
it with an interrupt, Ctrl c. Let's
try the second way, just to understand the relationship
between fg and
bg
a little better;
/home/larry# fg
yes >/dev/null}
[ now it's in the foreground again. Imagine that we hit Ctrl c to terminate it ]
/home/larry#
There, it's gone. Now, start up a few jobs running in simultaneously,
like this:
/home/larry# yes > /dev/null &
[1] 1024
/home/larry# yes | sort > /dev/null &
[2] 1026
/home/larry# yes | uniq > /dev/null
[ and here, type Ctrl z}
to suspend it, please ]
[3]+ Stopped yes | uniq >/dev/null
/home/larry#
The first thing you might notice about those commands is thetrailing & at the end of the first two. Putting an & after a command tells the shell to start in running in thebackground right from the very beginning. ( It's just a way to avoidhaving to start the program, type Ctrl z}, and then type bg. ) So, we started those two commands running in thebackground. The third is suspended and inactive at the moment. You maynotice that the machine has become slower now, as the two runningones require some amount of CPU time. Each one told you it's job number. The first two also showed youtheir process identification numbers, or PID's, immediatelyfollowing the job number. The PID's are normally not something youneed to know, but occasionally come in handy.
Let's kill the second one, since I think it's making your machineslow. You could just type kill \2, but that would be too easy.Instead, do this:
/home/larry# fg \2
yes | sort >/dev/null}
[ type Ctrl c} to kill it ]
/home/larry#}
As this demonstrates, fg takes parameters beginning with \ as well. In fact, you could just have typed this:
/home/larry# \2
yes | sort >/dev/null
[ type Ctrl c to kill it ]
/home/larry#
This works because the shell automatically
interprets a job numberas a request to put that job in the foreground.
It can tell jobnumbers from other numbers by the preceding \. Now
type jobs} to see which jobs are
left running:
/home/larry# jobs
[1]- Running yes >/dev/null &
[3]+ Stopped yes | uniq >/dev/null
/home/larry#
The "-" means that job number 1 is second in line tobe put in the foreground, if you just type fg withoutgiving it any parameters. The `` +'' means the specified job is first in line --- a fg without parameters willbring job number 3 to the foreground. However, you can get toit by naming it, if you wish:
/home/larry# fg \1
yes >/dev/null}
[ now type Ctrl z} to suspend it ]
[1]+ Stopped yes >/dev/null
/home/larry#
Having changed to job number 1 and
then suspending it has alsochanged the priorities of all your jobs. You
can see this withthe jobs command:
/home/larry# jobs
[1]+\ \ Stopped yes >/dev/null
[3]- Stopped yes | uniq >/dev/null
/home/larry#
Now they are both stopped ( because both were suspended with Ctrl z), and number 1 is next in line to come to the foreground by default. This is because you put it in the foregroundmanually, and then suspended it. The "+'' always refers tothe most recent job that was suspended from the foreground. You canstart it running again:
/home/larry# bg
[1]+ yes >/dev/null \&
/home/larry# jobs
[1]- Running yes >/dev/null
[3]+ Stopped yes | uniq >/dev/null
/home/larry
Notice that now it is running, and the other job has moved back upin line and has the +. Now let's kill them all so your systemisn't permanently slowed by processes doing nothing.
/home/larry# kill \1 \3
[3] Terminated yes | uniq >/dev/null
/home/larry# jobs
[1]+ Terminated yes >/dev/null
/home/larry#
You should see various messages about termination of jobs--- nothing dies quietly, it seems. The following table gives a summary of commands and keys used in job control.
A summary of commands and keys used in job control.
1. fg %job: This is a shell command thatreturns a job to the foreground. To find out which one this is bydefault, type jobs and look for the one with the +.
Parameters: Optional job number. The default is the processidentified with +.
2. &: When an & is added to the end of the command line, it tells the command to run in the backgroundautomatically. This process is then subject to all the usualmethods of job control detailed here.
3. bg job: This is a shell command thatcauses a suspended job to run in the background. To find out whichone this is by default, type jobs and look for the one with the +.
Parameters: Optional job number. The default is the processidentified with +.
4. kill %job PID}: This is a shellcommand that causes a background job, either suspended or running,to terminate. You should always specify the job number or PID, andif you are using job numbers, remember to precede them with a %.
Parameters: Either the job number ( preceded by \ ) or PID( no \ is necessary ). More than one process or job can bespecified on one line.
5. jobs: This shell command just lists informationabout the jobs currently running or suspending. Sometimes it alsotells you about ones that have just exited or been terminated.
6. Ctrl c: This is the generic interruptcharacter. Usually, if you type it while a program is running in theforeground, it will kill the program ( sometimes it takes a few tries). However, not all programs will respond to this method oftermination.
7. Ctrl z: This key combination usually causes aprogram to suspend, although a few programs ignore it. Once suspended,the job can be run in the background or killed.
The Theory of Job Control
It is important to understand that job control is done by the shell.There is no program on the system called fg; rather, fg, bg, &, jobs, and kill are all shell--builtins( actually, sometimes kill is an independent program, but the bash shell used by Linux has it built in ). This is a logicalway to do it: since each user wants their own job control space, and each user already has their own shell, it is easiest to just have theshell keep track of the user's jobs. Therefore, each user's jobnumbers are meaningful only to that user: my job number [1] and yourjob number [1] are probably two totally different processes. In fact,if you are logged in more than once, each of your shells will haveunique job control data, so you as a user might have two differentjobs with the same number running in two different shells.
The way to tell for sure is to use the Process ID numbers( PID's ). These are system--wide --- each process has itsown unique PID number. Two different users can refer to aprocess by its PID and know that they are talking about thesame process ( assuming that they are logged into the same machine! ).
Let's take a look at one more command to understand what PIDs are. The ps command will list all running processes, includingyour shell. Try it out. It also has a few options, the most importantof which ( to many people ) are a, u, and x. The a option will list processes belonging to any user, not just your own. The x switch will list processes that don't have terminal associated with them. ( This only makes sense for certainsystem programs that don't have to talk to users through a keyboard.). Finally, the u switch will give additional informationabout the process that is frequently useful.
To really get an idea of what your system is doing, put them alltogether: ps -aux. You can then see the process that uses themore memory by looking at the \MEM column, and the most CPUby looking at the \CPU column. ( The TIME column lists the total amount of CPU time used. )
Another quick note about PIDs. kill, in addition to takingoptions of the form % job#, will take options of raw PIDs.So, put a yes > /dev/null in the background, run ps, and look for yes. Then type kill PID}. ( In general, it's easier to just kill the job number instead of using PIDs. )If you start to program in C on your Linux system, you will soonlearn that the shell's job control is just an interactive version ofthe function calls fork and execl. This is too complex to go into here, but may be helpful to remember later on when youare programming and want to run multiple processes from a singleprogram.
Virtual Consoles: Being in Many Places at Once
Linux supports virtual consoles. These are a way of makingyour single machine seem like multiple terminals, all connected toone Linux kernel. Thankfully, using virtual consoles is one of thesimplest things about Linux: there are ``hot keys'' for switchingamong the consoles quickly. To try it, log in to your Linux system,hold down the left Alt key, and press F2 ( that is, thefunction key number2 ). ( Make sure you are doing this from textconsoles: if you are running X windows or some other graphicalapplication, it probably won't work, although rumor has it thatX Windows will soon allow virtual console switching under Linux. )
-- I think it does now. ---
You should find yourself at another login prompt. Don't panic: youare now on virtual console (VC) number 2! Log in here and do somethings --- a few ls's or whatever --- to confirm that this isa real login shell. Now you can return to VC number 1, by holdingdown the left Alt} and pressing F1. Or you can move on toa third VC, in the obvious way ( Alt -- F3 ).
Linux systems generally come with four VC's enabled by default. Youcan increase this all the way to eight; this should be covered inldpsa. It involves editing a file in /etc or two. However,four should be enough for most people. Once you get used to them, VC's will probably become an indispensabletool for getting many things done at once. For example, I typicallyrun Emacs on VC 1 ( and do most of my work there ), while having acommunications program up on VC 3 ( so I can be downloading oruploading files by modem while I work, or running jobs on remotemachines ), and keep a shell up on VC 2 just in case I want to runsomething else without tying up VC 1.
Boot--up Actions
You may have previous experience with MS--DOS or other single useroperating systems, such as OS/2 or the Macintosh. In these operatingsystems, you didn't have to identify yourself to the computer beforeusing it; it was assumed that you were the only user of the systemand could access everything. Well, Unix is a multi--user operatingsystem --- not only can more than one person use it at a time,different people are treated differently.
To tell people apart, Unix needs a user to identify him or herself( From here on in this book, we shall be using the masculine pronounsto identify all people. This is the standard English convention, andpeople shouldn't take it as a statement that only men can usecomputers. ) by a process called logging in. When you first turn on the computer a complex process takes place before the computer isready for someone to use it. Since this guide is geared towards Linux,I'll tell you what happens during the Linux boot--up sequence.
If you're using Linux on some type of computer besides an Intel PC,some things in this chapter won't apply to you. Mostly, they'll be inSection intel--powerup.
If you're just interested in using your computer, you can skip all theinformation in the chapter except for Section actual--login--section.
Power to the Computer
The first thing that happens when you turn an Intel is that the BIOSexecutes. BIOS stands for Basic Input OutputSystem. It's a program permenantly stored in the computer onread--only chips. It performs some minimal tests, and then looks for afloppy disk in the first disk drive. If it finds one, it looks for a``boot sector'' on that disk, and starts executing code from it, ifany. If there is a disk, but no boot sector, the BIOS will print amessage like: Non-system disk or disk error
Removing the disk and pressing a key will cause the boot process tocontinue.
If there isn't a floppy disk in the drive, the BIOS looks for a masterboot record (MBR) on the hard disk. It will start executing the codefound there, which loads the operating system. On Linux systems, LILO,the LInux LOader, can occupy the MBR position, and willload Linux. For now, we'll assume that happens and that Linux startsto load. ( Your particular distribution may handle booting from thehard disk differently. Check with the documentation included withthe distribution. Another good reference is the LILO documentation,
Linux Takes Over
After the BIOS passes control to LILO, LILO passes control to theLinux kernel. A kernel is the central program of the operatingsystem, in control of all other programs. The first thing thatLinux does once it starts executing is to change to protected mode.The 80386 ( When we refer to the 80386, we are also talking about the80486, Pentium, and Pentium Pro computers unless I specifically sayso. Also, We'll be abbreviating 80386 as 386. ) CPU that controlsyour computer has two modes called ``real mode'' and ``protectedmode''. DOS runs in real mode, as does the BIOS. However, for moreadvanced operating systems, it is necessary to run in protected mode.Therefore, when Linux boots, it discardes the BIOS.
Other CPUs will get to this stage differently. No other CPU needs toswitch into protected mode and few have to have such a heavy frameworkaround the loading procedure as LILO and the BIOS. Once the kernelstarts up, Linux works much the same.
The path an Intel PC takes to get to a shell prompt. init
may or may not start X Window System. If it does,
xdm runs.Otherwise, getty
runs.

Linux then looks at the type of hardware it's running on. It wantsto know what type of hard disks you have, whether or not you have abus mouse, whether or not you're on a network, and other bits oftrivia like that. Linux can't remember things between boots, so ithas to ask these questions each time it starts up. Luckily, it isn'tasking you these questions --- it is asking the hardware! Duringboot--up, the Linux kernel will print variations on several messages.You can read about the messages in kernel--messages. This queryprocess can cause some problems with your system but if it was goingto, it probably would have when you first installed Linux. If you'rehaving problems, consult your distribution's documentation.
The kernel merely manages other programs, so once it is satisfiedeverything is okay, it must start another program to do anythinguseful. The program the kernel starts is called init. ( Notice the difference in font. Things in this font are usually the names of programs, files, directories, or other computerrelated items. ) After the kernel starts init, it never startsanother program. The kernel becomes a manager and a provider, not anactive program.
So to see what the computer is doing after the kernel boots up, we'llhave to examine init. init goes through a complicatedstartup sequence that isn't the same for all computers. Linux has manydifferent versions of init, and each does things its own way. It also matters whether your computer is on a network and whatdistribution you used to install Linux. Some things that might happenonce init is started:
1. The file systems might be checked. What is a file system? A file system is the layout of files on the hard disk.It let's Linux know which parts of the disk are already used, andwhich aren't. ( It's like an index to a rather large filing systemor a card catalog to a library. ) Unfortunately, due to variousfactors such as power losses, what the file system informationthinks is going on in the rest of the disk and the actually layoutof the rest of the disk are occasionally in conflict. A specialprogram, called fsck, can find these situations and hopefullycorrect them}
2.Special routing programs for networks are run. Theseprograms tell your computer how it's suppose to contact othercomputers.
3. Temporary files left by some programs may be deleted.
4. The system clock can be correctly updated. This is trickier then one might think, since Unix, by default, wants thetime in UCT ( Universal Coordinated Time, also known as GreenwichMean Time ) and your CMOS clock, a battery powered clock in yourcomputer, is probably set on local time. This means that someprogram must read the time from your hardware clock and correctit to UCT.
After init is finished with its duties at boot--up, it goeson to its regularly scheduled activities. init can be called the parent of all processes on a Unix system. A process is simplya running program. Since one program can be running two or moretimes, there can be two or more processes for any particular program.
In Unix, a process, an instance of a program, is created by a systemcall --- a service provided by the kernel --- called fork. ( It'scalled ``fork'' since one process splits off into two seperateones. ) init forks a couple of processes, which in turn forksome of their own. On your Linux system, what init runs are several instances of a program called getty. getty isthe program that will allow a user to login and eventually calls aprogram called login.
The User Acts
Logging In
The first thing you have to do to use a Unix machine is to identifyyourself. The login is Unix's way of knowing that users areauthorized to use the system. It asks for an accountname andpassword. An account name is normally similar to your regular name;you should have already received one from your system administrator,or created your own if you are the system administrator.
You should see, after all the boot-up procedures are done, somethinglike the following ( the first line is merely a greeting message ---it might be a disclaimer or anything else ):Welcome to the mousehouse. Please, have some cheese.
mousehouse login:
However, it's possible that what the system presents you with doesnot look like this. Instead of a boring text mode screen, it isgraphical. However, it will still ask you to login, and willfunction mostly the same way. If this is the case on your system,you are going to be using The X Window System. This means that youwill be presented with a windowing system. The related sectionwill discuss some of the differences that you'll be facing.Logging in will be similar as will the basics to much of Unix. Ifyou are using X, look for a giant X is the margin.
This is, of course, your invitation to login. Throughout this chapter,we'll be using the fictional ( or not so fictional, depending on yourmachine ) user larry as we did up to now. Whenever you see larry, you should be substituting your own account name.Accountnames are usually based on real names; bigger, more seriousUnix systems will have accounts using the user's last name, or somecombination of first and last name, or even some numbers. Possibleaccounts for Larry Greenfield might be: larry, greenfie, lgreenfi, lg19
mousehouse is, by the way, the ``name'' of the machine I'm working on. It is possible that when you installed Linux, you were prompted for some very witty name. It isn't very important, butwhenever it comes up, I'll be using mousehouse or, rarely, lionsden} when I need to use a second system for clarity orcontrast. After entering larry and pressing Return}, I'm facedwith the following:
mousehouse login: larry
Password:
What Linux is asking for is your password. When you typein your password, you won't be able to see what you type. Typecarefully: it is possible to delete, but you won't be able to seewhat you are editing. Don't type too slowly if people are watching --- they'll be able to learn your password. If you mistype,you'll be presented with another chance to login.
If you've typed your login name and password correctly, a shortmessage will appear, called the message of the day. The message is the content of the file /etc/motd. This could say anything --- the system adminstrator decides what itshould be. After that, a prompt appears. A prompt is justthat, something prompting you for the next command to give thesystem. It should look something like this:
/home/larry#
If you've already determined you're using X, you'll probably seea prompt like the one above in a ``window'' somewhere on thescreen. ( A ``window'' is a rectangular box. ) To type into theprompt, move the mouse cursor ( it probably looks like a big ``x''or an arrow ) using the mouse into the window.
Leaving the Computer
CAUTION!!!: Do not just turn off the computer! You risk losingvaluable data!
Unlike most versions of DOS, it's a bad thing to just hit thepower switch when you're done using the computer. It is also badto reboot the machine ( with the reset button ) without firsttaking proper precautions. Linux, in order to improve performance,has a disk cache. This means it temporarily stores part ofthe computer's permanent storage in RAM. ( The difference between``RAM'' and a hard disk is like the difference between short termmemory and long term memory. Shutting off the power is like givingthe computer a knock on the head --- it'll forget everything inshort term memory. But things saved in long term memory, the harddisk, will be okay. The disk is thousands of times slower thanRAM. ) The idea of what Linux thinks the disk should be and whatthe disk actually contains is syncronized every 30 seconds. In orderto turn off or reboot the computer, you'll have to go through aprocedure telling it to stop caching disk information.
If you're done with the computer, but are logged in ( you'veentered a username and password ), first you must logout. To do so,enter the command logout. All commands are sent by pressing Return. Until you hit Return nothing will happen and you can delete what you've done and start over.
/home/larry# logout
Welcome to the mousehouse. Please, have some cheese.
mousehouse login:
Now another user can login.
Turning the Computer Off
If this is a single user system, you might want to turn thecomputer off when you're done with it. ( To avoid possiblyweakening some hardware components, only turn off the computerwhen you're done for the day. Turning the computer on and offonce a day is probably the best compromise between energy andwear & tear on the system. ) To do so, you'll have to log intoa special account called root. The root account is the system adminstrator's account and can access any file on thesystem. If you're going to turn the computer off, get the passwordfrom the system adminstrator. ( In a single user system, that'syou! Make sure you know the root password. ) root:
mousehouse login: root
Password:
Linux version 1.3.55 (root@mousehouse) #1 Sun
Jan 7 14:56:26 EST 1996
/# shutdown now
Why? end of the day
URGENT: message from the sysadmin:
System going down NOW
... end of the day ...
Now you can turn off the power...
The command shutdown now prepares the system to be reset or turned off. Wait for a message saying it is safe to and thenreset or turn off the system. ( When the system asks you ``Why?'',it is merely asking for a reason to tell other users. Since no oneis using the system when you shut it down, you can tell it anythingyou want or nothing at all. )
A quick message to the lazy: an alternative to the logout/loginapproach is to use the command su. As a normal user, fromyour prompt, type su and press Return. It should prompt you for the root password, and then give you rootprivileges. Now you can shutdown the system with the shutdownnow command.
Kernel Messages
When you first start your computer,
a series of messages flashacross the screen describing the hardware that
is attached to yourcomputer. These messages are printed by the Linux kernel.
In thissection, I'll attempt to describe and explain those messages.Naturally,
these messages differ from machine to machine. I'lldescribe the messages
I get for my machine. The following examplecontains all of the standard
messages and some specific ones. ( Ingeneral, the machine I'm taking this
from is a minimally configuredone: you won't see a lot of device specific
configuration. ) Thiswas made with Linux version 1.3.55 --- one of the
most recent as ofthis writing.
linux kernel starting messages
1. The first thing Linux does is decides what type of video card and screen you have, so it can pick a good font size.( The smaller the font, the more that can fit on the screen on anyone time. ) Linux may ask you if you want a special font, or itmight have had a choice compiled in. ( ``Compiled'' is the processby which a computer program that a human writes gets translatedinto something the computer understands. A feature that has been``compiled in'' has been included in the program. ) Console: 16 point font, 400 scans
Console: colour VGA+ 80x25, 1 virtual console (max 63)
In this example, the machine owner decided he wanted the standard,large font at compile time. Also, note the misspelling of the word``color.'' Linus evidently learned the wrong version of English.
2. The next thing the kernel will report is how fast your system is, as measured by ``BogoMIPS''. A ``MIP'' stands fora million instructions per second, and a ``BogoMIP'' is a ``bogusMIP'': how many times the computer can do absolutely nothing in onesecond. ( Since this loop doesn't actually do anything, the numberis not actually a measure of how fast the system is. ) Linux usesthis number when it needs to wait for a hardware device.}
Calibrating delay loop.. ok - 33.28 BogoMIPS}
3. The Linux kernel also tells you a little about memory usage:
Memory: 23180k/24576k available (544k kernel code, 384k reserved,468k data)
This said that the machine had 24 megabytes of memory. Some of thismemory was reserved for the kernel. The rest of it can be used byprograms. This is the temporary RAM that is used only for shortterm storage. Your computer also has a permanent memory called a hard disk. The hard disk's contents stay around even when power is turned off.
4. Throughout the bootup procedure, Linux tests differentparts of the hardware and prints messages about these tests.
This processor honours the WP bit even when in supervisormode. Good
5. Now Linux moves onto the network configuration. Thefollowing should be described in ldpng, and is beyond the scope ofthis document.
Swansea University Computer Society NET3.033 for Linux 1.3.50 IP Protocols: ICMP, UDP, Tcp
6. Linux supports a FPU, a floating point unit. This is a special chip ( or part of a chip, in the case of a 80486DXCPU that performs arithmetic dealing with non--whole numbers.Some of these chips are bad, and when Linux tries to identifythese chips, the machine ``crashes''. The machine stops functioning.If this happens, you'll see:
Checking 386/387 coupling...
Otherwise, you'll see:
Checking 386/387 coupling...Ok, fpu,using exception 16 error reporting
if you're using a 486DX. If you are using a 386 with a 387, you'llsee:
Checking 386/387 coupling... Ok, fpu using irq13 error reporting.
7.It now runs another test on the ``halt'' instruction.
Checking 'hlt' instruction... Ok
8.. After that initial configuration, Linux prints a lineidentifying itself. It says what version it is, what version of theGNU C Compiler compiled it, and when it was compiled.
Linux version 1.3.55 (root@mousehouse) (gcc version 2.7.0)
#1 Sun$\,$Jan$\,$7 14:56:26 EST 1996
9.The serial driver has started to ask questions about the hardware. A driver is a part of the kernel that controls a device, usually a peripheral. It is responsible for the detailsof how the CPU communicates with the device. This allows people whowrite user applications to concentrate on the application: they don'thave to worry about exactly how the computer works.
Serial driver version 4.11 with no serial optionsenabled
tty00 at 0x03f8 (irq = 4) is a 16450
tty01 at 0x02f8 (irq = 3) is a 16450
tty02 at 0x03e8 (irq = 4) is a 16450
Here, it found 3 serial ports. A serial port is the equivalent ofa DOS COM port, and is a device normally used to communicatewith modems and mice.
What it is trying to say is that serial port 0 ( COM1)has an address of 0x03f8. When it interrupts the kernel, usually to say that it has data, it uses IRQ 4. An IRQ is anothermeans of a peripheral talking to the software. Each serial port alsohas a controller chip. The usual one for a port to have is a 16450;other values possible are 8250 and 16550.}
10. Next comes the parallel port driver. A parallel portis normally connected to a printer, and the names for the parallelports ( in Linux ) start with lp.lp stands for Line Printer, although in modern times it makes moresense for it to stand for Laser Printer. ( However,Linux will happily communicate with any sort of parallel printer:dot matrix, ink jet, or laser. )
lp0 at 0x03bc, (polling)
That message says it has found one parallel port, and is using thestandard driver for it.
11. Linux next identifies your hard disk drives. In theexample system I'm showing you, mousehouse, I've installed twoIDE hard disk drives.
hda: WDC AC2340, 325MB w/127KB Cache, CHS=1010/12/55
hdb: WDC AC2850F, 814MB w/64KB Cache, LBA, CHS=827/32/63
12. The kernel now moves onto looking at your floppy drives. In this example, the machine has two drives: drive ``A''is a $5\ 1/4}$ inch drive, and drive ``B'' is a 3 1/2 inchdrive. Linux calls drive ``A'' fd0 and drive ``B'' fd1.
Floppy drive(s): fd0 is 1.44M, fd1 is 1.2M
floppy: FDC 0 is a National Semiconductor PC87306
13. The next driver to start on my example system is the SLIP driver. It prints out a message about itsconfiguration.
SLIP: version 0.8.3-NET3.019-NEWTTY (dynamic channels, max=256)
(6 bit encapsulation enabled)
CSLIP: code copyright 1989 Regents of the University ofCalifornia
14. The kernel also scans the hard disks it found. It will look for the different partitions on each of them. A partitionis a logical separation on a drive that is used to keep operatingsystems from interfering with each other. In this example, thecomputer had two hard disks ( hda,hdb) with fourpartitions and one partition, respectively.
Partition check:
hda: hda1 hda2 hda3 hda4
hdb: hdb1
15. Finally, Linux mounts the root partition.The root partition is the disk partition where the Linux operatingsystem resides. When Linux ``mounts'' this partition, it is makingthe partition available for use by the user.
VFS: Mounted root (ext2 filesystem) readonly
The X Window System
This chapter only applies to those using the X Window System.If you encounter a screen with multiply windows, colors, or acursor that is only movable with your mouse, you are using X.( If your screen consists of white characters on a black background, you are not currently using X. If you want to startit up, take a look at x--start--stop--section)
Starting and Stopping the X Window System
Starting X
Even if X doesn't start automatically when you login, it ispossible to start it from the regular text--mode shell prompt.There are two possible commands that will start X, either startx or xinit. Try startx first. If theshell complains that no such command is found, try using xinit and see if X starts. If neither command works,you may not have X installed on your system --- consult localdocumentation for your distribution.
If the command runs but you are eventually returned to the blackscreen with the shell prompt, X is installed but not configured.Consult the documentation that came with your distribution on howto setup X.
Exiting X
Depending on how X is configured, there are two possible waysyou might have to exit X. The first is if your window managercontrols whether or not X is running. If it does, you'll haveto exit X using a menu ( see Section x--menus on page x--menus). To display a menu, click a button on the background.
The important menu entry should be ``Exit Window Manager'' or``Exit X'' or some entry containing the word ``Exit''. Try tofind that entry ( there could be more than one menu --- trydifferent mouse buttons! ) and choose it.
The other method would be for a special xterm} to controlX. If this is the case, there is probably a window labeled``login'' or ``system xterm''. To exit from X, move the mousecursor into that window and type ``exit''.
If X was automatically started when you logged in, one of thesemethods should log you out. Simply login again to return. If youstarted X manually, these methods should return you to the textmode prompt. ( If you wish to logout, type logout at this prompt. )
What is The X Window System?
The X Window System is a distributed, graphical method of workingdeveloped primarily at the Massachusetts Institute of Technology.It has since been passed to a consortium of vendors ( aptly named``The X Consortium'' ) and is being maintained by them.
The X Window System ( hereafter abbreviated as ``X'' [ There areseveral acceptable ways to refer to The X Window System. A commonthough incorrect way of referring to X is ``X Windows''. ] ) hasnew versions every few years, called releases. As of this writing,the latest revision is X11R6, or release six. The eleven in X11 isofficially the version number but there hasn't been a new versionin many years, and one is not currently planned.
There are two terms when dealing with X that you should befamiliar. The client is a X program. For instance, xterm} is the client that displays your shell when youlog on. The server is a program that provides servicesto the client program. For instance, the server draws the window for xterm and communicates with the user.
Since the client and the server are two separate programs,it is possible to run the client and the server on two physicallyseparate machines. In addition to supplying a standard method ofdoing graphics, you can run a program on a remote machine ( acrossthe country, if you like! ) and have it display on the workstationright in front of you.
A third term you should be familiar with is the window manager. The window manager is a special client that tells theserver where to position various windows and provides a way forthe user to move these windows around. The server, by itself, doesnothing for the user. It is merely there to provide a buffer betweenthe user and the client.
What's This on my Screen?
When you first start X, several programs are started. First, theserver is started. Then, several clients are usually started.Unfortunately, this is not standardized across various distributions.It is likely that among these clients are a window manager, either fvwm or twm, a prompt, xterm, and a clock, xclock.
An annotated example of a standard X screen. In this example, the user is running twm. The standard clock has been replaced by a transparent
clock called oclock

XClock
xclock [-digital] [-analog] [-update seconds] [-hands color}]
I'll explain the simpliest one first: xclock functions exactly as you'd expect it would. It ticks off the seconds, minutes and hours in a small window.
No amounts of clicking or typing in xclock's window willaffect it --- that's all it does. Or is it? In fact, there arevarious different options you can give to the program to haveit act in different ways. For instance, xclock -digitalwill create a digital clock. xclock -update 1 will create a second hand that moves every second, while -update 5 will create a second hand that moves every 5 seconds.
For more information on xclock's options, consult itsmanpage --- man xclock. If you're going to try runninga few of your own xclock's, you should probably readSection Multitasking to learn how to run them in addition toyour current programs. ( If you run an xclock} in theforeground --- the usual way of running a program --- and wantto get out of it, Ctrl c )
XTerm
The window with a prompt in it ( something that probably lookslike /home/larry# ) is being controlled by a program called xterm. xterm is a deceptively complicated program. At first glance, it doesn't seem to do much, but it actually has to doa lot of work. xterm emulates a terminal so that regular text--mode Unix applications work correctly. It also maintains abuffer of information so that you can refer back to old commands.( To see how to use this, look at Section x--scroll--bar. )
For much of this book, we're going to be learning about the Unixcommand--line, and you'll find that inside your xterm window. In order to type into xterm, you usually have to move yourmouse cursor ( possibly shaped like an ``X'' or an arrow ) into the xterm window. However, this behavior is dependent on thewindow manager.
One way of starting more programs under X is through an xterm. Since X programs are standard Unix programs, they can be run fromnormal command prompts such as xterms. Since running a longterm program from a xterm would tie up the xterm as long as the program was running, people normally start X programs in thebackground. For more information about this, see Section Multitasking.
Window Managers
On Linux, there are two different window managers that arecommonly used. One of them, called twm} is short for``Tab Window Manager''. It is larger than the other windowmanager usually used, fvwm. fvwm stands for ``F(?) Virtual Window Manager'' --- the author neglected totie down exactly what the f stood for. ) Both twm and fvwm are highly configurable, which means I can't tellyou exactly what keys do what in your particular setup.
To learn about twm's configuration, look at Sectiontwm-config-section. fvwm's configuration is covered inSection fvwm-config-section.
When New Windows are Created
There are three possible things a window manager will do whena new window is created. It is possible to configure a windowmanager so that an outline of the new window is shown, and youare allowed to position it on your screen. That is called manual placement}. If you are presented with the outline of a window, simply use the mouse to place it where you wish itto appear and click the left mouse button.
It is also possible that the window manager will place the newwindow somewhere on the screen by itself. This is known asrandom placement}.
Finally, sometimes an application will ask for a specific spoton the screen, or the window manager will be configured todisplay certain applications on the same place of the screen allthe time. ( For instance, I specify that I want xclock} toalways appear in the upper right hand corner of the screen. )
Focus
The window manager controls some important things. The firstthing you'll be interested in is focus. The focus of theserver is which window will get what you type into the keyboard.Usually in X the focus is determined by the position of the mousecursor. If the mouse cursor is in one xterm's window( You can have more then one copy of xterm running at thesame time! ), that xterm will get your keypresses. This isdifferent from many other windowing systems, such as MicrosoftWindows, OS/2, or the Macintosh, where you must click the mousein a window before that window gets focus. Usually under X, ifyour mouse cursor wanders from a window, focus will be lost andyou'll no longer be able to type there.
Note, however, that it is possible to configure both twm and fvwm so that you must click on or in a window to gainfocus, and click somewhere else to lose it, identical to thebehavior of Microsoft Windows. Either discover how your windowmanager is configured by trial and error, or consult localdocumentation.
Moving Windows
Another very configurable thing in X is how to move windowsaround. In my personal configuration of twm, there arethree different ways of moving windows around. The most obviousmethod is to move the mouse cursor onto the title bar anddrag the window around the screen. Unfortunately, this may bedone with any of the left, right, or middle buttons ( Many PCshave only two button mice. If this is the case for you, you shouldbe able to emulate a middle button by using the left and rightbuttons simultaneously. ). ( To drag, move the cursor above thetitle bar, and hold down on the button while moving the mouse. )Most likely, your configuration is set to move windows using theleft mouse buttons
Another way of moving windows may be holding down a key whiledragging the mouse. For instance, in my configuration, if Ihold down the Alt key, move the cursor above a window,I can drag the window around using the left mouse button. Again, you may be able to understand how the window manager isconfigured by trial and error, or by seeing local documentation.Alternatively, if you want to try to interpret the window manager'sconfiguration file, see Section twm--config--section for twmor Section fvwm--config--section for fvwm.
Depth
Since windows are allowed to overlap in X, there is a concept of depth. Even though the windows and the screen are both two dimensional, one window can be in front of another, partially orcompletely obscuring the rear window.
There are several operations that deal with depth:
1. Raising the window, or bringing a windowto the front. This is usually accomplished by clicking on a window'stitle bar with one of the buttons. Depending on how the windowmanager is configured, it could be any one of the buttons. ( It isalso possible that more then one button will do the job. )
2. Lowering the window, or pushing the window tothe back. This can generally be accomplished by a different clickin the title bar. It is also possible to configure some windowmanagers so that one click will bring the window forward if thereis anything over it, while that same click will lower it when itis in the front.
3. Cycling through windows is another operation many window managers allow. This brings each window to the front in an orderly cycle.
Iconization
There are several other operations that can obscure windows orhide them completely. First is the idea of ``iconization''.Depending on the window manager, this can be done in manydifferent ways. In twm, many people configure an icon manager. This is a special window that contains a list of all the other windows on the screen. If you click on a name( depending on the setup, it could be with any of the buttons! )the window disappears --- it is iconified. The window is stillactive, but you can't see it. Another click in the icon managerrestores the window to the screen.
This is quite useful. For instance, you could have remote xterm's to many different computers that you occasionallyuse. However, since you rarely use all of them at a given time,you can keep most of the xterms windows iconified while you work with a small subset. The only problem with this is it becomeseasy to ``lose'' windows. This causes you to create new windowsthat duplicate the functionality of iconified windows.
Other window managers might create actual icons across the bottomof the screen, or might just leave icons on the root window.
Resizing
There are several different methods to resize windows under X.Again, it is dependent on your window manager and exactly how yourwindow manager is configured. The method many Microsoft Windowsusers are familiar with is to click on and drag the border of awindow. If your window manager creates large borders that changehow the mouse cursor looks when it is moved over them, that isprobably the method used to resize windows.
Another method used is to create a ``resizing'' button on thetitlebar. In Figure, a small button is visible on the right ofeach titlebar. To resize windows, the mouse is moved onto theresize button and the left mouse button is held down. You canthen move the mouse outside the borders of the window to resizeit. The button is released when the desired size has been reached.
Maximization
Most window managers support maximization. In twm, for instance, you can maximize the height, the width, or bothdimensions of a window. This is called ``zooming'' in twm'slanguage although I prefer the term maximization. Differentapplications respond differently to changes in their window size.( For instance, twm won't make the font bigger but willgive you a larger workspace. )
Unfortunately, it is extremely non--standard on how to maximizewindows.
Menus
Another purpose for window managers is for them to provide menusfor the user to quickly accomplish tasks that are done over andover. For instance, I might make a menu choice that automaticallylaunches Emacs or an additional xterm for me. That way I don't need to type in an xterm} --- an especially good thingif there aren't any running xterm's that I need to type in tostart a new program!
In general, different menus can be accessed by clicking on theroot window, which is an immovable window behind all the otherones. By default, it is colored gray, but could look like anything.( One fun program to try is called xfishtank. It places asmall aquarium in the background for you.) To try to see a menu,click and hold down a button on the desktop. A menu should pop up.To make a selection, move ( without releasing the mouse button )the cursor over one of the items any then release the mouse button.
X Attributes
There are many programs that take advantage of X. Some programs,like emacs, can be run either as a text--mode program or asa program that creates its own X window. However, most X programscan only be run under X.
Geometry
There are a few things common to all programs running under X.In X, the concept of geometry is where and how large a windowis. A window's geometry has four components:
1. The horizontal size, usually measured in pixels.( A pixel is the smallest unit that can be colored. Many X setupson Intel PCs have 1024 pixels horizontally and 768 pixels vertically. ) Some applications, like xterm and emacs,measure their size in terms of number of characters they can fit inthe window. ( For instance, eighty characters across. )
2. The vertical size, also usually measured in pixels.It's possible for it to be measured in characters.
3. The horizontal distance from one of the sides of thescreen. For instance, +35 would mean make the left edge of thewindow thirty--five pixels from the left edge of the screen. On theother hand, -50 would mean make the right edge of the windowfifty pixels from the right edge of the screen. It's generallyimpossible to start the window off the screen, although a window canbe moved off the screen. ( The main exception is when the window isvery large. )
4. The vertical distance from either the top or the bottom. A positive vertical distance is measured from the top of thescreen; a negative vertical distance is measured from the bottom ofthe screen.
All four components get put together into a geometry string that lookslike: 503x73-78+0}. ( That translates into a window 503 pixelslong, 73 pixels high, put near the top right hand corner of thescreen. ) Another way of stating it is hsize x visze+-hplace+-vplace.
Display
Every X application has a display that it is associated with. Thedisplay is the name of the screen that the X server controls. Adisplay consists of three components:
1. The machine name that the server is running on. At stand--alone Linux installations the server is always running onthe same system as the clients. In such cases, the machine name canbe omitted.
2.The number of the server running on that machine. Since any one machine could have multiple X servers running on it( unlikely for most Linux machines, but possible ) each must havea unique number.
3.The screen number. X supports a particular server controlling more than one screen at a time. You can imagine thatsomeone wants a lot of screen space, so they have two monitorssitting next to each other. Since they don't want two X serversrunning on one machine for performance reasons, they let one Xserver control both screens.
These three things are put together like so: machine:server-number.screen-number.
For instance, on mousehouse, all my applications have thedisplay set to :0.0, which means the first screen of thefirst server on the local display. However, if I am using a remotecomputer, the display might be set to mousehouse:0.0.
By default, the display is taken from the environment variable( see Section section--env--variables ) named DISPLAY,and can be overridden with a command--line option. To see how DISPLAY} is set, try the command echo $DISPLAY}.
Common Features
While X is a graphical user interface, it is a very unevengraphical user interface. It's impossible to say how any component of the system is going to work, because every componentcan easily be reconfigured, changed, and even replaced. This meansit's hard to say exactly how to use various parts of the interface.We've already encountered one cause of this: the different windowmanagers and how configurable each window manager is.
Another cause of this uneven interface is the fact that Xapplications are built using things called ``widget sets''.Included with the standard X distribution are ``Athena widgets''developed at MIT. These are commonly used in free applications.They have the disadvantage that they are not particularly good--looking and are somewhat harder to use than other widgets.
The other popular widget set is called ``Motif''. Motif is acommercial widget set similar to the user interface used inMicrosoft Windows. Many commercial applications use Motif widgets,as well as some free applications. The popular World Wide Web 5Browser netscape uses Motif.Let's try to go through some of the more usually things you'llencounter.
Buttons
Buttons are generally the easiest thing to use. A button is invokedby positioning the mouse cursor over it and clicking ( pressing andimmediately releasing the mouse button ) the left button. Athena andMotif buttons are functionally the same although they have cosmeticdifferences.
Menu Bars
A menu bar is a collection of commands accessible using the mouse.For instance, emacs's menu bar is shown in Figure x11-menu-bar.Each word is a category heading of commands. File deals withcommands that bring up new files and save files. By convention, thisis also the category that contains the command to exit the program.
To access a command, move the mouse
cursor over a particular category( such as File) and press and hold
down the left mouse button.This will display a variety of commands. To
select one of the commands,move the mouse cursor over that command and
release the left mousebutton. Some menu bars let you click on a category
--- if this isthe case, clicking on the category will display the menu
until youclick on either a command, another menu, or outside the menu bar(
indicating that you are not interested in running a particularcommand ).
emacs will change its menu bar depending on thetype of file you're working on.
Here is one possible menu bar.
![]()
Scroll Bars
A scroll bar is a method to allow people to display onlypart of a document, while the rest is off the screen. For instance,the xterm window is currently displaying the bottom third ofthe text available in Figure x11-scrollbar. It's easy to see whatpart of the available text is current being displayed: the darkenedpart of the scroll bar is relative to both the position and theamount of displayed text. If the text displayed is all there is,the entire scroll bar is dark. If the middle half of the text is displayed, the middle half of the scroll bar is darkened.
A vertical scroll bar may be to the
left or right of the text and ahorizontal one may be above or below, depending
the application.
An Athena--type scroll bar is visible on the left ofxterm window.
Next to it, a Motif-type scroll bar is visible on the netscape window


Athena scroll bars
Athena scroll bars operate differently from scroll bars in otherwindowing systems. Each of the three buttons of the mouse operatedifferently. To scroll upwards ( that is, display material abovewhat is currently visible ) you can click the rightmost mousebutton anywhere in the scroll bar. To scroll downwards, click theleft mouse button anywhere in the scroll bar.
You can also jump to a particular location in the displayed materialby clicking the middle mouse button anywhere in the scroll bar. Thiscauses the window to display material starting at that point in thedocument.
Motif scroll bars
A Motif scroll bar acts much more like a Microsoft Windows orMacintosh scroll bar. An example of one is on the right in Figurex11--scrollbar. Notice that in addition to the bar, it has arrowsabove and below it. These are used for fine--tuning: clicking eitherthe left or middle buttons on them will scroll a small amount suchas one line; the right button does nothing.
The behavior of clicking inside the scroll bar is widely differentfor Motif scroll bars than Athena scroll bars. The right button hasno effect. Clicking the left button above the current positionscrolls upward. Similarly, clicking below the current positionscrolls downward. Clicking and holding the left button on thecurrent position allows one to move the bar at will. Releasing theleft button positions the window.
Clicking the middle button anywhere on the bar will immediatelyjump to that location, similar to the behavior of the Athena middlebutton. However, instead of starting to display the data at theposition clicked, that position is taken to be the midpoint of thedata to be displayed.