If a process cpu % is higer than


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If a process cpu % is higer than
# 1  
Old 11-20-2012
If a process cpu % is higer than

Is this possible as part of a bigger script to do?

eg:

elif
myprocess.bin cpu% > 12
exit 1
elif

is there a command for this?

thanks
# 2  
Old 11-20-2012
Code:
if [ $( UNIX95= ps -p <PID> -o pcpu | awk 'NR>1' ) -gt 12 ]
then
     # perform action
fi

Code:
# uname
HP-UX

# 3  
Old 11-20-2012
so..
Code:
if [ $( UNIX95= ps -p <xbmc.bin> -o pcpu | awk 'NR>1' ) -gt 12 ]
then
     echo greater than 12
fi

I get:
Code:
/home/billy/bin/cpu.sh: line 1: xbmc.bin: No such file or directory
/home/billy/bin/cpu.sh: line 1: [: -gt: unary operator expected

this is on Ubuntu

Last edited by Franklin52; 11-21-2012 at 03:22 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 11-20-2012
You have to pass the Process ID as argument instead of Process Name.

If xbmc.bin is the process which you want to monitor, then you have to get the Process ID of xbmc.bin and pass it without wrapping it inside < >.
# 5  
Old 11-20-2012
Code:
if [ $( xbmc.bin= ps -p <PID> -o pcpu | awk 'NR>1' ) -gt 12 ]
then
     echo perform
fi

or I need prgep involved?

Last edited by Franklin52; 11-21-2012 at 03:22 AM.. Reason: Please use code tags for data and code samples
# 6  
Old 11-20-2012
UNIX95 is a variable which changes the behavior of ps command, so don't change it.

Follow below steps:-

1. Get the process id of xbmc.bin:-
Code:
ps -eaf | awk '/xbmc.bin/ { print $2 } '

2. Replace below highlighted with process id:-
Code:
UNIX95= ps -p PID -o pcpu | awk 'NR>1'

# 7  
Old 11-20-2012
The simplest way to generate the %CPU, for Ubuntu (procps-derived implementations in general):
Code:
ps -C xbmc.bin -o pcpu=

A more portable approach:
Code:
ps -p $(pgrep 'xbmc\.bin') -o pcpu=

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Process going to 100% CPU

I have a httpd process which uses up 100% cpu. This makes my application to stop working and it just gets hung. I tried getting the tusc output looks something like this: # /usr/local/bin/tusc -pl 26516 ( Attached to process 26516 ("/opt/hpws22/apache/bin/httpd -d /opt/hpws22/apache -k... (3 Replies)
Discussion started by: chacko193
3 Replies

2. Emergency UNIX and Linux Support

CPU and memory utilization of a process, by process name

Can someone please help me with a script that will help in identifying the CPU & memory usage by a process name, rather than a process id.This is to primarily analyze the consumption of resources, for performance tweaking. G (4 Replies)
Discussion started by: ggayathri
4 Replies

3. Solaris

process CPU time

We are using JAVA program and strange thing is it takes 100% CPU when not in use. The program function is to stream a file on output port (one direction). It checks one directory and when there is a file in it, starts. While it is streaming the CPU usage is normal, about 20%. But, if... (9 Replies)
Discussion started by: orange47
9 Replies

4. Red Hat

Process by CPU

Hello All, I am preparing a script to capture the processes consuming more CPU. So is there any way that i can sort & redirect to file only those processes consuming more than 5.0 % using ps command itself. Regards Ankit (3 Replies)
Discussion started by: ajaincv
3 Replies

5. Shell Programming and Scripting

Capturing the CPU% used by a process

Hi, I just wonder I need to write a script where I can check if a particular process is consuming X amount of CPU. I was thinking of using the ps command but doesn't seems to work. Any ideas. Thanks. (2 Replies)
Discussion started by: arizah
2 Replies

6. Shell Programming and Scripting

CPU Usage for a particular process

Hi, I have a shell script. But, upon execution of the same, the cpu usage is sometimes getting 100 % (checked executing top command). At that point of time, my process hangs, doesn't run anymore. I need to kill it manually. My concern is, is there any default method, by which I can check... (1 Reply)
Discussion started by: jitendriya.dash
1 Replies

7. UNIX for Dummies Questions & Answers

how to get persistant cpu utilization values per process per cpu in linux (! top,ps)

hi, i want to know cpu utilizatiion per process per cpu..for single processor also if multicore in linux ..to use these values in shell script to kill processes exceeding cpu utilization.ps (pcpu) command does not give exact values..top does not give persistant values..psstat,vmstat..does njot... (3 Replies)
Discussion started by: pankajd
3 Replies

8. AIX

cpu utilization of a process

Hi, How can i find out the average cpu utilization of a particular long-running process in AIX? is there some command for this Thanks (2 Replies)
Discussion started by: iam
2 Replies

9. UNIX for Dummies Questions & Answers

process not using enough cpu

I am running solaris 9 on a SUn 480r. It is running SAS statistical software, these processes in full flow normally run at about 50-60% cpu (theres nothing else really running on the box) this is fine, and the SAS jobs get run nice and quick. However over the last few weeks everytime a SAS job is... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

10. UNIX for Advanced & Expert Users

process -> 1 cpu

Is there a way I can assign processes to different processors? I know in windows xp you can set process affinity, and wondered if there is a *nix equivelant. (2 Replies)
Discussion started by: Solitare
2 Replies
Login or Register to Ask a Question