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
# 8  
Old 11-20-2012
The OPs statement "as part of a bigger script" concerns me here.

Typically it is quite unlikley for a script process to use a large amount of CPU in it's own right. More than likley a child process of the script (like grep, find, mysql, etc) will actually consume the CPU.

Also note that using a large % of the CPU isn't a bad thing, if there is work to be done and free cycles available they should be used for the job. Consider using "nice" to give the process less priority or enforcing a maximum runtime rather than CPU watching.
This User Gave Thanks to Chubler_XL For This Post:
# 9  
Old 11-21-2012
I basically want to see if the process is idle if it is then perform an action.

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

returns the cpu, not sure how to then see if that result is higher

Is this correct

Code:
if [ps -p $(pgrep 'xbmc\.bin') -o pcpu= | awk 'NR>1' ) -gt 12 ]
then

When I re run ps -p $(pgrep 'xbmc\.bin') -o pcpu= it seems to reutrn the same figure as before.
# 10  
Old 11-26-2012
How about checking if process isn't in the running (R) state:

Code:
if [ $( ps -f $(pgrep 'xbmc\.bin') -o state= ) != "R" ]
then

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