프로세스 정보 확인 (AIX), getprocs64

OS/리눅스 & 유닉스 2012. 5. 16. 21:12

#include <stdio.h>

#include <stdlib.h>

#include <procinfo.h>

#include <sys/types.h>


int

main(argc, argv)

int argc;

char *argv[];

{

        struct procentry64 psinfo;

struct psinfo ps;

char filename[64];

        pid_t pid;

int fd;

int count;


        if (argc > 1)

                pid = atoi(argv[1]);

        else

                pid = getpid();


        printf("My pid: %d\n", pid);


sprintf(ps.pr_psargs, "data missing", 12);

sprintf(filename, "/proc/%d/psinfo", pid);

fd=open(filename, O_RDONLY);

if(fd == -1) {

perror("open failure");

} else {

count = read(fd,&ps,sizeof(struct psinfo));

if(count != sizeof(struct psinfo)) {

perror("read failure");

printf("count was %d expected %d\n", count, sizeof(struct psinfo));

}

close(fd);

}


        if (getprocs64(&psinfo, sizeof(struct procentry64), NULL, sizeof(struct fdsinfo64) , &pid, 1) > 0) {

printf("%d,%0.0f,%d,%d,%d,%d,%d,%s,%s\n",

(int)psinfo.pi_pid,

(double) (TIMED(pi_ru.ru_utime) +TIMED(pi_ru.ru_stime)),

(int)psinfo.pi_size*4, /* convert pages to KBytes */

(int)psinfo.pi_thcount,

(int)psinfo.pi_state,

(int)psinfo.pi_start,

(int)psinfo.pi_uid,

psinfo.pi_comm,

ps.pr_psargs

);

        } else {

                perror("getproc64");

                return 1;

        }

}

: