[Linux] “TOP” 명령어 설명

리눅스를 사용하다 보면 “Top” 명령어를 자주 사용하게 된다. 해당 명령어를 사용하면 현재 실행 중인 프로세스의 정보를 확인할 수 있다. 다양한 정보가 출력되는데 정확한 의미를 몰라서 정리해보았다. 우선 개인적으로 필요한 부분만 정리하였다. 더 필요한 정보가 있는 경우 추가로 정리할 예정이다

 

“Top” 명령어 (출처 1)

처음 실행 시

  • $top -b: 모든 정보를 한번에 출력함
  • $top -n N: N 횟수 만큼만 Top을 Refresh함

실행 후

  • Shift + p: CPU 사용량에 따라서 정렬
  • Shift + m: 메모리 사용량에 따라서 정렬
  • Shift + t: 프로세서가 실행 시간에 따라서 정렬

 

Memory (VIRT, RES, SHR) (출처 1, 2)

그림 1: Top Memory 관련 정보

  • VIRT (Virtual Image): 프로세스가 사용하고 있는 Virtual 메모리 사용량 (Code Memory, Data Memory, Shared Memory, Swap Memory) (The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used.)
  • RES (Resident Size): 프로세스가 사용하고 있는 물리 메모리 사용량 (The non-swapped physical memory a task has used.)
  • SHR (Shared Memory Size): 다른 프로세스와 공유하고 있는 메모리 사용량 (The amount of shared memory used by a task. It simply reflects memory that could be potentially shared with other processes.). 예시로 라이브러리를 들 수 있음. 대부분의 리눅스 프로세스는 glibc라는 라이브러리를 참고하기에 이런 라이브러리를 공유 메모리에 올려서 사용

 

ps와 top의 차이점 (출처 1)

  • ps는 ps한 시점에 proc에서 검색한 cpu 사용량
  • top은 proc에서 일정 주기로 합산해 cpu 사용율 출력

 

출처

  1. https://zzsza.github.io/development/2018/07/18/linux-top/
  2. https://askubuntu.com/questions/176001/what-do-virt-res-and-shr-mean-in-the-top-command

Leave a Comment