솔라리스의 메모리 체크 방법은 /proc 밑에 프로세서 별로 생성되는 프로세스 정보 파일을 읽어들이는 것이다.
아래 파일 포맷은 아래 구조체 형식으로 정보들이 들어있으며, 구조체로 읽어들이면 처리하기 편하다..
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include PRFNSZ 1024
#include PRARGSZ 1024
typedef struct {
....int pr_flag; /* process flags */
....int pr_nlwp; /* number of lwps in process */
....pid_t pr_pid; /* unique process id */
....pid_t pr_ppid; /* process id of parent */
....pid_t pr_pgid; /* pid of process group leader */
....pid_t pr_sid; /* session id */
....uid_t pr_uid; /* real user id */
....uid_t pr_euid; /* effective user id */
....gid_t pr_gid; /* real group id */
....gid_t pr_egid; /* effective group id */
....uintptr_t pr_addr; /* address of process */
....size_t pr_size; /* size of process image in Kbytes */
....size_t pr_rssize; /* resident set size in Kbytes */
....size_t pr_pad1;
....dev_t pr_ttydev; /* controlling tty device(or PRNODEV)*/
......../* The following percent numbers are 16-bit binary */
......../* fractions [0 .. 1] with the binary point to the */
......../* right of the high-order bit (1.0 == 0x8000) */
....ushort_t pr_pctcpu; /* % of recent cpu time used by all lwps */
....ushort_t pr_pctmem; /* % of system memory used by process */
....timestruc_t pr_start; /* process start time, from the epoch */
....timestruc_t pr_time; /* usr+sys cpu time for this process */
....timestruc_t pr_ctime; /* usr+sys cpu time for reaped children */
....char pr_fname[PRFNSZ]; /* name of execed file */
....char pr_psargs[PRARGSZ]; /* initial characters of arg list */
....int pr_wstat; /* if zombie, the wait() status */
....int pr_argc; /* initial argument count */
....uintptr_t pr_argv; /* address of initial argument vector */
....uintptr_t pr_envp; /* address of initial environment vector */
....char pr_dmodel; /* data model of the process */
....char pr_pad2[3];
....int pr_filler[7]; /* reserved for future use */
} psinfo;
int main(int argc, char *argv[])
{
....int m_pid, fd;
....char tmp1[1024];
....psinfo pinfo;
....memset(tmp1, 0x00, sizeof(tmp1));
....m_pid = atoi(argv[1]);
....sprintf(tmp1, "/proc/%d/psinfo", m_pid);
....fd = open(tmp1, O_RDONLY);
....read(fd, (void *)&pinfo, sizeof(pinfo));
..../* ----------- INFO PRINT --------------- */
....printf(" Process id <%d>\\n", pinfo.pr_pid);
....printf(" Parent process id <%d>\\n", pinfo.pr_ppid);
....printf(" Process image size (Kbyte) <%d>\\n", pinfo.pr_size);
....printf(" Resident set size (Kbyte) <%d>\\n", pinfo.pr_rssize);
....printf(" Process cpu used <%d>\\n", pinfo.pr_pctcpu);
....printf(" Process memory used <%d>\\n", pinfo.pr_pctmem);
....printf(" Execute File name <%s>\\n", pinfo.pr_fname);
....return 0;
}
'MY IT' 카테고리의 다른 글
[STL] DEQUE (0) | 2006.07.15 |
---|---|
[STL] LIST (0) | 2006.07.15 |
바이러스 (0) | 2006.05.01 |
Shell 정렬 (0) | 2006.04.14 |
패킷 판단 (0) | 2006.04.11 |