본문 바로가기

리눅스

리눅스에서 메모리 사용률이 높은 프로세스를 찾는 방법

반응형

리눅스에서 메모리 사용률이 높은 프로세스를 찾는 방법

1. top 명령어

top 명령어는 시스템 상태를 실시간으로 모니터링하는 도구로 메모리 사용률이 높은 프로세스를 확인할 수 있습니다. top을 실행한 후에는 메모리 사용량이 큰 프로세스들이 상단에 나타납니다.

top

2. htop 명령어

htop은 top과 유사하지만 더 사용하기 편리하며 색상으로 시각화된 인터페이스를 제공합니다.

sudo apt-get install htop
더보기
더보기

---

$ sudo apt install htop
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libnl-3-200 libnl-genl-3-200
Suggested packages:
  lm-sensors lsof strace
The following NEW packages will be installed:
  htop libnl-3-200 libnl-genl-3-200
0 upgraded, 3 newly installed, 0 to remove and 53 not upgraded.
Need to get 197 kB of archives.
After this operation, 566 kB of additional disk space will be used.
Do you want to continue? [Y/n]
...

---

htop

3. ps 명령어와 정렬

ps 명령어를 사용하여 메모리 사용률에 따라 정렬된 프로세스 리스트를 확인할 수 있습니다.

%mem은 메모리 사용률을 나타냅니다. --sort=-%mem 옵션은 메모리 사용률이 높은 순으로 정렬합니다.

ps aux --sort=-%mem | head -n 10
$ ps aux --sort=-%mem | head -n 10
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      792394  1.2 29.2 44983664 9604092 ?    Sl   Nov22 652:59 java -jar -Djava.io.tmpdir=/opt/ngrinder-controller/lib /opt/ngrinder-controller-3.5.8.war --port 80
mtgisa   3152880  0.8  2.0 24171888 665040 ?     Sl   Dec20  99:07 java -jar Syncon.jar client.yaml
mtgisa   2043227  0.1  0.4 13060072 144488 ?     Sl   Dec15  31:29 java -jar ProcessCheck.jar config.yaml
mtgisa   1011520  1.0  0.2 353716 70920 ?        S    12:39   0:03 php-fpm: pool www
mtgisa   1011493  0.9  0.2 353664 68600 ?        S    12:39   0:03 php-fpm: pool www
mtgisa   1011482  0.9  0.1 361764 63680 ?        S    12:39   0:02 php-fpm: pool www
mtgisa   1011698  0.0  0.1 163952 62784 ?        S    12:39   0:00 php /app/pado/www/artisan queue:work --max-time=3600
mtgisa   1011697  0.0  0.1 163952 62592 ?        S    12:39   0:00 php /app/pado/www/artisan queue:work --max-time=3600
mtgisa   1011445  0.9  0.1 361768 62568 ?        S    12:39   0:02 php-fpm: pool www
728x90

4. smem 명령어

smem은 메모리 사용을 좀 더 상세하게 표시하는 도구입니다. -rs mem 옵션은 메모리 사용량에 따라 내림차순으로 정렬합니다.

smem 설치

sudo apt-get update
sudo apt-get install smem
더보기
더보기

---

