共有メモリを開こうとしていますが、そのようなファイルやディレクトリのエラーは発生しません。しかし、名前領域にファイルとディレクトリがあります。
fd_sh = shm_open("/home/angus/c_tutorials/interview/linux_sys_pgm/mmap/region", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if(fd_sh == -1){
perror("fd_sh:ERROR");
return -1;
}
Linuxでは(コードを考えると、これがOSだと思います)、名前はスラッシュで始まる必要がありますが、その後に他の名前を付けないでください。たとえば"/myshm"、通常のファイル名ではありません。
マニュアルページから:
The operation of shm_open() is analogous to that of open(2). name
specifies the shared memory object to be created or opened. For porta‐
ble use, a shared memory object should be identified by a name of the
form /somename; that is, a null-terminated string of up to NAME_MAX
(i.e., 255) characters consisting of an initial slash, followed by one
or more characters, none of which are slashes.
このようにするとうまくいきます。
実際には、指定された名前はでファイルとして作成される/dev/shmため、パスを使用するにはディレクトリ構造を作成する必要があります。このディレクトリはメモリ内にあるだけなので、これはお勧めできません。