Operating System - HP-UX
1753468 Members
4712 Online
108794 Solutions
New Discussion юеВ

How to detect Process wit high cpu during n seconds

 
SOLVED
Go to solution
Leo The Cat
Regular Advisor

How to detect Process wit high cpu during n seconds

Hi

I'd like to find and kill systematically all processes with cpu > 80% during 60 seconds. Is it possible ?

Bests Regards
Den
7 REPLIES 7
Johnson Punniyalingam
Honored Contributor

Re: How to detect Process wit high cpu during n seconds

>>>I'd like to find and kill systematically all processes with cpu > 80% during 60 seconds. Is it possible ?<<<

Yes, its possible,

But.... later you may end-up in killing the system important processes with cpu > 80%

well , your goal should find out which process uses more cpu usage, than dig in to the issue , deeper

Thanks,
Johnson
Problems are common to all, but attitude makes the difference
Leo The Cat
Regular Advisor

Re: How to detect Process wit high cpu during n seconds

Hi

My need is to kill one process over 80% if this process take that during n secondes. It's my request and investigation is not here the purpose.

Regards
Den
OldSchool
Honored Contributor

Re: How to detect Process wit high cpu during n seconds

"....later you may end-up in killing the system important processes with cpu > 80%"

are you looking to kill processes which have been > 80% for more than 60 seconds, or processes > 80% within a 60 second period?

in either case, unintended results are likely, which could render the system unusable without a reboot.

this is a *very* *bad* idea
Leo The Cat
Regular Advisor

Re: How to detect Process wit high cpu during n seconds

Hi OldSchool !

"....
are you looking to kill processes which have been > 80% for more than 60 seconds, or processes > 80% within a 60 second period?
..."

To be exact, 80% cpu usage more than 60 seconds.

But I could do script and crontab (every 5 minutes) doing this:
Find a process over 80%
if no => END.
if yes=> start a 60 seconds loop with a check at every 5 seconds. if all checks within this loop are positives (The same process always over 80%)I could kill it.


Bests regards
Den
Leo The Cat
Regular Advisor

Re: How to detect Process wit high cpu during n seconds

Small precision. The owner of this process is not unknow ... ! So my target is an applicative process and not a system process ! ;-)of course !

Den.
TTr
Honored Contributor
Solution

Re: How to detect Process wit high cpu during n seconds

You can run the top command for a few seconds and examine its output. As in "top -s XX -d 2". You can check the output of the top command with a script and look at the %CPU columns and extract the PID etc.
I guess you are aware to be selective about which process to kill based on user owner etc.
Leo The Cat
Regular Advisor

Re: How to detect Process wit high cpu during n seconds

The TTr's post give us a good clue.

Bests Regards
Den.