어떤 프로그램 몇바이트 사용하는지 알려면?

nayana의 이미지

하나의 바이너리 파일이 있다고 할때 그 실행파일이 메모리를 몇바이트를 사용하는지 알수있나요?

paperplane의 이미지

실행되고 있는 프로그램이 메모리를 얼마나 먹는지를 알고 싶다면

top 이면 되지 않을까요?

nayana의 이미지

예를 들어서 가령 코드 이렇게 다음과 같이 있다고 하면

Quote:
#include <stdio.h>

int main( void )
{
int a = 0;

return 0;
}


있다고 하면 이프로그램의 경우 실행하자마자 끝나기 때문에 top으로 알수가 없는데...이럴때는 어떻게 해야하나요?
nohmad의 이미지

지역변수는 스택 단위로 늘어나므로 그것으로 메모리 사용량을 따진다는 게 별로 의미없어 보입니다. 동적 메모리라면 valgrind를 사용하면 쉽게 알 수 있습니다.

$ valgrind --tool=memcheck date
==18766== Memcheck, a memory error detector for x86-linux.
==18766== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==18766== Using valgrind-2.2.0, a program supervision framework for x86-linux.
==18766== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==18766== For more details, rerun with: -v
==18766==
2005. 10. 27. (목) 20:25:20 KST
==18766==
==18766== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 19 from 1)
==18766== malloc/free: in use at exit: 216 bytes in 2 blocks.
==18766== malloc/free: 422 allocs, 420 frees, 19231 bytes allocated.
==18766== For a detailed leak analysis,  rerun with: --leak-check=yes
==18766== For counts of detected errors, rerun with: -v