Process Information
Definition : A process is a program that is executed (or currently running on the computer). It reside in the memory (RAM) of the computer. Every process is unique and is identified by a Process Number called PID. The PID is a random number starting from 0 to 65534. Also, a process has various period of execution. (Eg, sleeping)
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.
Foreground and Background
When you run a specific command, usually that command is in the foreground and it's using the computer until it is finished. For example, if you want to run other commands rather than wait for the program to finish, you can type CTRL+Z to put it in the background. To stop a running application (from the foreground) you usually have to type CTRL+C.
Once an application is put into the background, it can be brought to the foreground using the fg command.It is possible to launch a program directly into the background by using an amperstand (&).To do this you should look at the example below :
root@linuxedu:~# updatedb & [1] 5467
This means that the program has been started, the PID of the program is 5467 and it was launched in the background.
The ps(1) and top(1) commands
There are two useful commands to see the processes on a system, ps(1) and top(1). The ps command shows a static list of the running processes on the system.It shows you the PID, the amount of memory a process is 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 second so that you can easily observe what your system is doing.
By default, ps outputs only the processes that you own. For example:
tress@linuxedu:~$ ps PID TTY TIME CMD 5632 pts/1 00:00:00 bash 5782 pts/1 00:00:00 ps
The output of ps, as you can see from the example, is organised into a number of columns.:
- PID is the process ID discussed earlier.
- TT shows the tty the program is running on.
- STAT shows the status of the process.
- TIME shows the amount of time the program has been running on the CPU.
- CMD is the command line used to start the program.
ps(1) has a number of different options to change the information that is displayed. One of the most useful combinations is auxww :
- a displays all the running programs, not just yours.
- u displays the memory usage and the username of the process owner.
- x displays information about daemon processes
- ww causes ps(1) to display the full command line used to start a specific program.
The output of the top command is quite similar.
tress@linxuedu:~$ top 18:25:39 up 128 days, 2:17, 2 users, load average: 1.75, 1.29, 1.11 71 processes: 68 sleeping, 2 running, 0 zombie, 0 stopped CPU states: 98.0% user, 2.0% system, 0.0% nice, 0.0% idle Mem: 125508K total, 121836K used, 3672K free, 4736K buffers Swap: 240932K total, 0K used, 240932K free, 47728K cached PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 543 nobody 9 0 19596 19M 1304 S 1.1 15.6 60:38 squid 1 root 8 0 512 512 456 S 0.0 0.4 0:09 init 2 root 9 0 0 0 0 SW 0.0 0.0 0:00 keventd 3 root 19 19 0 0 0 SWN 0.0 0.0 0:00 ksoftirqd_CPU0 4 root 9 0 0 0 0 SW 0.0 0.0 0:03 kswapd 5 root 9 0 0 0 0 SW 0.0 0.0 0:00 bdflush 6 root 9 0 0 0 0 SW 0.0 0.0 0:00 kupdated 143 daemon 9 0 540 540 464 S 0.0 0.4 0:00 portmap 540 root 9 0 1084 1084 916 S 0.0 0.8 0:00 squid 554 nobody 9 0 312 308 260 S 0.0 0.2 0:13 unlinkd 599 root 9 0 612 612 516 S 0.0 0.4 0:06 syslogd 651 root 9 0 1320 1320 448 S 0.0 1.0 0:01 klogd 688 root 9 0 2840 2836 1864 S 0.0 2.2 0:00 named 1018 amavis 9 0 556 552 460 S 0.0 0.4 0:00 amavis-milter 1021 root 9 0 700 700 616 S 0.0 0.5 0:00 rpc.statd 1029 root 9 0 460 460 404 S 0.0 0.3 0:00 courierlogger 705 root 8 0 2260 2256 1672 S 0.0 1.7 0:00 lwresd 713 root 9 0 2260 2256 1672 S 0.0 1.7 0:00 lwresd
As you can see, the output of the top command is split into two sections. The header (first 5 lines) shows the PID of the last process to run, the system load averages (shows you the measure of how busy is the system), the system uptime (time since last reboot) and the current time. The other figures in the header relate to how many processes are running (71 in our case), how much memory and swap is taken, and how much time the system is spending in different CPU states.
The second section of the output is very similar to the ps command output.However it shows you the amount of memory used by a program, and also the amount of needed memory for a specific process.
