[linux] 메모리


Linux에서 사용중인 실제 사용중인 메모리 구하기

설명

Linux "free" 실행 결과

[root@redjini script]# free -m
total used free shared buffers cached
Mem: 1010 817 193 0 121 115
-/+ buffers/cache: 579 431
Swap: 2000 66 1933

실제 Free Memory : free(193 MB) + buffers(121 MB) + cached(115 MB)

스크립트

#!/bin/sh

MEM_TOTAL=`free | grep ^Mem | awk '{print $2}'`
MEM_FREE=`free | grep ^Mem | awk '{print $4}'`
MEM_BUFFER=`free | grep ^Mem | awk '{print $6}'`
MEM_CACHED=`free | grep ^Mem | awk '{print $7}'`

REAL_MEM_FREE=$(($MEM_FREE+$MEM_BUFFER+$MEM_CACHED))
REAL_MEM_USED=$(($MEM_TOTAL-$REAL_MEM_FREE))

echo "TOTAL: $MEM_TOTAL"
echo "FREE : $REAL_MEM_FREE"
echo "USED : $REAL_MEM_USED"

참고

"프로그래밍 / Linux & Shell Script" 분류의 다른 글

[shell script] bash read command (0)2014/02/11
[linux] shell command 로그 남기기 (0)2014/01/27
[linux] Linux Console에서 BEEP 사운드 끄기 (0)2014/01/27
[shell] netstat (0)2014/01/22
[shell script] 배열(Array) 사용하기 (0)2014/01/10
[shell script] 함수(Function) 사용하기 (0)2014/01/09
[shell script] Here Documents (0)2013/11/26
[shell script] directory exists check (0)2013/11/20
[shell script] 실행 경로 구하기 (0)2013/10/24
[shell] yum 장애 조치 (0)2009/04/21


Powered by Textcube