update for rename of docs/user/DebugKernelCrashDumps.mdwn to docs/user/list/DebugKern...
[ikiwiki.git] / docs / handbook / handbook-basics-processes.mdwn
1 \r
2 \r
3 ## 3.7 Processes \r
4 \r
5 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.\r
6 \r
7 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&section8). `init` is always the first process, so its PID is always 1. `init` is started automatically by the kernel when DragonFly starts.\r
8 \r
9 Two commands are particularly useful to see the processes on the system, [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps&section1) 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.\r
10 \r
11 By default, `ps` only shows you the commands that are running and are owned by you. For example:\r
12 \r
13     \r
14     % ps\r
15       PID  TT  STAT      TIME COMMAND\r
16       298  p0  Ss     0:01.10 tcsh\r
17      7078  p0  S      2:40.88 xemacs mdoc.xsl (xemacs-21.1.14)\r
18     37393  p0  I      0:03.11 xemacs freebsd.dsl (xemacs-21.1.14)\r
19     48630  p0  S      2:50.89 /usr/local/lib/netscape-linux/navigator-linux-4.77.bi\r
20     48730  p0  IW     0:00.00 (dns helper) (navigator-linux-)\r
21     72210  p0  R+     0:00.00 ps\r
22       390  p1  Is     0:01.14 tcsh\r
23      7059  p2  Is+    1:36.18 /usr/local/bin/mutt -y\r
24      6688  p3  IWs    0:00.00 tcsh\r
25     10735  p4  IWs    0:00.00 tcsh\r
26     20256  p5  IWs    0:00.00 tcsh\r
27       262  v0  IWs    0:00.00 -tcsh (tcsh)\r
28       270  v0  IW+    0:00.00 /bin/sh /usr/X11R6/bin/startx -- -bpp 16\r
29       280  v0  IW+    0:00.00 xinit /home/nik/.xinitrc -- -bpp 16\r
30       284  v0  IW     0:00.00 /bin/sh /home/nik/.xinitrc\r
31       285  v0  S      0:38.45 /usr/X11R6/bin/sawfish\r
32 \r
33 \r
34 As you can see in this example, the output from [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps&section1) is organized into a number of columns. `PID` is the process ID discussed earlier. PIDs are assigned starting from 1, go up to 99999, 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.\r
35 \r
36 [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps&section1) 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.\r
37 \r
38 The output from [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#top&section1) is similar. A sample session looks like this:\r
39 \r
40     \r
41     % top\r
42     last pid: 72257;  load averages:  0.13,  0.09,  0.03    up 0+13:38:33  22:39:10\r
43     47 processes:  1 running, 46 sleeping\r
44     CPU states: 12.6% user,  0.0% nice,  7.8% system,  0.0% interrupt, 79.7% idle\r
45     Mem: 36M Active, 5256K Inact, 13M Wired, 6312K Cache, 15M Buf, 408K Free\r
46     Swap: 256M Total, 38M Used, 217M Free, 15% Inuse\r
47     \r
48       PID USERNAME PRI NICE  SIZE    RES STATE    TIME   WCPU    CPU COMMAND\r
49     72257 nik       28   0  1960K  1044K RUN      0:00 14.86%  1.42% top\r
50      7078 nik        2   0 15280K 10960K select   2:54  0.88%  0.88% xemacs-21.1.14\r
51       281 nik        2   0 18636K  7112K select   5:36  0.73%  0.73% XF86_SVGA\r
52       296 nik        2   0  3240K  1644K select   0:12  0.05%  0.05% xterm\r
53     48630 nik        2   0 29816K  9148K select   3:18  0.00%  0.00% navigator-linu\r
54       175 root       2   0   924K   252K select   1:41  0.00%  0.00% syslogd\r
55      7059 nik        2   0  7260K  4644K poll     1:38  0.00%  0.00% mutt\r
56     ...\r
57 \r
58 \r
59 The output is split into two sections. The header (the first five lines) shows the PID of the last process to run, the system load averages (which are a measure of how busy the system is), the system uptime (time since the last reboot) and the current time. The other figures in the header relate to how many processes are running (47 in this case), how much memory and swap space has been taken up, and how much time the system is spending in different CPU states.\r
60 \r
61 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&section1). 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  **Netscape®**  has required almost 30 MB of RAM, but is currently only using 9 MB.\r
62 \r
63 [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#top&section1) automatically updates this display every two seconds; this can be changed with the `s` option.\r
64 \r
65 \r
66 \r
67 CategoryHandbook\r
68 CategoryHandbook-basics\r