Wednesday March 28, 2007
Using ps
The process is the heart of the UNIX
system. It is a program in operation and is identified by its unique process id (PID). The common command to list process information is ps. There are 2 flavors of ps, /usr/bin/ps (from SVR4 ) and /usr/ucb/ps (from BSD). The following is valid only for /usr/bin/ps.
$ ps -ef
prints information about every process(-e) that is running with full (-f) details.
Here is a brief description of the
output columns for ps :
Column 1 : User id(UID)
Column 2 : Unique process id for the process(PID)
Column 3: Parent Id for the process(PPID)
Column 4: C - According to the man pages, it is "Processor utilization for scheduling(obsolete)". This represents the CPU utilization factor.
Column 5 : Start time of the process in hours,minutes and seconds(STIME)
Column 6 :The controlling terminal for the process ; ? is printed when there is no controlling terminal(TTY).
Column 7 : Time consumed by CPU for the process. If this number is high,it may mean that the process is hogging the CPU (TIME).
Column 8 : The command name that initiated the process.(CMD).
Here are some examples of ps :
$ ps -ef | grep <uid>
prints all processes for userid
You can send (redirect) the output of ps (or any other command) to a file by typing
$ ps -ef | grep userid > filename
To append the output to a file, type
$ ps -ef | grep username >> filename
To find the process ids of all users running
firefox, for example, type
$ ps -ef | grep -i firefox | awk '{print $2}'
where $2 refers to the PID (2nd column) in the output for ps.
To print the pid of a particular user running firefox, type
$ ps -ef | grep userid | grep -i firefox | awk '{print $2}'
You can also specify the arguments to be outputted with the -o option. This example prints the user id,process id,percentage of recent CPU usage and the command that initiated the process for a particular user.
$ ps -eo user,pid,pcpu,comm | grep userid
You can find more examples on using ps on Sun's BigAdmin website here .
Posted at 02:56PM Mar 28, 2007 by Jyothi Srinath in Sun | Comments[2]
Today's Page Hits: 64