Introducing UNIX and Linux |
Processes and devicesOverview |
Process statusWithin a UNIX system there are one or more processing elements (which we will refer to as processors) that can only run a single process at any one time. At any instant, that process can be described completely by a sequence of bytes - some representing the memory contained within the processor, some describing the precise current state of the computation. It is possible to copy these bytes to memory, and replace them by a sequence of bytes from elsewhere in memory. Thus a partially completed process can be temporarily suspended (or stopped), and completed at a later time, and in the meantime another process can be run on that processor. The kernel manages a large 'pool' of processes, most of which are not running at any specific instant, and moves them to and from the processor (or processors) as required. Much of this movement is automatic and hidden from users - for instance, when there are several users on the machine each with a program which is running, the relevant processes are moved in and out of the processor so that each is allocated a fair percentage of the time (this is known as time-sharing). However, users do have a certain degree of control over their own processes. A process can be in a number of states, normally either running (currently being worked on by a processor), or stopped (not being processed, but available to continue evaluation when instructed). When a process completes its execution; it is removed from the system entirely and killed. Not all processes will have been invoked by a user - some are so-called system processes, and are constantly running while the system is operational. When you initially log in, you invoke a program that is a copy of the shell, and known as your login shell. This program forms a process which must be present during the whole time you are logged in. Any subsequent process that is created by you is controlled from the terminal (or window) in which you were typing the command that created it. If you type in a command to a shell, it can be of two possible types. Either it is a 'built-in' shell command, which is interpreted by the shell process directly, or a new process is created for it. In the latter case the binary code for it is copied from storage, and forms the process to execute that command. The process that is the current shell is suspended and the process for the new command is run. After that process has finished running, it is destroyed, and the shell process is resumed. You can find out which processes you have, either running or
stopped, by means of the command
Note that all time when a process has been suspended, or has otherwise been moved out of any processor, is excluded from the figures. Each process is given a unique identification number, its
process-id or PID, which is
indicated in the first column of the output from ps. The second
column displays the name of the terminal from which that process is
being controlled (normally your own terminal or one of your
windows). The column headed Another very useful utility is 5:21pm up 1 day, 23:02, 2 users, load av: 1.00, 1.00, 1.00 150 processes: 146 sleeping, 1 running, 3 zombie, 0 stopped CPU states: 0.1% user, 0.7% system, 0.0% nice, 99.0% idle Mem: 128808K av, 120728K used, 8080K free, 37432K buff Swap: 152248K av, 9812K used, 142436K free 618980K cached PID USER PRI NI SIZE RSS STAT %CPU %MEM TIME COMMAND 10545 sam 16 0 249M 106M R 24.2 17.1 18.5H gen 14250 chris 9 0 92 80 S 23.4 11.0 74.3H S5Ba 14271 chris 9 0 0 0 SW 23.5 11.0 74.4H S5Bb 28095 sam 9 0 0 0 SW 0.7 0.1 0:00 wget 25716 root 19 19 0 0 SWN 0.0 0.0 0:00 init 11 root 9 0 0 0 SW 0.0 0.0 0:00 khubd 372 root 9 0 676 640 S 0.0 0.0 0:00 dhcpcd 631 root 9 0 892 852 S 0.0 0.0 0:00 sshd 646 root 9 0 692 688 S 0.0 0.0 0:00 syslogd 649 root 9 0 1056 1048 S 0.0 0.1 0:00 klogd |
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck