Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

i was wondering about something like CPUlimit to limit the process CPU usage but i am aiming to apply the same percentage of usage for its children processes too automatically without adding them manually in Terminal by hand , so Is there something Limits the CPU usage for a process and its Children whether there is or there is not another process needs the resources for the same time the first one uses it ? cgroup cpu.shares limits only when there is another process need the consumed resources by a previous process , what i am to is something like sudo cpulimit -p 1234 -l 20 so the limit here of cpu usage doesnt consider if there is another process or not demanding the used resources they apply it regardless of anything but my problem is that it applied on the parent process pid =1234 but its children no , so any suggestion pls ? i hope i explained my issue abundantly clear Thanks in advance .

share|improve this question
1  
Have a look at this: Cpulimit –  M.Meintjes Apr 29 '13 at 13:36
    
yes thank u , i read it ,but excuse me ı didnt get what ıs the new thing u want to tell me , i am beginner –  Ahmed Zain El Dein Apr 29 '13 at 13:44
    
I'm not sure but if you look at pstree -p you can see the processes in a tree kind of way... now if you take the first PID and limit the cpu the "children PIDs" should automatically take over the cpu limit? But as mentioned i'm not sure. –  M.Meintjes Apr 29 '13 at 13:46
1  
Well I didn't read your post thoroughly... I search a bit and found this LINK. Hope this helps :) –  M.Meintjes Apr 29 '13 at 13:51
1  
Easily Change ‘CPU Affinity’ in Ubuntu using ‘procexp’ hecticgeek.com/2013/03/change-cpu-affinity-ubuntu-procexp –  Qasim Apr 29 '13 at 14:23

1 Answer 1

up vote 1 down vote accepted

This link may help Set maximum CPU consumption in percentage by any process searched by : MrSeed

this script may help too , any any one wants to enter suggestions on this script to enhance it , it will be my pleasure

       #!/bin/bash -xv

read -p "Which program u want to limit its processes?" ProgrameName
read -p "Which limitation percentage u want for it ?" limitationPercentage  
read -p "Period to be sleep " sleepInterval 
dataFile="/home/ahmedubuntu/Desktop/.file.txt"
separator="######"
trap "echo \"\" > $dataFile"  SIGINT SIGTERM SIGHUP
########################################################
if [ -e $dataFile ]; then
  echo "File $dataFile already exists!"
  echo -e "" > $dataFile
else
  echo >> $dataFile
fi 
echo -e "$ProgrameName \n $limitationPercentage \n" >> $dataFile
getAllPIDRunUnderThisProgram=$( ps -e | grep "$ProgrameName" | awk '{print $1;}')
echo -e "${getAllPIDRunUnderThisProgram[@]}  \n $separator \n" >> $dataFile
for i in $getAllPIDRunUnderThisProgram
   do
    gnomeTab+=( --tab -e "cpulimit -p $i -l $limitationPercentage ")  
   done
gnome-terminal "${gnomeTab[@]}"
#echo gnome-terminal "${gnomeTab[@]}"
########################################################
while sleep $sleepInterval
do
i=0
while read line
do
if [ -n "$line" ] && ["$line" != "separator"] 
then
programeNameAndPID[i]=$line
((i++))
elif [["$line" == "separator"]] ; then
getAllPIDRunUnderThisProgram=$( ps -e | grep "$programeNameAndPID[0]" | awk '{print $1;}')
if [${#getAllPIDRunUnderThisProgram[*]} -gt ${#programeNameAndPID[*]}-2  ]
then
unset gnomeTab
newProcessNumber=${#getAllPIDRunUnderThisProgram[*]}-${#programeNameAndPID[*]}-2
index=${#getAllPIDRunUnderThisProgram[*]}-1
for (( c=$newProcessNumber ; c > 0 ; c-- ))
do
gnomeTab+=( --tab -e "cpulimit -p $getAllPIDRunUnderThisProgram[$index] -l $programeNameAndPID[1] ") 
((index--)) 
done
gnome-terminal "${gnomeTab[@]}"
fi
i=0
unset programeNameAndPID
fi
done < $dataFile
done

and by adding nice -10 will work well with no need to sudo and password

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.