'psinfo_t'에 해당되는 글 1건
- 2010.01.21 Pid를 통해 process 정보 얻기
/proc/{pid}/psinfo 파일을 읽어와서 필요한 정보를 얻어온다
예)
psinfo_t ps_info;
memset (&ps_info, 0, sizeof (psinfo_t));
sprintf (buf, "/proc/%d/psinfo", pid);
if ((fd = open (buf, O_RDONLY)) < 0) {
exit(-1);
}
read (fd, &ps_info, sizeof(psinfo_t));
close (fd);
예)
psinfo_t ps_info;
memset (&ps_info, 0, sizeof (psinfo_t));
sprintf (buf, "/proc/%d/psinfo", pid);
if ((fd = open (buf, O_RDONLY)) < 0) {
exit(-1);
}
read (fd, &ps_info, sizeof(psinfo_t));
close (fd);
typedef struct psinfo { 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_t; |