Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TOP

Status
Not open for further replies.

porsche

Technical User
Jun 15, 2000
2
0
0
IE
Hi<br><br>I am having a problem whereby, I am using 'top' to search for a process that is going haywire intermittently and eating up CPU.Is there a way of checking CPU usage of an individual process and if it is above a certain level - either killing it off or notifying me by email.<br>would be grateful for any help received<br><br><br>John
 
After reading the ps man page in XPG4 there is a -o option for the command. So if you are running XPG4 OS then you might use:<br><FONT FACE=monospace><br>ps -p process_id -o pcpu=&quot;%CPU&quot; &gt; results<br></font><br>That should give you the process details with a column called %CPU which is just that. You could then write a script to check this value and issue a kill if the % goes above a threshold. <br><br>Unfortunately we are not using an XPG4 compliant version of HPUX. There are some though aren't there?!<br><br>Hope that helps a bit<br>Loon
 
Here's a script we use at out site for identifying &quot;haywire&quot; processes.&nbsp;&nbsp;It's written for a Solaris 2.x based system, so you may need to tweak it for HP-UX.<br><FONT FACE=monospace><br>#!/bin/sh<br>#<br># Show processes with greater than 0.99% processor usage.<br><br># Weed out processes with 0.xx% processor usage.<br>PS='ps -ef -o user -o pid -o pcpu -o ppid -o comm ¦ egrep -v &quot; 0\.0¦[0-9]&nbsp;&nbsp;0\.&quot;'<br><br>if [ &quot;X$1&quot; = &quot;X-r&quot; ]<br>then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Refresh option selected.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while true<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ps -ef -o user -o pid -o pcpu -o tty -o ppid -o comm ¦ egrep -v <br>&quot; 0\.0¦[0-9]&nbsp;&nbsp;0\.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# ${PS}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep 5<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;done<br>else<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Weed out processes with 0.xx% processor usage.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ps -ef -o user -o pid -o pcpu -o tty -o ppid -o comm ¦ egrep -v &quot; 0\.0¦[<br>0-9]&nbsp;&nbsp;0\.&quot;<br>fi<br></font><br><br>If you run the script with a &quot;-r&quot; argument, it will keep repeating at 5 second intervals until you press ^C to interrupt it.&nbsp;&nbsp;(Or whatever your interrupt key is.)<br><br>Hope it helps. <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
 
To use the XPG4 flags on ps, all you need to do is export the UNIX95 variable. For example:<br><br>export UNIX95=1; ps -p &lt;pid&gt; -o pcpu . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top