確認環境
- CentOS 5.5
- cpulimit 1.1 (http://sourceforge.jp/projects/freshmeat_cpulimit/)
上記、URLから入手(詳細割愛)
コンパイル
(1) 解凍
[owner@localhost ~]$ tar zxvf cpulimit-1.1.tar.gz cpulimit-1.1/ cpulimit-1.1/Makefile cpulimit-1.1/cpulimit.c [owner@localhost ~]$ cd cpulimit-1.1(2) コンパイル
[owner@localhost cpulimit-1.1]$ make gcc -o cpulimit cpulimit.c -lrt -Wall -O2 [owner@localhost cpulimit-1.1]$インストール
インストール機能は付いてない。自分で好きな場所に移動が必要。
お試し
(1) ループシェルを作成
$ cat loop.sh #!/bin/sh while :; do :; done; $(2) ループを実施(制限なし)
$ sh ./loop.sh &
$ top
op - 18:54:11 up 14 days, 1:51, 1 user, load average: 0.36, 0.20, 0.15
Tasks: 221 total, 6 running, 213 sleeping, 0 stopped, 2 zombie
Cpu(s): 50.6%us, 0.7%sy, 0.0%ni, 48.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1927292k total, 1898348k used, 28944k free, 154448k buffers
Swap: 2097052k total, 126540k used, 1970512k free, 1115344k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3988 owner 25 0 63860 1076 928 R 99.7 0.1 0:10.63 sh
3989 owner 15 0 12844 1176 808 R 0.7 0.1 0:00.05 top
29602 owner 15 0 657m 127m 31m R 0.7 6.8 108:40.45 firefox
2757 root 34 19 0 0 0 R 0.3 0.0 75:20.93 kipmi0
2985 root 15 0 184m 3436 2168 S 0.3 0.2 4:30.63 amDaemon
3079 root 15 0 671m 48m 46m S 0.3 2.6 121:50.97 eecd
1 root 15 0 10352 596 564 S 0.0 0.0 0:01.39 init
2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:00.12 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/1
6 root 34 19 0 0 0 S 0.0 0.0 0:00.20 ksoftirqd/1
7 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1
8 root 10 -5 0 0 0 S 0.0 0.0 0:00.03 events/0
9 root 10 -5 0 0 0 S 0.0 0.0 0:00.02 events/1
10 root 10 -5 0 0 0 S 0.0 0.0 0:00.02 khelper
27 root 10 -5 0 0 0 S 0.0 0.0 0:00.01 kthread
(3) ループを実施(50%制限)$ sh loop.sh &
[1] 4077
$ ./cpulimit -l 50 -p 4077 &
[2] 4086
Process 4077 detected
Warning: cannot renice.
To work better you should run this program as root.
$ top
top - 19:00:09 up 14 days, 1:57, 1 user, load average: 0.87, 0.69, 0.40
Tasks: 222 total, 4 running, 216 sleeping, 0 stopped, 2 zombie
Cpu(s): 26.2%us, 0.8%sy, 0.0%ni, 72.5%id, 0.5%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1927292k total, 1900624k used, 26668k free, 154556k buffers
Swap: 2097052k total, 126540k used, 1970512k free, 1116004k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4077 owner 15 0 63860 1080 928 R 50.5 0.1 2:09.78 sh
2757 root 34 19 0 0 0 R 1.0 0.0 75:22.33 kipmi0
29661 owner 15 0 99072 29m 13m S 0.7 1.5 21:37.42 npviewer.bin
3728 owner 15 0 70528 1776 1304 S 0.3 0.1 0:00.16 bash
29211 owner 15 0 60012 19m 5652 S 0.3 1.0 42:04.71 Xvnc
1 root 15 0 10352 596 564 S 0.0 0.0 0:01.39 init
2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:00.12 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/1
6 root 34 19 0 0 0 S 0.0 0.0 0:00.20 ksoftirqd/1
7 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1
8 root 10 -5 0 0 0 S 0.0 0.0 0:00.03 events/0
9 root 10 -5 0 0 0 S 0.0 0.0 0:00.02 events/1
10 root 10 -5 0 0 0 S 0.0 0.0 0:00.02 khelper
27 root 10 -5 0 0 0 S 0.0 0.0 0:00.01 kthread
32 root 10 -5 0 0 0 S 0.0 0.0 0:00.04 kblockd/0
(3) ループ実施(10%制限)$ ./cpulimit -l 10 -p 4077 &
[2] 4201
Process 4077 detected
Warning: cannot renice.
To work better you should run this program as root.
$ top
top - 19:03:45 up 14 days, 2:01, 1 user, load average: 2.45, 1.38, 0.71
Tasks: 222 total, 1 running, 218 sleeping, 1 stopped, 2 zombie
Cpu(s): 5.8%us, 0.3%sy, 0.0%ni, 93.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1927292k total, 1900904k used, 26388k free, 154672k buffers
Swap: 2097052k total, 126540k used, 1970512k free, 1116448k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4077 owner 15 0 63860 1080 928 T 10.6 0.1 3:59.60 sh
4222 owner 15 0 12844 1172 808 R 0.3 0.1 0:00.06 top
29211 owner 15 0 60012 19m 5652 S 0.3 1.0 42:09.18 Xvnc
29661 owner 15 0 99072 29m 13m S 0.3 1.5 21:40.00 npviewer.bin
1 root 15 0 10352 596 564 S 0.0 0.0 0:01.39 init
2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:00.12 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/1
6 root 34 19 0 0 0 S 0.0 0.0 0:00.20 ksoftirqd/1
7 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1
8 root 10 -5 0 0 0 S 0.0 0.0 0:00.03 events/0
9 root 10 -5 0 0 0 S 0.0 0.0 0:00.02 events/1
10 root 10 -5 0 0 0 S 0.0 0.0 0:00.02 khelper
27 root 10 -5 0 0 0 S 0.0 0.0 0:00.01 kthread
32 root 10 -5 0 0 0 S 0.0 0.0 0:00.04 kblockd/0
33 root 10 -5 0 0 0 S 0.0 0.0 0:00.47 kblockd/1
備考参考
以上
0 件のコメント:
コメントを投稿