ในกรณีที่ไม่มีรายละเอียดที่ร้องขอ ...
นี่คือวิธีที่ฉันใช้ cgroups บน ubuntu
ตลอดโพสต์นี้คุณจะต้องเปลี่ยนตัวแปร "$ USER" เป็นผู้ใช้ที่ดำเนินการ
ฉันเพิ่มข้อมูลสำหรับหน่วยความจำเช่นเดียวกับที่จะเป็นคำถามที่พบบ่อยถ้าคุณไม่ต้องการมันไม่ได้ใช้มัน
1) ติดตั้ง cgroup-bin
sudo apt-get install cgroup-bin
2) รีบูต cgroups ตั้งอยู่ที่/sys/fs/cgroup
3) สร้าง cgroup สำหรับผู้ใช้ของคุณ (เจ้าของกระบวนการ)
# Change $USER to the system user running your process.
sudo cgcreate -a $USER -g memory,cpu:$USER
4) ผู้ใช้ของคุณสามารถจัดการทรัพยากรได้ ตามค่าเริ่มต้นผู้ใช้จะได้รับ 1024 cpu units (แชร์) ดังนั้นเพื่อ จำกัด ประมาณ 10% cpu หน่วยความจำมีหน่วยเป็นไบต์ ...
# About 10 % cpu
echo 100 > /cgroup/cpu/$USER/cpu.shares
# 10 Mb
echo 10000000 > /cgroup/memory/$USER/memory.limit_in_bytes
5) เริ่มกระบวนการของคุณ (เปลี่ยน exec เป็น cgexec)
# -g specifies the control group to run the process in
# Limit cpu
cgexec -g cpu:$USER command <options> &
# Limit cpu and memory
cgexec -g memory,cpu:$USER command <options> &
องค์ประกอบ
สมมติว่ากลุ่ม cg เหมาะกับคุณ;)
แก้ไข/etc/cgconfig.conf
เพิ่มใน cgroup ที่คุณกำหนดเอง
# Graphical
gksudo gedit /etc/cgconfig.conf
# Command line
sudo -e /etc/cgconfig.conf
เพิ่มใน cgroup ของคุณ เปลี่ยน $ USER เป็นชื่อผู้ใช้ที่เป็นเจ้าของกระบวนการอีกครั้ง
group $USER {
# Specify which users can admin (set limits) the group
perm {
admin {
uid = $USER;
}
# Specify which users can add tasks to this group
task {
uid = $USER;
}
}
# Set the cpu and memory limits for this group
cpu {
cpu.shares = 100;
}
memory {
memory.limit_in_bytes = 10000000;
}
}
นอกจากนี้คุณยังสามารถระบุกลุ่มgid=$GROUP
/etc/cgconfig.conf มีความคิดเห็นดี
ตอนนี้เรียกใช้กระบวนการของคุณอีกครั้งด้วย cgexec -g cpu:$USER command <options>
คุณสามารถดูกระบวนการของคุณ (โดย PID) ใน /sys/fs/cgroup/cpu/$USER/tasks
ตัวอย่าง
bodhi @ ufbt: ~ $ cgexec -g cpu: bodhi sleep 100 &
[1] 1499
bodhi @ ufbt: ~ $ cat / sys / fs / cgroup / cpu / bodhi / งาน
1499
สำหรับข้อมูลเพิ่มเติมโปรดดูที่:
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/