嵌入式 Linux 进程间通信之信号灯的几点注意事项
来源:互联网 发布:windows日志怎么看sql 编辑:程序博客网 时间:2024/06/05 05:06
1. 关于union semun结构体的定义和头文件的包含
在用信号灯进行通信时,包含头文件:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
但是,在编译程序的时候提示错误,提示union semun对应的类型不存在
看到有加头文件:#include <linux/sem.h> (不便于程序移植,如果包含该头文件,则不能移到UNIX系统下)
但在加上该头文件之后,又会提示,说有些数据结构被重复的定义了
搞得是加也不是,不加也不是
因为在semctl()方法中用到了该数据结构,所以man semctl,发现有如下说明:
The calling program must define this union as follows:
union semun {
int val; /* Value for SETVAL */
struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */
unsigned short *array; /* Array for GETALL, SETALL */
struct seminfo *__buf; /* Buffer for IPC_INFO
(Linux-specific) */
};
即,调用程序必须定义如下结构体...
原来需要自己定义union semun联合体才可以...
2. 关于ftok()函数中参数pathname的取值
key_t ftok(const char *pathname, int proj_id);
原来以为,随便给pathname取个值就好了,但是执行的时候总是提示错误:“ENOENT: A component of path does not exist, or path is an empty string.”
后来才发现,必须给该参数取一个有效的路径才可以...
在man ftok中也详细的文档说明:
pathname (which must refer to an existing, accessible file) 即,pathname必须指向一个已存在,并可访问的路径;
least significant 8 bits of proj_id 即,proj_id为8bit的有效的非0值(1-127)
3. 程序的执行
由于信号集为系统内核中存储,所以程序的执行必须有Root权限才可以
- Linux 进程间通信之信号灯的几点注意事项
- 嵌入式 Linux 进程间通信之信号灯的几点注意事项
- 嵌入式 Linux 进程间通信之消息队列的几点注意事项
- Linux 进程间通信之消息队列的几点注意事项
- 嵌入式 Linux环境进程间通信(四):信号灯
- Linux 进程间通信 - 信号灯
- Linux进程间通信---信号灯
- 进程间的通信---信号灯
- Linux的进程编程-之二-进程间通信(信号灯-Semaphore)
- Linux环境进程间通信 信号灯
- Linux环境进程间通信(四): 信号灯
- Linux 进程间通信 - 信号灯(Semaphores)
- Linux进程间通信 —— 信号灯
- UNIX环境高级编程学习之第十五章进程间通信 - 信号量的使用(信号灯的使用, 计算信号灯)
- 笔记七:进程间的通信(IPC通信之信号灯)
- 嵌入式 Linux 进程间通信几种方式小结
- Linux环境进程间通信(四):信号灯
- Linux环境进程间通信系列(四):信号灯
- Cocos2d-x 3.0 开发(十五)使用UILayout布局,制作对话界面
- 嵌入式 Linux 进程间通信之消息队列的几点注意事项
- 思维导图MindManager使用说明
- python 模块-使用HTMLParser 解析html
- [Android实例] [版主原创]android之ScrollView里嵌套ListView
- 嵌入式 Linux 进程间通信之信号灯的几点注意事项
- form表单提交之前判断
- 漫画制作软件EasyComic V1.7发布
- Party All the Time+hdu+三分搜索
- C语言 指教坐标转换为极坐标
- 上海白玉兰妇科医院为你介绍骗子的骗术
- Eclipse <Unhandled event loop exception>
- Cocos2d-x 3.0开发(十三)使用CocoStudio编辑帧事件并关联到程序
- new balance qJNd eIf5 jfhN