Linux, FreeBSD에서 shared memory의 사용량을 알고 싶을 때.
ipcs -- report System V interprocess communication facilities status
$ ipcs -a
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 6291457 ilashman 600 33554432 2 dest
------ Semaphore Arrays --------
key semid owner perms nsems
------ Message Queues --------
key msqid owner perms used-bytes messages
UNIX Network Programming Volume2, Part 4. Shared Memory 301쪽
유명한 shared memory용 library : mm
http://www.ossp.org/pkg/lib/mm/
man mm
설치방법 :
./configure --prefix=/home/ilashman/local/mm-1.3.0 --with-shm=IPCSHM
make -j 8
make test
make install
-------------------------------------------------------------------------
Libraries have been installed in:
/home/ilashman/local/mm-1.3.0/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
------------------------------------------------------------------------
.bashrc 파일 수정
----------------------
export LIBDIR=/home/ilashman/local/mm-1.3.0/lib:$LIBDIR
export LD_LIBRARY_PATH=/home/ilashman/local/mm-1.3.0/lib:$LD_LIBRARY_PATH
export LD_RUN_PATH=/home/ilashman/local/mm-1.3.0/lib:$LD_RUN_PATH
컴파일 방법 :
g++ -g -Wall test.cpp `mm-config --ldflags --libs`
초기화 : MM_create(크기, "파일명");
할당 : MM_malloc(bytes)
해제 : MM_free(p)
남은 양 보기 : MM_available() - 메모리 leak이 있는 지 확인할 때 쓸 수도 있다.
댓글 없음:
댓글 쓰기