plan 9 - 2nd edition - README | /sys/doc/ Documentation archive gsoc | doc archive | software repo | ninetimes | harmful | 9P | cat-v.org Related sites: | sitemap Sections:› bell labs/› economics/› henry spencer/› inferno/» plan 9/› 1st edition/» 2nd edition/» README› install› papers/› port› 3rd edition/› 4th edition/› IWP9/› misc/› real time/› translations/› political science/› programming/› xml/ READMEBrian W. Kernighanbwk@research.bell-labs.comThis brief document is intended to help you get started using Plan 9.It is written by a casual Plan 9 userwho is not in any way part of the Plan 9 group,and is aimed at ordinary users with a UNIX background.Getting StartedI'm assuming that you or someone you trust has read,understood, and performed the instructions in the Plan 9 installationprocedure.I'm also assuming that you have at least looked at the overview paper,``Plan 9 from Bell Labs'',which explains what Plan 9 does and how it goes about it.There are also some helpful explanations and examples inthe paper ``The Use of Name Spaces in Plan 9;''both these papers are in this volume.I am further assuming that you have the Plan 9 manual, Volume I, near tohand, and are willing to read manual pages for commandsas their names appear here.How you get started after you turnyour terminal on depends on how your Plan 9 system is set up;the details are different for a stand-alone system or a terminalconnected to a file server and a CPU server.The latter is mostly what I'll talk about.In much the same way that.profileis executed by the shell on UNIX systems,the filelib/profileis executed by the shell on Plan 9when you log in.When your account was created, someone ran thenewusercommand, which created a few directories(bin,bin/rc,lib,andtmp)in your home directory$home,then set up a profile lib/profilethat looks like this, though with more frills:bind -a $home/bin/rc /binfont = /lib/font/bit/pelm/euro.9.fontswitch($service){case terminal prompt=('term ' ' ') exec 8½case cpu bind -b /mnt/term/mnt/8½ /dev prompt=('cpu ' ' ')}Many of the interesting bits of Plan 9 are implicitin this file; most important, it starts the window system.The 8½ Window SystemThe window system for Plan 9 is called 8½;theterminalcase in the profile starts 8½ with the lineexec 8½8½ provides less of the ``flexibility'' and certainlyfar fewer features thanxtermon X terminals, but I prefer it.The most important difference is that 8½ treats all texton the screen alike; with the mouse you can edit anything youcan see, so you can fix up and resubmit commands,fiddle the output of a program or its input and resubmit it,and so on.This ability to edit the past is liberatingto such a degree that once you use it, you'll neverwant to go back to something likexterm.8½ can be called recursively: you can make a new window, run 8½ in it, andeverything you do there is insulated from the surroundings.8½ does not provide any analog of the virtual window management of,for example, VTWM, nor does it provide zillions of(or even a few) icons, but you can move a window almost off the screen,and you can hide it and then recall it from a pop-up menu,which is loosely equivalent to iconifying it.You can also ask 8½ to run a file of commands when it starts;most people put this request into their profile:exec 8½ -i lib/windowsNormally this is used to set up windows that you always use:#!/bin/rcwindow 'x0 y0 x1 y1' command line...wherex0,y0andx1,y1are the coordinates of the window in question (andyincreases down the screen).Thewindowcommand opens a window at the specified place,then runs the command in it.The commandwlocwill tell you the names and locations of all windows, in the right formatto be inserted directly in a file.Set up the windows and programs the way you want them,then runwlocand snarf its output.CommandsMost of the standard UNIX commands exist in almost the same formon Plan 9; this includes standbys like cat,ls,cd,pwd,cp,mv,diff,grepandawk.You'll notice minor differences in behavior but for the most partyou don't have to think about this.The rc ShellOne big difference:Plan 9 uses a different shell, calledrc.For running commands interactively, it's almost the same asthe Bourne or Korn shells, so filename metacharacters like*and?behave the same, and simple redirections with>and>>and|are the same.Quoting is simpler:double quotes and backslash have no special meaning,and single quotes quote anything.To get a single quote into a quoted string, double the quote:echo ''''prints a single quote.For programming, rcis almost unrelated tosh,which is a nuisance.In particular, control flow operators likeifandforhave a different syntax.All shell scripts have to begin with#!/bin/rcEnvironment variables are set byvar = 'anything'where the quotes can be omitted if anythingcontains no spaces.Environment variables are accessed as$var;certain variables are initialized when your process begins,includinguser(your name),home(your home directory), andservice,which isterminalwhen you are running on your terminalandCPUwhen you are running on a CPU server.Directories and Search PathsOne of the unifying ideas in Plan 9 is that all resources are accessed as file systems.Central to this is management of the name space so thatyou can select and arrange the resources you want to use.Thebindandmountcommands manipulate the name space.In particular, the commandbind -a $home/bin/rc /binin the profile binds the directory$home/bin/rcafter(-a)the directory /bin,forming aunion directory.(More precisely, it makes/binan alias for the union.)Other than the current directory,the shell searches only/binfor commands to run, but it searches all the directoriesthat have been unioned together.By convention, your personal shell scripts are placed in $home/bin/rc.When you first log in, several directories are bound to/bin,including/rc/bin,which contains shell scripts, and/$cputype/bin,which contains binaries for your current CPU type.The variablecputypeis the type of processor you are running on,typically one of386,sparc,mips,or68020.When you run a program such asls,the version for your current CPU type will be found in/binand executed.If you subsequently execute thecpucommand to access a CPU server, in that process and thosestarted by it,cputypewill be the type of the CPU server, and thelscommand (again in/bin)that you run there will be the right binary for that CPU.This mechanism ofunion directories replaces the search path of conventionalUNIX shells.As far as you are concerned,allexecutable programs are in/bin.Trylc /binto see the names of all executable programs.Interesting File SystemsUNIX users are familiar with the idea that devices likedisks and tapes are part of the file system.Plan 9 carries that idea a lot further.If you look at the directory/dev,you will see some familiar names.Trycat /dev/timea couple of times, for example.Or, after you have snarfed some text using the button 2 menu item,trycat /dev/snarfNote that some files likeconsandmouseoccur more than once./devis a union directory, and these are multiple occurrences of the same file.The first/dev/mouserefers to the current window, and the next one to theenclosing window (which is probably the whole screen at this point).Trycat /dev/mousethen move the mouse around inside and outside of the current window.The shell environment is kept in a directory called/env;each shell environment variable is stored in a file.Trycat /env/fontfor example.Running processes are found in/proc;each process is a directory, and each file in that directoryaccesses some aspect of the process.For example, thestatusfile contains (textual) status information about the process.Tryawk '{print $1}' /proc/*/statusto get a list of the names of the running processes.You might also find it interesting to poke aroundin /net;all network connections are managed as file systems as well.In all of these cases, the service presents a file-systeminterface to its clients, although the implementation behindis not generally a traditional file system.Finally, it's worth looking at/sys,which is a conventional file system that contains directoriesof source code, libraries, headers, manual pages, documentation,and the like.This roughly matches similar directories foundon UNIX systems.FontsOne aspect of 8½ that you can change is the font it usesfor displaying text.There is a default font, but normally the variablefontis set explicitly in the profile:font = /lib/font/bit/pelm/euro.9.font8½ -f $fontThe fonteuro.9.fontis a collection of almost any character you might findin European languages, including Cyrillic, Greek,and a bunch of special characters.There are other fonts that include oriental languages as well,and a variety of sizes.Plan 9 uses the Unicode character set throughout,which means that the system and the various programs alldeal comfortably with a very large character set.(Think 16 bits, or 64K characters.)So if you want to edit files in languages thatuse more than ASCII characters, or rungreporawkover them, it just works.You may have trouble printing such characters on standard printers,but they will appear fine on the screen.EditingThe standard Plan 9 editor is calledsam;it's a particularly good multi-file editor,it provides regular expression syntaxthe same as in the venerableed(which also exists), and you can snarf text from one of itswindows and paste it into other 8½ windows or vice versa.The mouse idioms forsamand8½are the same.It will also edit files on other systems if there isa network connection.By the way, regular expressions have been cleaned up all programs exceptrcsupport the same regular expressions,which are pretty close to those found inegrepon UNIX systems.The CPU ServerIn the Plan 9 world view, one is meant to run interactive programssuch as editors on the terminal and compute-intensive programssuch as compilers on a CPU server,which runs faster and has a higher bandwidth to the file server.Thecpucommand connects you to a CPU serverso your computation runs faster, but everything elsestays the same.The mechanism is quite different from eitherremote login (which does not preserve the name space you arecurrently working in) or network file system access(which does not change the processor).The linebind -b /mnt/term/mnt/8½ /devin your profile arranges that all the devices (including mouse,keyboard and screen) associated with your terminalare inherited by the CPU server so they continue to workin a CPU window.Connecting to UNIX SystemsIt is likely that your Plan 9 system will beconnected by some network to a UNIX system.The commandconconnects to another system (typically UNIX);the commandrxis rather like thershcommandon UNIX systems, for executing a single command on another machine.If the UNIX system cooperates, it is also possible to mounta UNIX file system in the Plan 9 name space so that fileson the UNIX side are accessible from Plan 9.The command9fs machineestablishes the connection and mounts the files;thereafter the root of the target file system isin the Plan 9 directory at/n/machine.Plan 9 CPU servers answer FTP,rlogin,andtelnetrequests. If you wantyour own personal access privileges, you will need to reply to achallenge using a SecureNet key or equivalent; otherwise, usernoneis permitted unchallenged access, sufficient to access manyglobally available services and databases (see section 7 of the manual).Similar restrictions applywhen accessing Plan 9 file servers over NFS;in this case, the program9authinitiates the challenge/response dialog.If your Plan 9 machine shares a disk with MS-DOS,as it might well on a PC,you can access the DOS file system through/n/c:,and other disks as/n/a:,etc.This is a convenient way to get information into and outof the PC world.Backup and RecoveryNormally the state of the Plan 9 file system is recorded every dayor so; on our system, it's stored on an optical disk.If your Plan 9 system is suitably equipped, you shouldbe able to run another service that makes the paststate of the file system accessible (read only).For example, if you run the command9fs dumpit mounts this file system on/n/dump.At that point, you cancdinto the past:cd /n/dump/1995/0401/usr/youls -lputs you in your directory as it was on April 1, 1995.This really is a file system, so all the normal commandswork fine; you candiffa file from then with one on some other date,or copy an old version to the present.Plan 9 has no backup or recovery programs; this mechanism subsumesthem all.Programming in Plan 9Most programming in Plan 9 is done in ANSI C,with the usual supporting tools like YACC available.One difference of note:makehas been largely supplanted bymk,which is cleaner but different. As with the shell, it takestime to internalize the differences.For each supported CPU type,there is a C compiler to generate code(named using a single letter mnemonic), with a version of that compilerthat may be executed on any CPU type.Themkfilenormally encapsulates this, and/sys/src/cmdcontains examples that you can adapt easily.Although ANSI C is supported, the Plan 9 libraries are notANSI and the standard ANSI header files normally are not found.Compiling C programs is different enough that you shouldread the paper called ``How to Use the Plan 9 C Compiler''before starting.If you are importing or exporting a C program, you will wantto use the ANSI/POSIX environment (``APE''), which really does providefor portability, including a complete set of POSIX-compatible libraries and some POSIX tools.The compiler driver is calledpcc.The commandape/pshwill bind the right files and starta POSIX-compliant shell.Although these POSIX tools are useful for exchanging programswith the outside world,you will generally be more productive using the nativePlan 9 tools where possible.EnvoiPlan 9 is not UNIX.If you think of it as UNIX, you'll often be frustratedbecause something doesn't exist or works differently.If you think of it as Plan 9, however, you'll find thatmost of it works very smoothly, and that there aresome truly neat ideas that make things much cleanerthan you have seen before. Copyright © 1995 Lucent Technologies. All rights reserved. Powered by wercvar gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src="http://doc.cat-v.org/plan_9/2nd_edition/README/" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));var pageTracker = _gat._getTracker("UA-1220719-1");pageTracker._setDomainName("cat-v.org");pageTracker._initData();pageTracker._trackPageview();var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src="http://doc.cat-v.org/plan_9/2nd_edition/README/" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));var pageTracker = _gat._getTracker("UA-1220719-5");pageTracker._initData();pageTracker._trackPageview(); |
|