Test command

hello,
i'v trying to use the TEST command and i have some problems with it.
i am trying kill all proccess wich is greater than 25.
i started with - ps -f | grep -v TTY | awk '{print $4}'
but i dont know how to proceed from here..
10x a lot, Daniel.

Do you mean process ID's greater than 25 that started from a specific terminal?

cheers,
Devaraj Takhellambam

You try the following script.In that,I used ps ajx -U $USER which will list all the processes which are owned by the user.

for x in `ps ajx -U $USER |  grep -v "PID" | awk '{print $2}'`
do
if [[ $x -gt 25 ]]; then
echo "Process Id:$x"
kill -9 $x
fi
done

i just want to kill processes that takes more than 25% from the cpu without a script, in 1 command

So do u mean that from the top command's output which will list the process about their %CPU occupied level. In that you want to kill that process. Am I correct? Not the process Id greater than 25?

ps -eo "cpu : %C  pid :%p"  

this command can give the process id and cpu usage ,
extraction from top command would be a toughest task , since it prints
some terminal related characters

The syntax for "ps" varies, as does the output. Please post which Operating System you have.

Btw. When you have multiple CPUs the percentage from "ps" is a percentage of one CPU. Thus a single process could run at 100% CPU without having any adverse effect. The more CPUs you fit to the computer the more likely you are to see processes with a very high CPU percentage.

Detecting a looping process is a fine art and I don't think that a single snapshot of the CPU percentage is useful for deciding whether to kill a process. It is unlikely that you would come up with a single command line which would be safe to run in a commerical environment.

A perfectly sized and perfectly tuned computer would have everything running at 100% with no wait states.

exactly.. but i think it would be better to do it with ps

Loking more closely at your original post and guessing the version of "ps", I think you will find that column 4 of "ps -f" with heading "C" is not true CPU percentage. It is however a figure related to CPU usage and used for scheduling.

When the figure is rising towards 255, unix lowers the priority of the task to stop it hogging a CPU. The number in the "C" column then goes down until the machine is less busy whence unix then ups the priority again.

so.. is there any command that i can kill processes with, that are using more tan 25% of the CPU?

ps -efopid,pcpu |
while read pid cpu
do
  [ ${cpu%.*} -gt 25 ] && kill "$pid"
done

@dadiT
Please post which Operating System you have and the number of CPUs on you server.

Unless this is coursework it is not sensible to kill a process just because it has a high %cu usage.