$ sudo apt-get install smem
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-aarch64-linux-gnu binutils-common blt cpp cpp-11 fontconfig-config fonts-dejavu-core fonts-lyx g++ g++-11 gcc gcc-11 gcc-11-base
  gcc-12-base javascript-common libasan6 libatomic1 libbinutils libblas3 libboost-dev libboost1.74-dev libc-dev-bin libc-devtools libc6 libc6-dev libcc1-0
  libcrypt-dev libctf-nobfd0 libctf0 libdeflate0 libexpat1-dev libfontconfig1 libfreetype6 libfribidi0 libgcc-11-dev libgcc-s1 libgd3 libgfortran5
  libgomp1 libgraphite2-3 libharfbuzz0b libhwasan0 libimagequant0 libisl23 libitm1 libjbig0 libjpeg-turbo8 libjpeg8 libjs-jquery libjs-jquery-ui
  libjs-sphinxdoc libjs-underscore liblapack3 liblbfgsb0 liblcms2-2 liblsan0 libmpc3 libmpfr6 libnsl-dev libopenblas-dev libopenblas-pthread-dev
  libopenblas0 libopenblas0-pthread libopenjp2-7 libpng16-16 libpython3-dev libpython3.10 libpython3.10-dev libpython3.10-minimal libpython3.10-stdlib
  libqhull-r8.0 libraqm0 libstdc++-11-dev libstdc++6 libtcl8.6 libtiff5 libtirpc-dev libtk8.6 libtsan0 libubsan1 libwebp7 libwebpdemux2 libwebpmux3
  libxft2 libxpm4 libxrender1 libxsimd-dev libxslt1.1 libxss1 linux-libc-dev manpages manpages-dev python-matplotlib-data python3-appdirs python3-attr
  python3-beniget python3-brotli python3-bs4 python3-chardet python3-cycler python3-dateutil python3-decorator python3-dev python3-distutils
  python3-fonttools python3-fs python3-gast python3-html5lib python3-kiwisolver python3-lib2to3 python3-lxml python3-lz4 python3-matplotlib python3-mpmath
  python3-numpy python3-olefile python3-packaging python3-pil python3-pil.imagetk python3-pkg-resources python3-ply python3-pyparsing python3-pythran
  python3-scipy python3-six python3-soupsieve python3-sympy python3-tk python3-tz python3-ufolib2 python3-unicodedata2 python3-webencodings python3.10
  python3.10-dev python3.10-minimal rpcsvc-proto tk8.6-blt2.5 tzdata unicode-data x11-common zlib1g-dev
Suggested packages:
  binutils-doc blt-demo cpp-doc gcc-11-locales gcc-11-doc gcc-multilib make autoconf automake libtool flex bison gdb gcc-doc apache2 | lighttpd | httpd
  libboost-doc libboost1.74-doc libboost-atomic1.74-dev libboost-chrono1.74-dev libboost-container1.74-dev libboost-context1.74-dev
  libboost-contract1.74-dev libboost-coroutine1.74-dev libboost-date-time1.74-dev libboost-exception1.74-dev libboost-fiber1.74-dev
  libboost-filesystem1.74-dev libboost-graph1.74-dev libboost-graph-parallel1.74-dev libboost-iostreams1.74-dev libboost-locale1.74-dev
  libboost-log1.74-dev libboost-math1.74-dev libboost-mpi1.74-dev libboost-mpi-python1.74-dev libboost-numpy1.74-dev libboost-program-options1.74-dev
  libboost-python1.74-dev libboost-random1.74-dev libboost-regex1.74-dev libboost-serialization1.74-dev libboost-stacktrace1.74-dev
  libboost-system1.74-dev libboost-test1.74-dev libboost-thread1.74-dev libboost-timer1.74-dev libboost-type-erasure1.74-dev libboost-wave1.74-dev
  libboost1.74-tools-dev libmpfrc++-dev libntl-dev libboost-nowide1.74-dev glibc-doc libgd-tools libjs-jquery-ui-docs liblcms2-utils libstdc++-11-doc
  tcl8.6 tk8.6 libxsimd-doc man-browser python-attr-doc python-cycler-doc python3-genshi python-lxml-doc dvipng ffmpeg fonts-staypuft ghostscript
  gir1.2-gtk-3.0 inkscape ipython3 librsvg2-common python-matplotlib-doc python3-cairocffi python3-gi-cairo python3-gobject python3-pyqt5 python3-sip
  python3-tornado texlive-extra-utils texlive-latex-extra python-mpmath-doc python3-gmpy2 gfortran python-numpy-doc python3-pytest python-pil-doc
  python3-setuptools python-ply-doc python-pyparsing-doc python-scipy-doc texlive-fonts-extra python-sympy-doc tix python3-tk-dbg python3.10-venv
  python3.10-doc binfmt-support
Recommended packages:
  libnss-nis libnss-nisplus
