FIX: markdown style changes
[ikiwiki.git] / docs / handbook / handbook-basics-processes.mdwn
1 ## Processes 
2
3
4
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.
6
7
8
9 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.
10
11 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.
12
13
14
15 By default, `ps` only shows you the commands that are running and are owned by you. For example:
16
17
18
19     
20
21     % ps
22
23       PID  TT  STAT      TIME COMMAND
24       298  p0  Ss     0:01.10 tcsh
25      7078  p0  S      2:40.88 xemacs mdoc.xsl (xemacs-21.1.14)
26     37393  p0  I      0:03.11 xemacs freebsd.dsl (xemacs-21.1.14)
27     48630  p0  S      2:50.89 /usr/local/lib/netscape-linux/navigator-linux-4.77.bi
28     48730  p0  IW     0:00.00 (dns helper) (navigator-linux-)
29     72210  p0  R+     0:00.00 ps
30       390  p1  Is     0:01.14 tcsh
31      7059  p2  Is+    1:36.18 /usr/local/bin/mutt -y
32      6688  p3  IWs    0:00.00 tcsh
33     10735  p4  IWs    0:00.00 tcsh
34     20256  p5  IWs    0:00.00 tcsh
35       262  v0  IWs    0:00.00 -tcsh (tcsh)
36       270  v0  IW+    0:00.00 /bin/sh /usr/X11R6/bin/startx -- -bpp 16
37       280  v0  IW+    0:00.00 xinit /home/nik/.xinitrc -- -bpp 16
38       284  v0  IW     0:00.00 /bin/sh /home/nik/.xinitrc
39       285  v0  S      0:38.45 /usr/X11R6/bin/sawfish
40
41
42
43 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.
44
45
46
47 [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.
48
49
50
51 The output from [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#top&section1) is similar. A sample session looks like this:
52
53
54
55     
56
57     % top
58     last pid: 72257;  load averages:  0.13,  0.09,  0.03    up 0+13:38:33  22:39:10
59     47 processes:  1 running, 46 sleeping
60     CPU states: 12.6% user,  0.0% nice,  7.8% system,  0.0% interrupt, 79.7% idle
61     Mem: 36M Active, 5256K Inact, 13M Wired, 6312K Cache, 15M Buf, 408K Free
62     Swap: 256M Total, 38M Used, 217M Free, 15% Inuse
63     
64
65       PID USERNAME PRI NICE  SIZE    RES STATE    TIME   WCPU    CPU COMMAND
66     72257 nik       28   0  1960K  1044K RUN      0:00 14.86%  1.42% top
67      7078 nik        2   0 15280K 10960K select   2:54  0.88%  0.88% xemacs-21.1.14
68       281 nik        2   0 18636K  7112K select   5:36  0.73%  0.73% XF86_SVGA
69       296 nik        2   0  3240K  1644K select   0:12  0.05%  0.05% xterm
70     48630 nik        2   0 29816K  9148K select   3:18  0.00%  0.00% navigator-linu
71       175 root       2   0   924K   252K select   1:41  0.00%  0.00% syslogd
72      7059 nik        2   0  7260K  4644K poll     1:38  0.00%  0.00% mutt
73     ...
74
75 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.
76
77 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.
78
79
80
81 [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.