よくわからないエンジニア

よく分からないエンジニア(無音鈴鹿)の日々の記録

よくわからないエンジニア

Linuxのリソース関連(free)

引き続き勉強中。LPIC level2一発合格に向けてのリソース関連コマンドの学習内容晒しです。

freeコマンド(CentOS6系)

本日はfreeコマンドです。普段あんまり使っていないので、とりあえずオプションなしとhelpを参照。

# free
             total       used       free     shared    buffers     cached
Mem:       1921992    1808780     113212        436     200036    1349192
-/+ buffers/cache:     259552    1662440
Swap:      1048572       4632    1043940
# free --help
free: invalid option -- '-'
usage: free [-b|-k|-m|-g|-h] [-l] [-o] [-t] [-s delay] [-c count] [-V]
  -b,-k,-m,-g show output in bytes, KB, MB, or GB
  -h human readable output (automatic unit scaling)
  -l show detailed low and high memory statistics
  -o use old format (no -/+buffers/cache line)
  -t display total for RAM + swap
  -s update every [delay] seconds
  -c update [count] times
  -a show available memory if exported by kernel (>80 characters per line)
  -V display version information and exit

sharedの項目はなんだろう。。

-b,-k,-m,-hオプション

こちらは左から順にバイト,キロ,メガの単位をつけて見やすくするオプションです。-hは見やすい形に勝手に変換してくれます。

# free -b
             total       used       free     shared    buffers     cached
Mem:    1968119808 1852157952  115961856     446464  204836864 1381576704
-/+ buffers/cache:  265744384 1702375424
Swap:   1073737728    4743168 1068994560
# free -k
             total       used       free     shared    buffers     cached
Mem:       1921992    1808748     113244        436     200036    1349196
-/+ buffers/cache:     259516    1662476
Swap:      1048572       4632    1043940
# free -m
             total       used       free     shared    buffers     cached
Mem:          1876       1766        110          0        195       1317
-/+ buffers/cache:        253       1623
Swap:         1023          4       1019
# free -h
             total       used       free     shared    buffers     cached
Mem:          1.8G       1.7G       110M       436K       195M       1.3G
-/+ buffers/cache:       253M       1.6G
Swap:         1.0G       4.5M       1.0G

特に面白くないので、次に行きます。

-tオプション

RAMとswapを合算したTotal行を付け加えてくれます。

# free -t
             total       used       free     shared    buffers     cached
Mem:       1921992    1808640     113352        436     200036    1349196
-/+ buffers/cache:     259408    1662584
Swap:      1048572       4632    1043940
Total:     2970564    1813272    1157292

-s,-cオプション

“-s 数字"で指定した数字秒で更新してくれます。-cオプションは回数指定です。

# free -s 5 -c 3
             total       used       free     shared    buffers     cached
Mem:       1921992    1808764     113228        436     200036    1349196
-/+ buffers/cache:     259532    1662460
Swap:      1048572       4632    1043940

             total       used       free     shared    buffers     cached
Mem:       1921992    1808780     113212        436     200036    1349196
-/+ buffers/cache:     259548    1662444
Swap:      1048572       4632    1043940

             total       used       free     shared    buffers     cached
Mem:       1921992    1808680     113312        436     200036    1349196
-/+ buffers/cache:     259448    1662544
Swap:      1048572       4632    1043940

オプションつけてコマンド実行しただけなので、今回つまらんなぁと思っていたら、なんと7系からはfreeの出力が変わったらしい。

free(CentOS7系)

早速、7系でもコマンドを実施してみる。

# free
              total        used        free      shared  buff/cache   available
Mem:        1883996      163356       94496       25124     1626144     1470172
Swap:       1048572           0     1048572
# free --help

Usage:
 free [options]

Options:
 -b, --bytes         show output in bytes
 -k, --kilo          show output in kilobytes
 -m, --mega          show output in megabytes
 -g, --giga          show output in gigabytes
     --tera          show output in terabytes
 -h, --human         show human-readable output
     --si            use powers of 1000 not 1024
 -l, --lohi          show detailed low and high memory statistics
 -t, --total         show total for RAM + swap
 -s N, --seconds N   repeat printing every N seconds
 -c N, --count N     repeat printing N times, then exit
 -w, --wide          wide output

     --help     display this help and exit
 -V, --version  output version information and exit

For more details see free(1).

新しく"available"の項目が増えています。この項目がほぼ利用可能なメモリの総量です。後はオプションはほとんど変わらんみたいですね。

完全に手抜きですが、オプションを覚えたという事でオッケーとしましょう。