previous contents up next

Unix for Advanced Users

10. Process Management under Unix

10.1. Process Hierarchy in Unix

As we saw in the boot sequence discussion, the second process created by the kernel after it loads itself (the first being swapper) is called init. All subsequent processes are created by init. For example, one of the processes started by init is inetd, the internet superdaemon. (inetd, in turn, creates many other processes, such as telnetd, on demand.) In the Unix process hierarchy, init is called the parent process and inetd the child of init. Any process can have any number of children (up to the kernel parameter nproc, the maximum allowed number of processes).

If you kill the parent of a child process, it automatically becomes the child of init.

Each running process has associated with it a process ID or PID (in fact, as far as the kernel is concerned, a process is just a number). In addition, each process is characterized by its parent's PID or PPID. Finally, each process runs at a default system priority, PRI. The numerical range of priority values for different Unixes is as follows.

The smaller the numerical value of the PRI, the higher the priority and vice versa (so that a process running under Solaris at a priority of 20 has a much lower priority than one running at -20).

The Unix command renice allows a user to change the priority of a running process.

The ps command can be used to look at PID and PPIDs. For example, a ps axl under Linux shows:
    % ps axl
      F   UID   PID  PPID PRI  NI   VSZ  RSS WCHAN  STAT TTY        TIME COMMAND
    100     0     1     0   0   0  1096  468 do_sel S    ?          0:07 init [5]
    040     0     2     1   0   0     0    0 bdflus SW   ?          0:00 [kflushd]
    040     0     3     1   0   0     0    0 kpiod  SW   ?          0:00 [kpiod]
    040     0     4     1   0   0     0    0 kswapd SW   ?          0:00 [kswapd]
    040     0     5     1 -20 -20     0    0 md_thr SW<  ?          0:00 [mdrecovery
    140     0   112     1   0   0  1068  376 do_sel S    ?          0:00 /usr/sbin/a
    040     0   294     1   0   0  1272  548 do_sel S    ?          0:00 syslogd -m 
    140     0   305     1   0   0  1380  644 do_sys S    ?          0:00 klogd
    040     2   319     1   0   0  1112  284 nanosl S    ?          0:00 /usr/sbin/a
    040     0   333     1   0   0  1284  532 nanosl S    ?          0:00 crond
    140     0   347     1   0   0  1232  504 do_sel S    ?          0:00 inetd
    140     0   361     1   0   0  1284  516 do_sel S    ?          0:00 lpd
    040   100   381     1   0   0  1988  908 do_sel S    ?          0:00 xfs
    140     0   396     1   0   0   640  256 do_sel S    ?          0:01 sshd
    100     0   429     1   0   0  1060  380 read_c S    tty1       0:00 /sbin/minge
    100     0   430     1   0   0  1060  380 read_c S    tty2       0:00 /sbin/minge
    100     0   431     1   0   0  1060  380 read_c S    tty3       0:00 /sbin/minge
    100     0   432     1   0   0  1060  380 read_c S    tty4       0:00 /sbin/minge
    100     0   433     1   0   0  1060  380 read_c S    tty5       0:00 /sbin/minge
    100     0   434     1   0   0  1060  380 read_c S    tty6       0:00 /sbin/minge
    100     0   435     1   0   0  2400 1088 do_pol S    ?          0:00 /etc/X11/pr
    140     0   437     1   0   0  1052  116 nanosl S    ?          0:00 update (bdf
    100     0   564   435   0   0  6052 2632 do_sel S    ?          0:01 /usr/bin/X1
    040     0   574   435   0   0  2404 1088 pipe_r S    ?          0:00 /etc/X11/pr
    100    42   578   574   0   0  5192 2760 do_pol S    ?          0:00 /usr/bin/gd
    140     0  2227   396   2   0  1976 1072 do_sel S    ?          0:01 sshd
    100     0  2229  2227   9   0  1700  940 wait4  S    ttyp0      0:00 -bash
    100     0  2270  2229  14   0  2472  820 -      R    ttyp0      0:00 ps axl
    
    In this process listing, it's immediately obvious that a number of processes, namely the first 22, were either started by init, PID 1, or became orphaned and became children of init. Also, the process mdrevovery is running at a very high priority (-20).

previous contents up next