메모리맵핑하려고 하는데, Invalid argument 라고 뜹니다.
가온누리
2023.04.01
질문 제목 : 질문 내용 :
stat 내용을 메모리맵핑해서 가져오려고, 코드를 짰는데, invalid argument 라고 뜨네요..
참고로 /proc/[pid]/stat 파일의 권한은 r--r--r-- 입니다.int main(){
char p_stat[40] = {/proc/1/stat};
int fd;
caddr_t addr;
struct stat statbuf;
if(stat(p_stat, &statbuf) == -1){
perror(stat);
exit(1);
}
if((fd = open(p_stat, o_rdonly)) == -1){ //o_rdwr 로 하면, 허가 거부라고 오류납니다.
perror(open);
exit(1);
}
addr = mmap(null, statbuf.st_size, prot_read, map_shared, fd, (off_t)0);
//prot_read , prot_write, prot_read|prot_write 다 똑같이 오류납니다.
if(addr == map_failed){
perror(mmap);
exit(1);
}
close(fd);
printf(%s, addr);
return 0;
}
대략 이렇게 짰습니다. 허가거부가 나길래 open() 은 o_rdonly로 하였구요.
오류메시지로mmap : invalid argument 라고 뜹니다.
대체 뭐가 문제일까요?