Reorder Unix Basics
[ikiwiki.git] / docs / handbook / UnixBasics / index.mdwn
1 # UNIX Basics 
2
3 [[!toc  levels=3]]
4
5 ## Synopsis 
6
7 The following chapter will cover the basic commands and functionality of the DragonFly operating system. Much of this material is relevant for any UNIX®-like operating system. Feel free to skim over this chapter if you are familiar with the material. If you are new to DragonFly, then you will definitely want to read through this chapter carefully.
8
9 After reading this chapter, you will know:
10
11 * How to use the ***virtual consoles*** of DragonFly.
12
13 * The differences between the various user accounts on a DragonFly system.
14
15 * What a shell is, and how to change your default login environment.
16
17 * How to read manual pages for more information.
18
19 * How to use basic text editors.
20
21 * How UNIX file permissions work along with understanding file flags in DragonFly.
22
23 * What devices and device nodes are.
24
25 * The DragonFly disk organization.
26
27 * How to mount and unmount file systems.
28
29 * The default DragonFly file system layout.
30
31 * What processes, daemons, and signals are.
32
33 ## Virtual Consoles and Terminals 
34
35 DragonFly can be used in various ways. One of them is typing commands to a text terminal. A lot of the flexibility and power of a UNIX® operating system is readily available at your hands when using DragonFly this way. This section describes what ***terminals*** and ***consoles*** are, and how you can use them in !DragonFly.
36
37 ### The Console 
38
39 If you have not configured DragonFly to automatically start a graphical environment during startup, the system will present you with a login prompt after it boots, right after the startup scripts finish running. You will see something similar to:
40
41     newaliases: no recipients
42     Starting cron.
43     Local package initialization:.
44     Additional TCP options:.
45     
46     Mon Jan  8 03:02:40 GMT 2018
47     
48     DragonFly/x86_64 (Amnesiac) (ttyv0)
49
50     login: 
51
52 The messages might be a bit different on your system, but you will see something similar. The last two lines are what we are interested in right now. The second last line reads:
53
54     DragonFly/x86_64 (Amnesiac) (ttyv0)
55
56 This line contains some bits of information about the system you have just booted. You are looking at a ***DragonFlyBSD*** console, running on an Intel, or AMD, or any other compatible processor of the amd64 (aka x86_64) architecture. The name of this machine (every UNIX machine has a name) is `Amnesiac`, and you are now looking at its system console--the `ttyv0` terminal. Finally, the last line is always:
57
58     login:
59
60 This is the part where you are supposed to type in your **username** to log into DragonFly. The next section describes how you can do this.
61
62 ### Logging into DragonFly 
63
64 DragonFly is a multiuser, multiprocessing system. This is the formal description that is usually given to a system that can be used by many different people, who simultaneously run a lot of programs on a single machine. Every multiuser system needs some way to distinguish one <i>user</i> from the rest. In DragonFly (and every other kind of UNIX and UNIX-like operating system), this is accomplished by requiring that every user must <i>log into</i>  the system before being able to run programs. Every user has a unique name (the username and a personal, secret key (the password)). DragonFly will ask for these two before allowing a user to run any programs.
65
66 Right after DragonFly boots and finishes running its startup scripts, it will present you with a prompt and ask for a valid username: 
67
68     login:
69
70 Startup scripts are programs that are run automatically by DragonFly when booting. Their main function is to set things up for everything else to run, and start any services that you have configured to run in the background doing useful things.
71
72 Let us assume that you are newbie and didn't configure system during install (don't worry, we'll add user/users later). Type **root** at this prompt:
73
74     login: root
75
76 and press [Enter].
77
78 If you've configured **root**'s password during install, type in **root**'s password and press [Enter]. The password is <i>not echoed!</i> You need not worry about this right now. Suffice it to say that it is done for security reasons. If you have typed your password correctly, you should by now be logged into DragonFly and ready to try out all the available commands.
79
80 You should see the message followed by a command prompt:
81
82     Welcome to DragonFly!
83
84     # 
85
86 ## Users
87
88 All access to the system is achieved via accounts, and all processes are run by users. There are three main types of accounts: root, daemons and user accounts. The root is used to manage the system with no limitations on privileges. Daemons run services. Finally, user accounts are used by real people, who log on, read mail, and so forth.
89
90 ### Root
91
92 The root account comes preconfigured to facilitate system administration, and should not be used for day-to-day tasks like sending and receiving mail, general exploration of the system, or programming.
93
94 This is because root, unlike normal user accounts, can operate without limits, and misuse of the root account may result in spectacular disasters. User accounts are unable to destroy the system by mistake, so it is generally best to use normal user accounts whenever possible, unless you especially need the extra privilege.
95
96 You should always double and triple-check commands you issue as root, since an extra space or missing character can mean irreparable data loss.
97
98 So, the first thing you should do after reading this chapter is to create an unprivileged user account for yourself for general usage if you have not already. This applies equally whether you are running a multi-user or single-user machine. Later in this chapter, we discuss how to create additional accounts, and how to change between the normal user and root.
99
100 ### Daemons 
101
102 Daemons are those used to run services such as DNS, mail, web servers, and so forth. The reason for this is security; if all services ran as root, they could act without restriction.
103
104 Examples of daemons are `daemon`, `operator`, `bind` (for the Domain Name Service), and `news`. Often sysadmins create `httpd` to run web servers they install.
105
106 `nobody` is the generic unprivileged daemon. However, it is important to keep in mind that the more services that use `nobody`, the more files and processes that user will become associated with, and hence the more privileged that user becomes.
107
108 ### User Accounts 
109
110 User accounts are the primary means of access for real people to the system, and these accounts insulate the user and the environment, preventing the users from damaging the system or other users, and allowing users to customize their environment without affecting others.
111
112 Every person accessing your system should have a unique user account. This allows you to find out who is doing what, prevent people from clobbering each others settings or reading each others mail, and so forth.
113
114 Each user can set up their own environment to accommodate their use of the system, by using alternate shells, editors, key bindings, language and so on.
115
116 ## Shells 
117
118 In DragonFly, a lot of everyday work is done in a command line interface called a shell. A shell's main job is to take commands from the input channel and execute them. A lot of shells also have built in functions to help everyday tasks such as file management, file globbing, command line editing, command macros, and environment variables. DragonFly comes with a set of shells, such as **sh**, the Bourne Shell, and **tcsh**, the improved C-shell. Many other shells are available from dports, such as **zsh** and **bash**.
119
120 Which shell do you use? It is really a matter of taste. The point is that each shell has unique properties that may or may not work with your preferred working environment, and that you have a choice of what shell to use.
121
122 One common feature in a shell is filename completion. Given the typing of the first few letters of a command or filename, you can usually have the shell automatically complete the rest of the command or filename by hitting the  [Tab]  key on the keyboard. Here is an example. Suppose you have two files called `foobar` and `foo.bar`. You want to delete `foo.bar`. So what you would type on the keyboard is: `rm fo[ **Tab** ].[ **Tab** ]`.
123
124 The shell would print out `rm foo[BEEP].bar`.
125
126 The [BEEP] is the console bell, which is the shell telling me it was unable to totally complete the filename because there is more than one match. Both `foobar` and `foo.bar` start with `fo`, but it was able to complete to `foo`. If you type in `.`, then hit [Tab] again, the shell would be able to fill in the rest of the filename for you.
127
128 ### Typing commands
129
130 The next thing important to know is that '#' character means type command as root user, while both '%' and '$' characters mean type as a non-root user. All shells use '#' character when you're logged in as root. Some shells prefer using '$' character when you're logged in not as root, some shells prefer using '%' for that. We'll use '%' character in documentation for typing commands as non-root user. You may type them as root of course, most of them won't harm you, but be careful...
131
132 For examle, run 'ls /root' as root is:
133
134     # ls /root
135
136 And, for example, run 'df' as non-root is:
137
138     % df
139
140 Remember, you may run it as root if you wish (as if you have a choice, now let's quickly create a new user).
141
142 So, after installing system you didn't add a new user, it's not a problem. First, set your root password:
143
144     # passwd
145
146 Now, your root user is protected. We'll discuss user management later, now just add a user:
147
148     # pw useradd pedik -mG wheel -s /bin/tcsh
149
150 And pick him a password:
151
152     # passwd pedik
153
154 Now you may switch to him:
155
156     # su pedik
157
158 Didn't see a password prompt? Of course you didn't, you were root user! Replace **pedik** with the name you want to give to your user.
159
160 Now you should see '%' character in command prompt. Try:
161
162     % whoami
163
164 Before we go further, you should know about command arguments. Command arguments are characters/words which come after commands:
165
166     % ls /usr
167
168 In this case, **/usr** is argument to **ls**.
169
170 Commands also have options, options are arguments followed by **-** (short options) or **--** (long options). Typing:
171
172     % ls -a -l
173
174 is equivalent to:
175
176     % ls -al
177
178 and is even equivalent to:
179
180     % ls -la
181
182 and to:
183
184     % ls -l -a
185
186 ### Using root account
187
188 Only users in **wheel** group may use root account, in the previous example we've already added **pedik** to **wheel** group.
189
190 To use root accout, simply type:
191
192     % su
193
194 You'll see password prompt because you're not root, just type **root**'s password and you'll see the shell prompt after '#' character. When you're done, type:
195
196     # exit
197
198 ## Manual Pages 
199
200 The most comprehensive documentation on DragonFly is in the form of manual pages. Nearly every program on the system comes with a short reference manual explaining the basic operation and various arguments.
201
202 The online manual is divided up into numbered sections:
203
204   1. User commands.
205   2. System calls and error numbers.
206   3. Functions in the C libraries.
207   4. Device drivers.
208   5. File formats.
209   6. Games and other diversions.
210   7. Miscellaneous information.
211   8. System maintenance and operation commands.
212   9. Kernel internals.
213
214 References to a particular section of the online manual are traditionally placed in parenthesis in written documentation.
215
216 These manuals can be viewed with the man(1) command. Use of the man(1) command is simple:
217
218     % man command
219
220 **command** is the name of the command you wish to learn about. For example, to learn more about man(1) command type:
221
222     % man man
223
224 In some cases, the same topic may appear in more than one section of the online manual. For example, there is a chmod(1) user command and a chmod(2) system call. In this case, you can tell the man(1) command which one you want by specifying the section:
225
226     % man 2 chmod
227
228 This will display the manual page for the system call chmod(2).
229
230 This is fine if you know the name of the command and simply wish to know how to use it, but what if you cannot recall the command name? You can use apropos(1) to search for keywords in the command descriptions:
231
232     % apropos mail
233
234 With this command you will be presented with a list of commands that have the keyword **mail** in their descriptions. This is actually functionally equivalent to using:
235
236     % man -k mail
237
238 So, you are looking at all those fancy commands in **/usr/bin** but do not have idea what they do, use whatis(1):
239
240     % whatis vi
241
242 This is functionally equivalent to using:
243
244     % man -f vi
245
246 ### Basic commands
247
248 * man(1) - display manual pages.
249 * pwd(1) - print working directory.
250 * ls(1) - list directory contents.
251 * cat(1) - it has many uses, for now you should know that 'cat filename' will print contents of **filename**.
252 * ee(1) - edit text files. For example, 'ee filename'. See also vi(1).
253 * mkdir(1) - make a directory. For example, 'mkdir dirname'.
254 * rmdir(1) - remove a directory.
255 * rm(1) - remove files.
256 * cd - change directory (shell built-in).
257 * chmod(1) - change file modes, including permissions.
258 * cp(1) - copy files.
259 * mv(1) - move and rename files.
260 * ps(1) - list active processes.
261 * kill(1) - kill processes.
262 * date(1) - print the current system date and time.
263 * mail(1) - access mailbox.
264 * exit - log out of system (shell build-in).
265 * cal(1) - prints calendar.
266 * su(1) - substitute user identity.
267
268 ### GNU Info Files
269
270 DragonFly includes many applications and utilities produced by the Free Software Foundation (FSF). In addition to manual pages, these programs come with more extensive hypertext documents called info files which can be viewed with the info(1) command or, if you installed  **emacs** , the info mode of  **emacs** . To use the info(1) command, simply type:
271
272     % info
273
274 For a brief introduction, type `h`. For a quick command reference, type `?`.
275
276 **Note:** DragonFly doesn't have info(1) in base. So, install it via pkg(8):
277
278     # pkg ins texinfo
279
280 We'll discuss later how to build it via dports.
281
282 ## Text Editors 
283
284 A lot of configuration in DragonFly is done by editing text files. Because of this, it would be a good idea to become familiar with a text editor. DragonFly comes with a few as part of the base system, and many more are available in the dports tree.
285
286 The easiest and simplest editor to learn is an editor called ee(1), which stands for easy editor. To start ee(1), one would type at the command line:
287
288     % ee filename
289
290 Where `filename` is the name of the file to be edited. For example, to edit **/etc/rc.conf**, type in:
291
292     # ee /etc/rc.conf
293
294 Once inside of `ee`, all of the commands for manipulating the editor's functions are listed at the top of the display. The caret **^** character represents the  [Ctrl]  key on the keyboard, so **^e** expands to the key combination Ctrl - e. To leave ee(1), hit the [Esc] key, then choose leave editor. The editor will prompt you to save any changes if the file has been modified.
295
296 DragonFly also comes with more powerful text editors such as  vi(1)  as part of the base system, while other editors, like emacs(1) and vim(1), are part of the dports tree. These editors offer much more functionality and power. However if you plan on doing a lot of text editing, learning a more powerful editor such as vim(1) or emacs(1) will save you much more time in the long run.
297
298 **Note:** if you're not familiar with vi(1) or can't (or don't want to) run emacs(1), you might want to install a small, fast, and portable editor called mg(1). It is compatible with emacs(1) because there shouldn't be any reason to learn more editor types than emacs(1) or vi(1). If you don't know how to use it, read **/usr/local/share/doc/mg/tutorial** first.
299
300 ## Multiple Consoles
301
302 Running UNIX commands in one console is fine, but DragonFly can run many programs at once. Having one console where commands can be typed would be a bit of a waste when an operating system like DragonFly can run dozens of programs at the same time. This is where <i>virtual consoles</i> can be very helpful. DragonFly can be configured to present you with many different virtual consoles. You can switch from one of them to any other virtual console by pressing a couple of keys on your keyboard. Each console has its own different output channel, and DragonFly takes care of properly redirecting keyboard input and monitor output as you switch from one virtual console to the next.
303
304 Special key combinations have been reserved by DragonFly for switching consoles. You can use  **Alt** - **F1** ,  **Alt** - **F2** , through  **Alt** - **F8**  to switch to a different virtual console in DragonFly. As you are switching from one console to the next, DragonFly takes care of saving and restoring the screen output. The result is an **illusion** of having multiple <i>virtual</i> screens and keyboards that you can use to type commands for DragonFly to run. The programs that you launch on one virtual console do not stop running when that console is not visible. They continue running when you have switched to a different virtual console.
305
306 A fairly technical and accurate description of all the details of the DragonFly console and keyboard drivers can be found in the manual pages of syscons(4), atkbd(4), vidcontrol(1) and kbdcontrol(1). We will not expand on the details here, but the interested reader can always consult the manual pages for a more detailed and thorough explanation of how things work.
307
308 ## Permissions 
309
310 DragonFly, being a direct descendant of BSD UNIX®, is based on several key UNIX concepts. The first and most pronounced is that DragonFly is a multi-user operating system. The system can handle several users all working simultaneously on completely unrelated tasks. The system is responsible for properly sharing and managing requests for hardware devices, peripherals, memory, and CPU time fairly to each user.
311
312 Because the system is capable of supporting multiple users, everything the system manages has a set of permissions governing who can read, write, and execute the resource. These permissions are stored as three octets broken into three pieces, one for the owner of the file, one for the group that the file belongs to, and one for everyone else. This numerical representation works like this:
313
314 [[!table  data="""
315 |<tablestyle="width:100%"> Value | Permission | Directory Listing 
316 <tablestyle="width:100%"> 0 | No read, no write, no execute | `---` 
317  1 | No read, no write, execute | `--x` 
318  2 | No read, write, no execute | `-w-` 
319  3 | No read, write, execute | `-wx` 
320  4 | Read, no write, no execute | `r--` 
321  5 | Read, no write, execute | `r-x` 
322  6 | Read, write, no execute | `rw-` 
323  7 | Read, write, execute | `rwx` |
324
325 """]]
326
327 You can use the `-l` command line argument to ls(1) to view a long directory listing that includes a column with information about a file's permissions for the owner, group, and everyone else. For example, a `ls -l` in an arbitrary directory may show:
328
329     % ls -l
330     total 530
331     -rw-r--r--  1 root  wheel     512 Sep  5 12:31 myfile
332     -rw-r--r--  1 root  wheel     512 Sep  5 12:31 otherfile
333     -rw-r--r--  1 root  wheel    7680 Sep  5 12:31 email.txt
334     ...
335
336 Here is how the first column of `ls -l` is broken up:    
337
338     -rw-r--r--
339
340 The first (leftmost) character tells if this file is a regular file, a directory, a special character device, a socket, or any other special pseudo-file device. In this case, the `-` indicates a regular file. The next three characters, `rw-` in this example, give the permissions for the owner of the file. The next three characters, `r--`, give the permissions for the group that the file belongs to. The final three characters, `r--`, give the permissions for the rest of the world. A dash means that the permission is turned off. In the case of this file, the permissions are set so the owner can read and write to the file, the group can read the file, and the rest of the world can only read the file. According to the table above, the permissions for this file would be `644`, where each digit represents the three parts of the file's permission.
341
342 This is all well and good, but how does the system control permissions on devices? DragonFly actually treats most hardware devices as a file that programs can open, read, and write data to just like any other file. These special device files are stored on the `/dev` directory.
343
344 Directories are also treated as files. They have read, write, and execute permissions. The executable bit for a directory has a slightly different meaning than that of files. When a directory is marked executable, it means it can be traversed into, that is, it is possible to ***cd*** (change directory) into it. This also means that within the directory it is possible to access files whose names are known (subject, of course, to the permissions on the files themselves).
345
346 In particular, in order to perform a directory listing, read permission must be set on the directory, whilst to delete a file that one knows the name of, it is necessary to have write ***and*** execute permissions to the directory containing the file. There are more permission bits, but they are primarily used in special circumstances such as setuid binaries and sticky directories. If you want more information on file permissions and how to set them, be sure to look at the chmod(1) manual page.
347
348 ### Symbolic Permissions 
349
350 Symbolic permissions, sometimes referred to as symbolic expressions, use characters in place of octal values to assign permissions to files or directories. Symbolic expressions use the syntax of (who) (action) (permissions), where the following values are available:
351
352 [[!table  data="""
353 <tablestyle="width:100%"> Option | Letter | Represents 
354 <tablestyle="width:100%"> (who) | u | User 
355  (who) | g | Group owner 
356  (who) | o | Other 
357  (who) | a | All (***world***) 
358  (action) | \+ | Adding permissions 
359  (action) | \- | Removing permissions 
360  (action) | = | Explicitly set permissions 
361  (permissions) | r | Read 
362  (permissions) | w | Write 
363  (permissions) | x | Execute 
364  (permissions) | t | Sticky bit 
365  (permissions) | s | Set UID or GID |
366
367 """]]
368
369 These values are used with the chmod(1) command just like before, but with letters. For an example, you could use the following command to block other users from accessing `FILE`:
370
371     % chmod go=FILE
372
373 A comma separated list can be provided when more than one set of changes to a file must be made. For example the following command will remove the groups and ***world*** write permission on `FILE`, then it adds the execute permissions for everyone:
374
375     % chmod go-w,a+x FILE
376
377 ### DragonFly File Tags
378
379 In addition to file permissions discussed previously, DragonFly supports the use of ***file flags.*** These flags add an additional level of security and control over files (but not directories), helping to ensure that in some cases not even `root` can remove or alter files.  File flags are altered by using the chflags(1)] utility, using a simple interface. For example, to enable the system undeletable flag on the file `file1`, issue the following command:
380
381     
382
383     # chflags sunlink file1
384
385 To disable the system undeletable flag, simply issue the previous command with ***no*** in front of the `sunlink`. Observe:
386
387     
388
389     # chflags nosunlink file1
390
391 To view the flags of this file, use the ls(1) command with the `-lo` flags:
392
393     
394
395     # ls -lo file1
396
397 The output should look like the following:
398
399     
400
401     -rw-r--r--  1 trhodes  trhodes  sunlnk 0 Mar  1 05:54 file1
402
403 Several flags may only added or removed to files by the `root` user. In other cases, the file owner may set these flags. It is recommended an administrator read over the chflags(1) and chflags(2) manual pages for more information.
404
405 ## Directory Structure
406
407 The DragonFly directory hierarchy is fundamental to obtaining an overall understanding of the system. The most important concept to grasp is that of the root directory, ***/***. This directory is the first one mounted at boot time and it contains the base system necessary to prepare the operating system for multi-user operation. The root directory also contains mount points for every other file system that you may want to mount.
408
409 A mount point is a directory where additional file systems can be grafted onto the root file system. Standard mount points include `/usr`, `/var`, `/tmp`, `/mnt`, and `/cdrom`. These directories are usually referenced to entries in the file `/etc/fstab`. `/etc/fstab` is a table of various file systems and mount points for reference by the system. Most of the file systems in `/etc/fstab` are mounted automatically at boot time from the script rc(8) unless they contain the `noauto` option.
410
411 A complete description of the file system hierarchy is available in hier(7). For now, a brief overview of the most common directories will suffice.
412
413 [[!table  data="""
414 <tablestyle="width:100%">Directory | Description 
415 <tablestyle="width:100%">  `/` | Root directory of the file system. 
416  `/bin/` | User utilities fundamental to both single-user and multi-user environments. 
417  `/boot/` | Programs and configuration files used during operating system bootstrap. 
418  `/boot/defaults/` | Default bootstrapping configuration files; see loader.conf(5). 
419  `/dev/` | Device nodes; see intro(4). 
420  `/etc/` | System configuration files and scripts. 
421  `/etc/defaults/` | Default system configuration files; see rc(8). 
422  `/etc/mail/` | Configuration files for mail transport agents such as sendmail(8). 
423  `/etc/periodic/` | Scripts that are run daily, weekly, and monthly, via cron(8); see periodic(8). 
424  `/etc/ppp/` | `ppp` configuration files; see ppp(8). 
425  `/mnt/` | Empty directory commonly used by system administrators as a temporary mount point. 
426  `/proc/` | Process file system; see procfs(5) and mount_procfs(8). 
427  `/root/` | Home directory for the `root` account. 
428  `/sbin/` | System programs and administration utilities fundamental to both single-user and multi-user environments. 
429  `/tmp/` | Temporary files. The contents of `/tmp` are usually NOT preserved across a system reboot. A memory-based file system is often mounted at `/tmp`. This can be automated with an entry in `/etc/fstab`; see mfs(8). 
430  `/usr/` | The majority of user utilities and applications. 
431  `/usr/bin/` | Common utilities, programming tools, and applications. 
432  `/usr/dports/` | The dports tree for installing packages (optional). 
433  `/usr/games/` | Useful and semi-frivolous programs.
434  `/usr/include/` | Standard C include files. 
435  `/usr/lib/` | Archive libraries. 
436  `/usr/libdata/` | Miscellaneous utility data files. 
437  `/usr/libexec/` | System daemons &amp; system utilities (executed by other programs). 
438  `/usr/local/` | Local executables, libraries, etc. Within `/usr/local`, the general layout sketched out by hier(7) for `/usr` should be used. An exceptions is the man directory, which is directly under `/usr/local` rather than under `/usr/local/share`. dports uses `/usr/local`. 
439  `/usr/obj/` | Architecture-specific target tree produced by building the `/usr/src` tree. 
440  `/usr/sbin/` | System daemons &amp; system utilities (executed by users). 
441  `/usr/share/` | Architecture-independent files. 
442  `/usr/src/` | BSD, third-party, and/or local source files. 
443  `/var/` | Multi-purpose log, temporary, transient, and spool files. A memory-based file system is sometimes mounted at `/var`. This can be automated with an entry in `/etc/fstab`; see mfs(8). 
444  `/var/log/` | Miscellaneous system log files. 
445  `/var/mail/` | User mailbox files. 
446  `/var/spool/` | Miscellaneous printer and mail system spooling directories. 
447  `/var/tmp/` | Temporary files. The files are usually preserved across a system reboot, unless **/var** is a memory-based file system. 
448  `/var/yp` | NIS maps. |
449
450 """]]
451
452 ### The /etc/ttys File 
453
454 The default configuration of DragonFly will start up with eight virtual consoles. This is not a hardwired setting though, and you can easily customize your installation to boot with more or fewer virtual consoles. The number and settings of the virtual consoles are configured in the `/etc/ttys` file.
455
456 You can use the `/etc/ttys` file to configure the virtual consoles of DragonFly. Each uncommented line in this file (lines that do not start with a `#` character) contains settings for a single terminal or virtual console. The default version of this file that ships with DragonFly configures nine virtual consoles, and enables eight of them. They are the lines that start with `ttyv`:
457     
458
459     # name  getty                           type    status          comments
460     #
461     ttyv0   "/usr/libexec/getty Pc"         cons25  on  secure
462     # Virtual terminals
463     ttyv1   "/usr/libexec/getty Pc"         cons25  on  secure
464     ttyv2   "/usr/libexec/getty Pc"         cons25  on  secure
465     ttyv3   "/usr/libexec/getty Pc"         cons25  on  secure
466     ttyv4   "/usr/libexec/getty Pc"         cons25  on  secure
467     ttyv5   "/usr/libexec/getty Pc"         cons25  on  secure
468     ttyv6   "/usr/libexec/getty Pc"         cons25  on  secure
469     ttyv7   "/usr/libexec/getty Pc"         cons25  on  secure
470     ttyv8   "/usr/local/bin/xdm -nodaemon"  xterm   off secure
471
472 For a detailed description of every column in this file and all the options you can use to set things up for the virtual consoles, consult the ttys(5) manual page.
473
474 ## Environment
475
476 Another feature of the shell is the use of environment variables. Environment variables are a variable key pair stored in the shell's environment space. This space can be read by any program invoked by the shell, and thus contains a lot of program configuration. Here is a list of common environment variables and what they mean:
477
478 [[!table  data="""
479 <tablestyle="width:100%"> Variable | Description 
480 <tablestyle="width:100%"> `USER` | Current logged in user's name. 
481  `PATH` | Colon separated list of directories to search for binaries. 
482  `DISPLAY` | Network name of the X11 display to connect to, if available. 
483  `SHELL` | The current shell. 
484  `TERM` | The name of the user's terminal. Used to determine the capabilities of the terminal. 
485  `TERMCAP` | Database entry of the terminal escape codes to perform various terminal functions. 
486  `OSTYPE` | Type of operating system. e.g., DragonFly. 
487  `MACHTYPE` | The CPU architecture that the system is running on. 
488  `EDITOR` | The user's preferred text editor. 
489  `PAGER` | The user's preferred text pager. 
490  `MANPATH` | Colon separated list of directories to search for manual pages. |
491
492 """]]
493
494 Setting an environment variable differs somewhat from shell to shell. For example, in the C-Style shells such as tcsh(1) and csh(1), you would use **setenv** to set environment variables. Under Bourne shells such as sh(1) and bash(1), you would use **export** to set your current environment variables. For example, to set or modify the `EDITOR` environment variable, under csh(1) or tcsh(1) a command like this would set `EDITOR` to `/usr/local/bin/emacs`:
495     
496
497     % setenv EDITOR /usr/local/bin/emacs
498
499 Under Bourne shells:
500
501     $ export EDITOR="/usr/local/bin/emacs"
502
503 You can also make most shells expand the environment variable by placing a `$` character in front of it on the command line. For example, `echo $TERM` would print out whatever `$TERM` is set to, because the shell expands `$TERM` and passes it on to `echo`.
504
505 Shells treat a lot of special characters, called meta-characters as special representations of data. The most common one is the `*` character, which represents any number of characters in a filename. These special meta-characters can be used to do filename globbing. For example, typing in `echo *` is almost the same as typing in `ls` because the shell takes all the files that match `*` and puts them on the command line for `echo` to see.
506
507 To prevent the shell from interpreting these special characters, they can be escaped from the shell by putting a backslash (`\`) character in front of them. `echo $TERM` prints whatever your terminal is set to. `echo \$TERM` prints `$TERM` as is.
508
509 ## Devices and Device Nodes 
510
511 A device is a term used mostly for hardware-related activities in a system, including disks, printers, graphics cards, and keyboards. When DragonFly boots, the majority of what DragonFly displays are devices being detected. You can look through the boot messages again by viewing `/var/run/dmesg.boot`.
512
513 For example, `acd0` is the first IDE CDROM drive, while `kbd0` represents the keyboard.
514
515 Most of these devices in a UNIX® operating system must be accessed through special files called device nodes, which are located in the `/dev` directory.
516
517 The device nodes in the `/dev` directory are created and destroyed automatically on DragonFly, by means of the device file system (devfs).
518
519 ## Disk Organization 
520
521 The smallest unit of organization that DragonFly uses to find files is the filename. Filenames are case-sensitive, which means that `readme.txt` and `README.TXT` are two separate files. DragonFly does not use the extension (`.txt`) of a file to determine whether the file is a program, or a document, or some other form of data.
522
523 Files are stored in directories.  A directory may contain no files, or it may contain many hundreds of files.  A directory can also contain other directories, allowing you to build up a hierarchy of directories within one another.  This makes it much easier to organize your data.
524
525 Files and directories are referenced by giving the file or directory name, followed by a forward slash, `/`, followed by any other directory names that are necessary.  If you have directory `foo`, which contains directory `bar`, which contains the file `readme.txt`, then the full name, or ***path*** to the file is `foo/bar/readme.txt`.
526
527 You might notice that all directories contain `.` and `..` directories. `.` is that directory itself, for example, `/usr/` is equivalent to `/usr/./` equivalent to `/usr/././` and so on. `..` is the parent directory, for example, `/` is equivalent to `/usr/../` equivalent to `/usr/../usr/..` and so on. So, the path to the file `foo/bar/readme.txt` could be written as `./foo/bar/../bar/./readme.txt`. `/`'s parent directory is `/`, so `/` is equivalent to `/../../../../../../`.
528
529 You might want to use **~** as a shortcut to your user's home directory. If you're logged in as **pedik** and path to his home directory is **/home/pedik**, you may simply write **~** instead of that long path (i.e. **~/foo/bar/readme.txt** is equivalent to **/home/pedik/foo/bar/readme.txt**). Note that **~** is usually interpreted by a shell and not guaranted to work anywhere else.
530
531 Directories and files are stored in a file system. Each file system contains exactly one directory at the very top level, called the ***root directory*** for that file system.  This root directory can then contain other directories.
532
533 So far this is probably similar to any other operating system you may have used.  There are a few differences; for example, MS-DOS® and Windows® use `\`.
534
535 DragonFly does not use drive letters, or other drive names in the path.
536
537 Instead, one file system is designated the ***root file system***.  The root file system's root directory is referred to as `/`.  Every other file system is then ***mounted*** under the root file system. No matter how many disks you have on your DragonFly system, every directory appears to be part of the same disk.
538
539 Suppose you have three file systems, called `A`, `B`, and `C`. Each file system has one root directory, which contains two other directories, called `A1`, `A2` (and likewise `B1`, `B2` and `C1`, `C2`).
540
541 Call `A` the root file system. If you used the `ls` command to view the contents of this directory you would see two subdirectories, `A1` and `A2`.  The directory tree looks like this.
542
543 A file system must be mounted on to a directory in another file system. So now suppose that you mount file system `B` on to the directory `A1`.  The root directory of `B` replaces `A1`, and the directories in `B` appear accordingly.
544
545 Any files that are in the `B1` or `B2` directories can be reached with the path `/A1/B1` or `/A1/B2` as necessary. Any files that were in `/A1` have been temporarily hidden.  They will reappear if `B` is ***unmounted*** from A.
546
547 If `B` had been mounted on `A2` then the paths would be `/A2/B1` and `/A2/B2` respectively.
548
549 File systems can be mounted on top of one another.  Continuing the last example, the `C` file system could be mounted on top of the `B1` directory in the `B` file system.
550
551 Or `C` could be mounted directly on to the `A` file system, under the `A1` directory.
552
553 ### The fstab File 
554
555 During the boot process, file systems listed in `/etc/fstab` are automatically mounted (unless they are listed with the `noauto` option).
556
557 The `/etc/fstab` file contains a list of lines of the following format:
558
559     # Device       Mountpoint   FStype     Options      Dump     Pass#
560
561 These parameters have the following meaning:
562
563 * `Device`: A device name (which should exist).
564
565 * `Mountpoint`: A directory (which should exist), on which to mount the file system.
566
567 * `FStype`: The file system type to pass to mount(8). The default DragonFly file system is `ufs`.
568
569 * `Options`: Either `rw` for read-write file systems, or `ro` for read-only file systems, followed by any other options that may be needed. A common option is `noauto` for file systems not normally mounted during the boot sequence. Other options are listed in the mount(8) manual page.
570
571 * `Dump`: This is used by dump(8) to determine which file systems require dumping. If the field is missing, a value of zero is assumed.
572
573 * `Pass`: This determines the order in which file systems should be checked. File systems that should be skipped should have their `passno` set to zero. The root file system (which needs to be checked before everything else) should have its `passno` set to one, and other file systems' `passno` should be set to values greater than one. If more than one file systems have the same `passno` then [fsck(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fsck&section=8) will attempt to check file systems in parallel if possible.
574
575 Consult the fstab(5) manual page for more information on the format of the `/etc/fstab` file and the options it contains.
576
577 ### The mount Command 
578
579 The mount(8) command is what is ultimately used to mount file systems.
580
581 In its most basic form, you use:
582
583     # mount device mountpoint
584
585 Or, if `mountpoint` is specified in `/etc/fstab`, just:    
586
587     # mount mountpoint
588
589 There are plenty of options, as mentioned in the mount(8) manual page, but the most common are:
590
591  **Mount Options** 
592
593 * `-a`: Mount all the file systems listed in `/etc/fstab`. Except those marked as `noauto`, excluded by the `-t` flag, or those that are already mounted.
594
595 * `-d`: Do everything except for the actual mount system call. This option is useful in conjunction with the `-v` flag to determine what mount(8) is actually trying to do.
596
597 * `-f`: Force the mount of an unclean file system (dangerous), or forces the revocation of write access when downgrading a file system's mount status from read-write to read-only.
598
599 * `-r`: Mount the file system read-only. This is identical to using the `rdonly` argument to the `-o` option.
600
601 * `-t` ***fstype***: Mount the given file system as the given file system type, or, if used with `-a` option, mount only file systems of the given type. `ufs` is the default file system type.
602
603 * `-u`: Update mount options on the file system.
604
605 * `-v`: Be verbose.
606
607 * `-w`: Mount the file system read-write.
608
609 The `-o` option takes a comma-separated list of the options, including the following:
610
611 * `nodev:` Do not interpret special devices on the file system. This is a useful security option.
612
613 * `noexec`: Do not allow execution of binaries on this file system. This is also a useful security option.
614
615 * `nosuid`: Do not interpret setuid or setgid flags on the file system. This is also a useful security option.
616
617 ### The umount Command 
618
619 The umount(8) command takes, as a parameter, one of a mountpoint, a device name, or the `-a` or `-A` option.
620
621 All forms take `-f` to force unmounting, and `-v` for verbosity. Be warned that `-f` is not generally a good idea. Forcibly unmounting file systems might crash the computer or damage data on the file system.
622
623 `-a` and `-A` are used to unmount all mounted file systems, possibly modified by the file system types listed after `-t`. `-A`, however, does not attempt to unmount the root file system.
624
625 ## Choosing File System Layout 
626
627 This is not normally something you need to concern yourself with. Typically you create file systems when installing DragonFly and decide where to mount them, and then never change them unless you add a new disk.
628
629 It is entirely possible to have one large root file system, and not need to create any others. There are some drawbacks to this approach, and one advantage.
630
631  **Benefits of Multiple File Systems** 
632
633 * Different file systems can have different ***mount options***.  For example, with careful planning, the root file system can be mounted read-only, making it impossible for you to inadvertently delete or edit a critical file.  Separating user-writable file systems, such as `/home`, from other file systems also allows them to be mounted ***nosuid***; this option prevents the ***suid***/***guid*** bits on executables stored on the file system from taking effect, possibly improving security.
634
635 * The UFS file system automatically optimizes the layout of files, depending on how the file system is being used. So a file system that contains many small files that are written frequently will have a different optimization to one that contains fewer, larger files.  By having one big file system this optimization breaks down.
636
637 * DragonFly's file systems are very robust should you lose power.  However, a power loss at a critical point could still damage the structure of the file system.  By splitting your data over multiple file systems it is more likely that the system will still come up, making it easier for you to restore from backup as necessary. This is a major reason to make the root file system of limited size, and with low write activity.
638
639  **Benefit of a Single File System** 
640
641 * File systems are a fixed size. If you create a file system when you install DragonFly and give it a specific size, you may later discover that you need to make the partition bigger.  The [growfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=growfs&amp;section=8) command makes it possible to increase the size of a UFS file system on the fly.
642
643 ## Disk Slices, Partitions and local UNIX file systems
644
645 DragonFly BSD divides disks into partitions and slices; it refers to locations on a disk by means of their unique codes.  For instance, the disk code `da1s3d` has a clear meaning: SCSI hard disk one, slice three, root file system.  Meanings for other such codes will become apparent by the end of this section; first of all come the meanings for the physical drive codes.  The most common are:
646
647 [[!table  data="""
648 <tablestyle="width:100%"> Code | Meaning 
649 <tablestyle="width:100%"> `ad` | ATAPI (IDE) disk 
650 `da` | SCSI direct access disk 
651 `acd` | ATAPI (IDE) CDROM 
652 `cd` | SCSI CDROM 
653 `vn` | Virtual disk
654 `fd` | Floppy disk |
655 """]]
656
657
658 ### Slices 
659
660 In BSD UNIX, including DragonFly, what are elsewhere known as ***partitions*** are instead known as ***slices***; on a multi-boot system, every operating system occupies at least one slice and is aware of the others.  Linux, and most UNIX operating systems, generally occupy at least two slices, one for the file system and one for swap space; on the other hand, BSD (with the exception of MacOS/DarwinBSD) may occupy only one slice, using an alternative method (called ***partitioning*** in BSD) to segregate file system and swap space.  Programs such as `parted` and `gparted`, contrary to their names, are in fact disk slicers.
661
662 In DragonFly, disk slices are designated with the letter `s` for ***slice*** and a positive integer, beginning either from zero or one, depending on the slicing scheme.  The first slice of a physical disk is thus named `s0`; the second, `s1`; and so on.  There can only be four ***physical*** slices on a disk, but one of these, designated the ***extended*** slice, may itself be sliced into ***logical*** slices.  If an extended slice exists, the logical slices it contains are numbered beginning with `s5`.  
663
664 For instance, the disk `da6` may be divided into physical slices `da6s1`, `da6s2` (the extended slice, containing logical slices `da6s5` and `da6s6`), and `da6s3`.  Note that if there are less than four physical slices, the relevant numbers are skipped, even if there are logical slices.
665
666 DragonFly supports two schemes for slices, MBR and GPT. Either of them can manage all of the slices on a disk:
667
668 * MBR: are set up using fdisk(8) and can be up to two terabytes (2,048 GB) in size.  Usually, MBR slices are numbered from 1; if there is only one slice on the disk (that is, the disk is ***dangerously dedicated***), however,it has slice number 0.
669
670 * GPT: are set up using gpt(8) and support disk sizes up to eight exabytes (eight billion terabytes, a ludicrously large and, within the foreseeable future, entirely theoretical size equivalent to 800,000 times the sum total of printed works within the Library of Congress).  ***Dangerous dedication*** is irrelevant in GPT; slices are ***always*** numbered from 0.
671
672 ### Partitions 
673
674 Uniquely in BSD, disk slices contain `disklabel` partitions. BSD can dispense with slices entirely and use a utility known as `disklabel` (or `bsdlabel`) to ***partition*** the disk instead. 
675
676 All BSD UNIX operating systems support eight partitions per slice, labelled `a` through `h`; most BSD systems, DragonFly included, support an additional eight, labelled `i` through `p`, for a total of sixteen per slice.  Partition layout is defined in a label on the slice where they reside.  Since each partition may have its own ***file system***, ***in BSD***, one slice may be formatted in several different file systems (a situation that does not hold true in Linux or Windows). 
677
678 Partition layout is defined in a label on the slice where the partition reside. DragonFly support two types of disk labels, disklabel32 and disklabel64 (the default):
679
680 * disklabel32(8): 32 bit disk label which can use slices with size up to 2 TB.
681
682 * disklabel64(8): 64 bit disk label which can use very large slices: size up to 16 million TB.
683
684 ***By convention***, four partition labels are reserved by the system and have special meanings.  The convention does not strictly have to hold true, but it is highly recommended to follow this gentleman's agreement:
685
686 [[!table  data="""
687 <tablestyle="width:100%"> Partition | Convention 
688 <tablestyle="width:100%"> `a` | Normally contains the root file system 
689  `b` | Normally contains swap space 
690   `c` | Normally the same size as the enclosing slice.  This allows utilities that need to work on the entire slice (for example, a bad block scanner) to work on the `c` partition. You would not normally create a file system on this partition. This is not necessarily true; it is possible to use the 'c' partition as a normal partition.
691    `d` | Normally the same size as the entire physical disk.  This is now rare, but to this day, some tools may operate oddly if told to work on partition `d`. | """]]   
692
693 ### Local UNIX file systems 
694
695 Each partition can contain only one ***file system***. Therefore, file systems often are described by either their typical mount point in the file system hierarchy, or the letter of the `disklabel` partition they are contained in.  DragonFly BSD supports three local UNIX file systems, UFS, HAMMER and HAMMER2:
696
697 * UFS: is the classic BSD UNIX file system (see ffs(5)). It supports a volume size up to two terabytes.
698
699 * HAMMER(5): is the classic DragonFly BSD file system with many advanced features.  HAMMER supports a volume size of up to one exabyte (one million terabytes).
700
701 * HAMMER2: is a brand-new DragonFlyBSD file system.
702
703 ***Historically***, the desirability of HAMMERfs increased with storage capacity.  For booting DragonFly from a small, local file system, UFS was previously recommended, with the option of a BOOT+HAMMER set up (512 MB UFS boot partition, the rest HAMMERfs).  For moderate storage requirements, UFS continued to be an option, but the extra features boasted by HAMMERfs (such as history retention) made it more desirable in this regard.  
704 Then, as now, HAMMERfs was the unrivalled king of the large partition, usually with a [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section=8) label on a GPT slice.
705
706 HAMMERfs is recommended for all volumes greater than fifty gigabytes---that is to say, all volumes manufactured within the last five years, and a goodly portion of older ones as well.
707
708 ### Adding a Disk 
709
710 Adding a disk is done by installing it physically and by connecting it to a disk controller supported by DragonFly BSD.  If you are in doubt as to whether a particular disk controller is supported, the manual pages for disk controllers can be consulted (`man -k disk` or `man -k scsi` can be of help).  Another, easier way of ascertaining support for a controller is to boot with the controller installed, and note if the boot messages contain the controller.
711
712 Assuming that disk `da6` is installed, we could set it up the old-fashioned way, using [fdisk(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fdisk&amp;section=8) and [disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&amp;section=8) or the modern way, with [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section=8) and [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section=8), or any combination thereof.
713
714 In this example, we chose [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section=8) and [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section=8).
715
716     # gpt -v create da6
717     [...]
718     # gpt add -s1 da6
719     da6s0
720     # gpt add da6
721     da6s1
722     # gpt show da6
723     [...]
724
725 In the above example, we first create the GPT and then add two slices.  The first slice added is `da6s0`, which is made a dummy slice of size 1 sector.  The reason for this is backwards compatibility: veteran users may remember that `s0` has special meaning in MBR slice schemes, but this is not true in GPT slices.  The second slice, `da6s1`, will cover the rest of the disk:
726
727     # disklabel -rw da6s1 auto
728
729 Edit label to add partitions as needed:
730
731     # disklabel -e da6s1
732
733 ## Processes 
734
735 DragonFly is a multi-tasking operating system. This means that it seems as though more than one program is running at once. Each program running at any one time is called a ***process***. Every command you run will start at least one new process, and there are a number of system processes that run all the time, keeping the system functional.
736
737 Each process is uniquely identified by a number called a ***process ID***, or ***PID***, and, like files, each process also has one owner and group. The owner and group information is used to determine what files and devices the process can open, using the file permissions discussed earlier. Most processes also have a parent process. The parent process is the process that started them. For example, if you are typing commands to the shell then the shell is a process, and any commands you run are also processes. Each process you run in this way will have your shell as its parent process. The exception to this is a special process called [init(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=init&section=8). `init` is always the first process, so its PID is always 1. `init` is started automatically by the kernel when DragonFly starts.
738
739 Two commands are particularly useful to see the processes on the system, [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1) and [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section=1). The `ps` command is used to show a static list of the currently running processes, and can show their PID, how much memory they are using, the command line they were started with, and so on. The `top` command displays all the running processes, and updates the display every few seconds, so that you can interactively see what your computer is doing.
740
741 By default, `ps` only shows you the commands that are running and are owned by you. For example:
742
743     % ps
744
745        PID  TT  STAT      TIME COMMAND
746       1334  0  I0s      0:00.04 -tcsh (tcsh)
747       1344  0  S3+      1:44.95 toxic
748       1318  1  I3s      0:00.01 tcsh
749       1331  1  I3+      0:00.01 tmux: client (/tmp/tmux-1001/default) (tmux)
750       1384  2  I1s      0:00.06 -tcsh (tcsh)
751       1427  2  S1+      0:05.43 weechat
752     427874  3  I1s      0:00.04 -tcsh (tcsh)
753     429005  3  I2+      0:00.22 mutt
754     521063  4  S1s      0:00.06 tcsh
755     521070  4  R0+      0:00.00 ps
756
757 As you can see in this example, the output from [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1) is organized into a number of columns. `PID` is the process ID discussed earlier. PIDs are assigned starting from 1, go up to 999999, and wrap around back to the beginning when you run out. The `TT` column shows the tty the program is running on, and can safely be ignored for the moment. `STAT` shows the program's state, and again, can be safely ignored. `TIME` is the amount of time the program has been running on the CPU--this is usually not the elapsed time since you started the program, as most programs spend a lot of time waiting for things to happen before they need to spend time on the CPU. Finally, `COMMAND` is the command line that was used to run the program.
758
759 [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps&section=1) supports a number of different options to change the information that is displayed. One of the most useful sets is `auxww`. `a` displays information about all the running processes, not just your own. `u` displays the username of the process' owner, as well as memory usage. `x` displays information about daemon processes, and `ww` causes [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1) to display the full command line, rather than truncating it once it gets too long to fit on the screen.
760
761 The output from [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section=1) is similar. A sample session looks like this:
762
763     
764
765     % top
766     load averages:  2.27,  2.53,  2.49;               up 0+08:40:44        04:17:09
767     49 processes: 1 running, 49 active
768     CPU states:     % user,     % nice,     % system,     % interrupt,     % idle
769     Memory: 4K Active, 4K Inact, 131098G Wired, 131088G Cache, 391M Buf, 536870904G
770     Swap: 8192M Total, 100M Used, 8092M Free, 1% Inuse
771
772        PID USERNAME   NICE  SIZE    RES    STATE   C   TIME   CTIME    CPU COMMAND
773     522158 mazocomp     0    16M    11M   kqread   2   0:00    0:00  2.34% xterm
774       1044 root         0    72M    24M   kqread   3   8:27    8:27  1.61% Xorg
775     522159 mazocomp     0  6764K  4552K    pause   1   0:00    0:00  1.42% tcsh
776        756 root         0  3404K   836K   kqread   1   0:00    0:00  0.29% udevd
777     407472 mazocomp     0  1227M   125M   kqread   1   2:01    2:01  0.00% vimb
778       1344 mazocomp     0    40M  5852K   nanslp   3   1:46    3:19  0.00% toxic
779        825 _sndio     -20  3884K  1104K   kqread   0   0:21    0:21  0.00% sndiod
780     ...
781
782 The output is split into two sections. The header (the first five lines) shows the system load averages (which are a measure of how busy the system is), the system uptime (time since the last boot) and the current time. The other figures in the header relate to how many processes are running (49 in this case), how much time the system is spending in different CPU states, and how much memory and swap space has been taken up.
783
784 Below that are a series of columns containing similar information to the output from [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1). As before you can see the PID, the username, the amount of CPU time taken, and the command that was run. [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section=1) also defaults to showing you the amount of memory space taken by the process. This is split into two columns, one for total size, and one for resident size. Total size is how much memory the application has needed, and the resident size is how much it is actually using at the moment. In this example you can see that  **Vimb**  has required 1227 MB of RAM, but is currently only using 125 MB.
785
786 [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section=1) automatically updates this display every five seconds; this can be changed with the `s` option.
787
788 ### Daemons, Signals, and Killing Processes 
789
790 When you run an editor it is easy to control the editor, tell it to load files, and so on. You can do this because the editor provides facilities to do so, and because the editor is attached to a ***terminal***. Some programs are not designed to be run with continuous user input, and so they disconnect from the terminal at the first opportunity. For example, a web server spends all day responding to web requests, it normally does not need any input from you. Programs that transport email from site to site are another example of this class of application.
791
792 We call these programs ***daemons***. Daemons were characters in Greek mythology; neither good or evil, they were little attendant spirits that, by and large, did useful things for mankind. Much like the web servers and mail servers of today do useful things. This is why the mascot for a number of BSD-based operating systems has, for a long time, been a cheerful looking daemon with sneakers and a pitchfork.
793
794 There is a convention to name programs that normally run as daemons with a trailing ***d***.  **BIND**  is the Berkeley Internet Name Daemon (and the actual program that executes is called `named`), the  **Apache**  web server program is called `httpd`, the line printer spooling daemon is `lpd` and so on. This is a convention, not a hard and fast rule; for example, the main mail daemon for the  **Sendmail**  application is called `sendmail`, and not `maild`, as you might imagine.
795
796 Sometimes you will need to communicate with a daemon process. These communications are called ***signals***, and you can communicate with a daemon (or with any other running process) by sending it a signal. There are a number of different signals that you can send--some of them have a specific meaning, others are interpreted by the application, and the application's documentation will tell you how that application interprets signals. You can only send a signal to a process that you own. If you send a signal to someone else's process with [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) or [kill(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=2) permission will be denied. The exception to this is the `root` user, who can send signals to everyone's processes.
797
798 DragonFly will also send applications signals in some cases. If an application is badly written, and tries to access memory that it is not supposed to, DragonFly sends the process the ***Segmentation Violation*** signal (`SIGSEGV`). If an application has used the [alarm(3)](http://leaf.dragonflybsd.org/cgi/web-man?command=alarm&section=3) system call to be alerted after a period of time has elapsed then it will be sent the Alarm signal (`SIGALRM`), and so on.
799
800 Two signals can be used to stop a process, `SIGTERM` and `SIGKILL`. `SIGTERM` is the polite way to kill a process; the process can ***catch*** the signal, realize that you want it to shut down, close any log files it may have open, and generally finish whatever it is doing at the time before shutting down. In some cases a process may even ignore `SIGTERM` if it is in the middle of some task that can not be interrupted.
801
802 `SIGKILL` can not be ignored by a process. This is the ***I do not care what you are doing, stop right now*** signal. If you send `SIGKILL` to a process then DragonFly will stop that process there.
803
804 **Important:** Killing random process on the system can be a bad idea. In particular, [init(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=init&section=8), process ID 1, is very special. Running `/bin/kill -s KILL 1` is a quick way to shutdown your system. ***Always*** double check the arguments you run [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) with ***before*** you press **Return** .
805
806 The other signals you might want to use are `SIGHUP`, `SIGUSR1`, and `SIGUSR2`. These are general purpose signals, and different applications will do different things when they are sent.
807
808 Suppose that you have changed your web server's configuration file--you would like to tell the web server to re-read its configuration. You could stop and restart `httpd`, but this would result in a brief outage period on your web server, which may be undesirable. Most daemons are written to respond to the `SIGHUP` signal by re-reading their configuration file. So instead of killing and restarting `httpd` you would send it the `SIGHUP` signal. Because there is no standard way to respond to these signals, different daemons will have different behavior, so be sure and read the documentation for the daemon in question.
809
810 Signals are sent using the [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) command, as this example shows.
811
812  **Sending a Signal to a Process** 
813
814 This example shows how to send a signal to [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8). The `inetd` configuration file is `/etc/inetd.conf`, and `inetd` will re-read this configuration file when it is sent `SIGHUP`.
815
816   1. Find the process ID of the process you want to send the signal to. Do this using [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps&section=1) and [grep(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=grep&section=1). The [grep(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=grep&section=1) command is used to search through output, looking for the string you specify. This command is run as a normal user, and [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8) is run as `root`, so the `ax` options must be given to [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1).
817
818       
819
820         % ps -ax | grep inetd
821
822         198  ??  IWs    0:00.00 inetd -wW
823
824   
825
826   So the [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#inetd&section8) PID is 198. In some cases the `grep inetd` command might also occur in this output. This is because of the way [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1) has to find the list of running processes.
827
828   2. Use [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) to send the signal. Because [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8) is being run by `root` you must use [su(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=su&section=1) to become `root` first.
829
830         % su
831         Password:
832         # /bin/kill -s HUP 198
833
834   In common with most UNIX® commands, [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) will not print any output if it is successful. If you send a signal to a process that you do not own then you will see `kill: PID: Operation not permitted`. If you mistype the PID you will either send the signal to the wrong process, which could be bad, or, if you are lucky, you will have sent the signal to a PID that is not currently in use, and you will see `kill: PID: No such process`.
835
836 **Why Use `/bin/kill`?** Many shells provide the `kill` command as a built in command; that is, the shell will send the signal directly, rather than running `/bin/kill`. This can be very useful, but different shells have a different syntax for specifying the name of the signal to send. Rather than try to learn all of them, it can be simpler just to use the `/bin/kill ...` command directly.
837
838 Sending other signals is very similar, just substitute `TERM` or `KILL` in the command line as necessary.