0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Macでメモリ全体の使用率を確認するコマンド

Posted at
  • Macにてメモリ状況を確認するにはGUIではアクティビティモニター、CUIではtopコマンド等があります。
  • 詳細情報を確認するには便利ですが、簡単に全体を知りたい場合があります。
  • 今回はMac標準のコマンドを利用して確認する方法を記録いたします。

環境

  • Mac OS 13.4.1

結果

未使用率

memory_pressure -Q | awk 'NR==2{printf "%.2f%%\n", $NF}'

# 出力 : xx.xx%

使用率

memory_pressure -Q | awk 'NR==2{printf "%.2f%%\n", 100 - $NF}'

# 出力 : xx.xx%

内容

  • 上記ではmemory_pressureコマンドを利用しています。
  • このコマンドはメモリ圧力状態の評価及び管理するためのもので、問題解析やシミュレート等に便利です。
  • 引数なしの実行でメモリ状況の詳細を出力してくれますが、-Qオプションをつけることで以下の情報のみの出力に抑制してくれます。
$ memory_pressure -Q

The system has xxxxxxx (xxxxxx pages with a page size of xxxx).
System-wide memory free percentage: xx%
  • つまり、この情報の2行目のSystem-wide memory free percentageの割合をawkに渡して使用率及び未使用率を出力するコマンドとなっております。

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?