Linux Processes Last Update Copyright Kenneth M. Chipps Ph.D. 1
Objectives of This Section Learn –What processes are in Linux –How to monitor processes Copyright Kenneth M. Chipps Ph.D. 2
Processes Each task that the kernel is working on is assigned a process id or PID Each process id has a parent process or PPID The parent of all processes is init or PID 1 Init is responsible for creating and managing processes Copyright Kenneth M. Chipps Ph.D. 3
Processes Recall that everything in Linux is a file Whether it is or it isn’t Most people think of a file as being something that is physically stored on a disk magnetically In Linux processes appear as files, but with a file length of zero Copyright Kenneth M. Chipps Ph.D. 4
Processes This is relevant in that processes running on a Linux system are monitored using these files Copyright Kenneth M. Chipps Ph.D. 5
File Locations These process pseudo files are stored in –/proc Under /proc are several directories also with zero length Each of these numerically named directories corresponds to the process IDs of a particular process running on the system Copyright Kenneth M. Chipps Ph.D. 6
File Locations Such as –PID –1 –2 –3 –4 –5 –6 –And so on Copyright Kenneth M. Chipps Ph.D. 7
File Locations The corresponding directories will look like this –dr-xr-xr-x 3 root root 0 Feb 17 17:26 1 –dr-xr-xr-x 3 root root 0 Feb 17 17:26 16 –dr-xr-xr-x 3 root root 0 Feb 17 17:26 2 –dr-xr-xr-x 3 root root 0 Feb 17 17:26 3 –dr-xr-xr-x 3 root root 0 Feb 17 17:26 4 –dr-xr-xr-x 3 root root 0 Feb 17 17:26 5 –dr-xr-xr-x 3 root root 0 Feb 17 17:26 6 –And so on Copyright Kenneth M. Chipps Ph.D. 8
File Locations Within these directories will be a list of files that show some information about the process the directory represents For example Copyright Kenneth M. Chipps Ph.D. 9
File Locations 9166]$ ls -l total 0 -r--r--r-- 1 shs shs 0 Feb 17 17:31 cmdline lrwxrwxrwx 1 shs shs 0 Feb 17 17:31 cwd -> /home/shs -r shs shs 0 Feb 17 17:31 environ lrwxrwxrwx 1 shs shs 0 Feb 17 17:31 exe - > /usr/bin/gnome-terminal dr-x shs shs 0 Feb 17 17:31 fd -r--r--r-- 1 shs shs 0 Feb 17 17:31 maps -rw shs shs 0 Feb 17 17:31 mem lrwxrwxrwx 1 shs shs 0 Feb 17 17:31 root -> / -r--r--r-- 1 shs shs 0 Feb 17 17:31 stat -r--r--r-- 1 shs shs 0 Feb 17 17:31 statm -r--r--r-- 1 shs shs 0 Feb 17 17:31 status Copyright Kenneth M. Chipps Ph.D. 10
Information on the Process Each of these files contains information on the process that the directory represents Using this information is not straight forward This is more a function that a developer might do, rather than a system administrator But it is there if you wish to look at it Copyright Kenneth M. Chipps Ph.D. 11
ps command This command produces a static list of the processes running at that instant In other words, it is a snapshot of what was running when the command was invoked To see a constantly updated list of running processes, use the top program Copyright Kenneth M. Chipps Ph.D. 12
ps command ps –ef –To display all processes with extended information ps ax –To list of current system processes, including processes owned by other users ps aux –Displays the owner of the processes along with the processes Copyright Kenneth M. Chipps Ph.D. 13
lsof Let’s say top shows an unusual program using a bunch of cpu resources ps shows the program’s command line name to be something that the find command cannot locate This may mean someone is running something that they are trying to hide In such a case lsof may be more useful Run it against the pid Copyright Kenneth M. Chipps Ph.D. 14
lsof As in –lsof –p The output of this command will show in the first column the real name of the program associated with the PID Checking the output produced may show what the program has been doing Copyright Kenneth M. Chipps Ph.D. 15
kill command Used to terminate a program from outside of the program To use it –At the command line search for the process causing the problem using grep Such as –ps ax | grep nameoftheprogram –This will show something like 7790 pts/1 S 1:25 /usr/lib/nameoftheprogram Copyright Kenneth M. Chipps Ph.D. 16
kill command –What is needed is the process number This is the number in the first column when the ps command is run this way In this case –7790 –Run kill 7790 If this doesn't do it, the parent process or PPID may need to be killed Copyright Kenneth M. Chipps Ph.D. 17
kill command To find it run –ps axl | grep nameoftheprogram When the ps command is run in this form, the PPID is the number in the fourth column Copyright Kenneth M. Chipps Ph.D. 18
killall command With this command all that is needed is the name of the program to be killed As in –killall httpd It does not work with PIDs Copyright Kenneth M. Chipps Ph.D. 19
top command The top command displays the currently running processes, as well as important information about them including their memory and CPU usage The list is both real-time and interactive Copyright Kenneth M. Chipps Ph.D. 20
top command Copyright Kenneth M. Chipps Ph.D. 21
Gnome System Monitor The Gnome GUI has a program similar to top –Main Menu Programs –System »System monitor Copyright Kenneth M. Chipps Ph.D. 22
Gnome System Monitor Copyright Kenneth M. Chipps Ph.D. 23