23
Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 1

Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D. 1

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

LinuxProcesses

Last Update 2012.08.241.3.0

Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

1

Page 2: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

Objectives of This Section

• Learn– What processes are in Linux– How to monitor processes

Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

2

Page 3: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

3

Page 4: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

4

Page 5: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

Processes

• This is relevant in that processes running on a Linux system are monitored using these files

Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

5

Page 6: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

6

Page 7: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

File Locations

• Such as– PID– 1– 2– 3– 4– 5– 6– And so on

Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

7

Page 8: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

8

Page 9: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

File Locations

• Within these directories will be a list of files that show some information about the process the directory represents

• For example

Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

9

Page 10: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

File Locations• [shs@dragonfly 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-------- 1 shs shs 0 Feb 17 17:31 environ• lrwxrwxrwx 1 shs shs 0 Feb 17 17:31 exe - > /usr/bin/gnome-terminal• dr-x------ 2 shs shs 0 Feb 17 17:31 fd• -r--r--r-- 1 shs shs 0 Feb 17 17:31 maps• -rw------- 1 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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

10

Page 11: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

11

Page 12: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

12

Page 13: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 processesCopyright 2000-2012 Kenneth M. Chipps Ph.D.

www.chipps.com13

Page 14: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

14

Page 15: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

lsof• As in

– lsof –p 24061• 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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

15

Page 16: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

16

Page 17: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

17

Page 18: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

18

Page 19: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

19

Page 20: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

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 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

20

Page 21: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

top command

Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

21

Page 22: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

Gnome System Monitor

• The Gnome GUI has a program similar to top– Main Menu

• Programs– System

» System monitor

Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

22

Page 23: Linux Processes Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.   1

Gnome System Monitor

Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

23