关于shm_open和shm_unlink的使用问题
来源:互联网 发布:出国留学知乎 编辑:程序博客网 时间:2024/06/11 13:46
原文链接http://blog.sina.com.cn/s/blog_4b0ca1af010009ns.html
关于shm_open和shm_unlink的使用问题
C programming in the UNIX environment的编程手册,一般都会为进程间用共享内存的方法通信提供两组方法:
1.
int shm_open(const char *name, int oflag, mode_t mode);
int shm_unlink(const char *name);
int ftruncate(int fd, off_t length);
2.
int shmget(key_t key, int size, int shmflg);
void *shmat(int shmid, const void *shmaddr, int shmflg);
int shmdt(const void *shmaddr);
int shmctl(int shmid, int cmd, struct shmid_ds *buf);
由于POSIX标准比较通用,一般建议使用该标准定义的方法集。
但是在使用shm_open和shm_unlink两个函数时,你可能遇到和我同样的问题,见如下代码。
该代码旨在测试你的系统是否支持POSIX定义的共享内存函数集。
/* This is just to test if the function is found in the libs. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
int
main (void)
{
}
假设它所在的文件为"test.c"
我这么编译:
gcc -o test test.c
结果为:
/tmp/ccaGhdRt.o(.text+0x23): In function `main':
: undefined reference to `shm_open'
/tmp/ccaGhdRt.o(.text+0x49): In function `main':
: undefined reference to `shm_unlink'
collect2: ld returned 1 exit status
编译结果实际上是说,没include相应的头文件,或是头文件不存在(即系统不支持该库函数)
但我man shm_open是可以找到帮助文件的(说明系统支持),原因何在???
请注意一下man shm_open的帮助文件的最后几行:
NOTES
a dedicated file system, which is normally mounted under /dev/shm.
如果你注意到的话,这样编译就能通过了:
gcc -o test test.c -lrt(此处同转载处有区别)
其实就是要连接库的原因。
- 关于shm_open和shm_unlink的使用问题
- 关于shm_open和shm_unlink的使用问题
- 关于shm_open和shm_unlink的使用问题
- 关于:(.text+0x21): undefined reference to `shm_open'问题
- -lrt问题,即:shm_open的头文件存在,编译却不通过,提示undefined
- 关于bitset和dynamic_bitset的使用问题!
- 关于comboBox和grid的使用问题
- 关于ResolveClientUrl和ResolveUrl的使用 问题
- shm_open和mmap,以及共享内存
- linux多线程 & IPC【】open和shm_open
- shm_unlink()函数
- shm_open与shm_ulink的实现1
- shm_open与shm_ulink的实现2
- 关于浏览器的缓存和getLastModified()的使用问题。
- 关于浏览器的缓存和getLastModified()的使用问题
- 关于SearchView的使用和遇到的问题
- 关于mybatis的jdbcType和javaType的使用场景问题
- php eval函数的使用和关于安全的问题
- 生成文件-java自动生成多个相同文件
- Selenium 中文API
- hibernate中PO(持久化对象)与POJO(普通的JavaBean)
- 破解优酷土豆播放器过程
- Python超级程序员使用的开发工具
- 关于shm_open和shm_unlink的使用问题
- Oracle 11g新特性虚拟列分区
- 直接插入排序
- elasticsearch mapping
- C++中 char*,char[],string,CString转换
- MySQL远程连接不上解决办法
- android简单计算器
- 百度地图
- nyoj 吝啬的国度 http://blog.csdn.net/code_pang/article/details/7719221