MicroBSD Handbook

Prev Next

3.5 Processes

MicroBSD like his father and mother (FreeBSD and OpenBSD) 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.

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. init is always the first process, so its PID is always 1. init is started automatically by the kernel when MicroBSD starts.

Two commands are particularly useful to see the processes on the system, ps and top. 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.

By default, ps only shows you the commands that are running and are owned by you. For example:

    # ps -auwx
    USER       PID %CPU %MEM   VSZ   RSS TT   STAT STARTED       TIME COMMAND
    root     13604  0.0  0.0   260   144 p0  R+     2:58AM    0:00.00 (ps)
    root     27595  0.0  0.0   104   376 ??  Ss     2:11PM    0:00.41 (syslogd)
    root     27276  0.0  0.0   356   864 ??  Is     2:11PM    0:01.41 (sshd)
    root      9046  0.0  0.0   228   460 ??  Ss     2:11PM    0:00.25 (cron)
    root      7042  0.0  0.0    48   404 C0  Is+    2:11PM    0:00.01 (getty)
    root     19730  0.0  0.0    48   404 C1  Is+    2:11PM    0:00.01 (getty)
    root     12624  0.0  0.0    48   404 C2  Is+    2:11PM    0:00.01 (getty)
    root     16538  0.0  0.0    48   404 C3  Is+    2:11PM    0:00.01 (getty)
    root     13760  0.0  0.0    48   404 C5  Is+    2:11PM    0:00.01 (getty)
    root     31398  0.0  0.0   412  1264 ??  Ss    12:33AM    0:00.60 (sshd)
    root      3570  0.0  0.0  1036  1524 p0  Ss    12:33AM    0:00.28 (tcsh)
    root     22496  0.0  0.0  1856   688 ??  Is    12:35AM    0:00.02 (smbd)
    root     26456  0.0  0.0   992   752 ??  Ss    12:36AM    0:00.51 (nmbd)
    root         1  0.0  0.0   340   192 ??  Is     2:11PM    0:00.02 (init)
 
 
-a

Display information about other users' processes as well as your own.

-u

Display information associated with the following keywords: user, pid, %cpu, %mem, vsz, rss, tt, state, start, time, and command.

-w

Use 132 columns to display information, instead of the default, which is your window size. If the -w option is specified more than once, ps will use as many columns as necessary without regard for your window size.

-x

Display information about processes without controlling terminals.

As you can see in this example, the output from ps is organized into a number of columns. USER is the user that own this process, PID is the process ID. PIDs are assigned starting from 1, go up to 99999, and wrap around back to the beginning when you run out. %CPU shows the usage of the processor, %MEM shows the memory used to run this process, VSZ shows virtual size in Kbytes (alias vsize), RSS shows real memory (resident set) size of the process (in 1024 byte units), TT 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. STARTED shows at what time process start, TIME is the amount of time the program has been running on the CPU--this is not necessarily the elapsed time since you started the program, as some 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.

The output from top is similar. A sample session looks like this:

    # top
    load averages:  0.10,  0.08,  0.08                                                                                                   03:28:54
    14 processes:  1 running, 14 idle
    CPU states:  0.0% user,  0.0% nice,  0.2% system,  0.0% interrupt, 99.8% idle
    Memory: Real: 7284K/16M act/tot  Free: 41M  Swap: 0M/140M used/tot

    PID USERNAME PRI NICE  SIZE   RES STATE WAIT     TIME    CPU COMMAND
  27276 root       2    0  356K  864K idle  select   0:01  0.00% sshd
  31398 root       2    0  456K 1288K sleep select   0:00  0.00% sshd
  26456 root       2    0  992K  752K sleep select   0:00  0.00% nmbd
  27595 root       2    0  104K  376K sleep select   0:00  0.00% syslogd
   3570 root      18    0 1036K 1524K sleep pause    0:00  0.00% tcsh
   9046 root       2    0  228K  460K idle  select   0:00  0.00% cron
      1 root      10    0  340K  192K idle  wait     0:00  0.00% init
  22496 root       2    0 1856K  688K idle  select   0:00  0.00% smbd
   7042 root       3    0   48K  404K idle  ttyin    0:00  0.00% getty
  16538 root       3    0   48K  404K idle  ttyin    0:00  0.00% getty
  19730 root       3    0   48K  404K idle  ttyin    0:00  0.00% getty
  13760 root       3    0   48K  404K idle  ttyin    0:00  0.00% getty
  12624 root       3    0   48K  404K idle  ttyin    0:00  0.00% getty
  17609 root      29    0  136K  648K run   -        0:00  0.00% top
 
 

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 other figures in the header relate to how many processes are running (14 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.

Below that are a series of columns containing similar information to the output from ps. As before you can see the PID, the username, the amount of CPU time taken, and the command that was run. top 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.

top automatically updates this display every two seconds; this can be changed with the -s option.


Prev Home Next
Mounting and Unmointing Filesystems Daemons, Signals, and Killing Processes

This, and other documents, can be downloaded from MicroBSD.

For questions about MicroBSD, read the documentation before contacting <MicroBSD Support>.
Copyright © 1995-2003 by The FreeBSD Documentation Project, OpenBSD FAQ Copyright © 1998-2003 OpenBSD, Modified for MicroBSD