The following NEW packages will be installed:
  binutils binutils-aarch64-linux-gnu binutils-common blt cpp cpp-11 fontconfig-config fonts-dejavu-core fonts-lyx g++ g++-11 gcc gcc-11 gcc-11-base
  javascript-common libasan6 libatomic1 libbinutils libblas3 libboost-dev libboost1.74-dev libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev
  libctf-nobfd0 libctf0 libdeflate0 libexpat1-dev libfontconfig1 libfreetype6 libfribidi0 libgcc-11-dev libgd3 libgfortran5 libgomp1 libgraphite2-3
  libharfbuzz0b libhwasan0 libimagequant0 libisl23 libitm1 libjbig0 libjpeg-turbo8 libjpeg8 libjs-jquery libjs-jquery-ui libjs-sphinxdoc libjs-underscore
  liblapack3 liblbfgsb0 liblcms2-2 liblsan0 libmpc3 libmpfr6 libnsl-dev libopenblas-dev libopenblas-pthread-dev libopenblas0 libopenblas0-pthread
  libopenjp2-7 libpng16-16 libpython3-dev libpython3.10-dev libqhull-r8.0 libraqm0 libstdc++-11-dev libtcl8.6 libtiff5 libtirpc-dev libtk8.6 libtsan0
  libubsan1 libwebp7 libwebpdemux2 libwebpmux3 libxft2 libxpm4 libxrender1 libxsimd-dev libxslt1.1 libxss1 linux-libc-dev manpages manpages-dev
  python-matplotlib-data python3-appdirs python3-attr python3-beniget python3-brotli python3-bs4 python3-chardet python3-cycler python3-dateutil
  python3-decorator python3-dev python3-distutils python3-fonttools python3-fs python3-gast python3-html5lib python3-kiwisolver python3-lib2to3
  python3-lxml python3-lz4 python3-matplotlib python3-mpmath python3-numpy python3-olefile python3-packaging python3-pil python3-pil.imagetk
  python3-pkg-resources python3-ply python3-pyparsing python3-pythran python3-scipy python3-six python3-soupsieve python3-sympy python3-tk python3-tz
  python3-ufolib2 python3-unicodedata2 python3-webencodings python3.10-dev rpcsvc-proto smem tk8.6-blt2.5 tzdata unicode-data x11-common zlib1g-dev
The following packages will be upgraded:
  gcc-12-base libc6 libgcc-s1 libpython3.10 libpython3.10-minimal libpython3.10-stdlib libstdc++6 python3.10 python3.10-minimal
9 upgraded, 134 newly installed, 0 to remove and 53 not upgraded.
Need to get 153 MB of archives.
After this operation, 665 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
...

---

smem -rs maps
$ smem -rs maps
  PID User     Command                         Swap      USS      PSS      RSS
 2238 root     /usr/bin/python3 /usr/bin/s        0    12164    12164    12168
    1 root     bash                               0     3332     3332     3336

5. pmap 명령어

특정 프로세스의 메모리 맵을 확인하기 위해 pmap 명령어를 사용할 수 있습니다. 에는 확인하고자 하는 프로세스의 ID를 넣어주면 됩니다.

pmap 1
$ pmap 1
1:   bash
0000aaaadad10000   1332K r-x-- bash
0000aaaadae6c000     20K r---- bash
0000aaaadae71000     36K rw--- bash
0000aaaadae7a000     44K rw---   [ anon ]
0000aaaafd730000    396K rw---   [ anon ]
0000ffff9c3b0000   1572K r-x-- libc.so.6 (deleted)
0000ffff9c539000     60K ----- libc.so.6 (deleted)
0000ffff9c548000     16K r---- libc.so.6 (deleted)
0000ffff9c54c000      8K rw--- libc.so.6 (deleted)
0000ffff9c54e000     48K rw---   [ anon ]
0000ffff9c560000    176K r-x-- libtinfo.so.6.3
0000ffff9c58c000     60K ----- libtinfo.so.6.3
0000ffff9c59b000     16K r---- libtinfo.so.6.3
0000ffff9c59f000      4K rw--- libtinfo.so.6.3
0000ffff9c5a7000    172K r-x-- ld-linux-aarch64.so.1 (deleted)
0000ffff9c5d7000      8K rw---   [ anon ]
0000ffff9c5dc000      8K rw---   [ anon ]
0000ffff9c5de000      8K r----   [ anon ]
0000ffff9c5e0000      4K r-x--   [ anon ]
0000ffff9c5e1000      8K r---- ld-linux-aarch64.so.1 (deleted)
0000ffff9c5e3000      8K rw--- ld-linux-aarch64.so.1 (deleted)
0000fffff8d59000    132K rw---   [ stack ]
 total             4136K

 

728x90
반응형