LoginSignup
6
6

More than 5 years have passed since last update.

Linux: プロセスが起動して終了するまでの最大メモリ使用量を調べる

Posted at

ピークメモリ使用量、つまりプロセスが実行中に一番メモリを使っていた時点での使用量を調べたい。

/usr/bin/time -vを使ってMaximum resident set sizeのところを見れば良い。

/usr/bin/time

  • CentOSならyum install time
  • Arch Linuxならpacman -S time

でインストールできる。

例えばdu -hのメモリ使用量を調べたい場合は次のようにする。

$ /usr/bin/time -v du -h > /dev/null
        Command being timed: "du -h"
        User time (seconds): 0.02
        System time (seconds): 0.08
        Percent of CPU this job got: 98%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.12
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 2236
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 130
        Voluntary context switches: 1
        Involuntary context switches: 37
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

Maximum resident set size (kbytes): 2236 なのでピークメモリ使用量は約2MiBだったと分かる。

See Also

6
6
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
6
6