深入解析Posix IPC与System V IPC
1. Posix IPC概述
Posix IPC(Inter - Process Communication,进程间通信)包含消息队列、信号量和共享内存三种类型,它们通过路径名进行标识,但这些路径名可能并非文件系统中的真实路径,这可能会引发可移植性问题。为解决此问题,可使用自定义的 px - ipc - name 函数,以下是该函数的代码:
char *px-ipc-name(const char *name) {
char *dir, *dst, *slash;
if ((dst = malloc(PATH_MAX)) == NULL)
return (NULL);
/* can override default directory with environment variable */
if ((dir = getenv("PX-IPC-NAME")) == NULL) {
#ifdef POSIX-IPC-PREFIX
dir = POSIX-IPC-PREFIX; /* from "config.h" */
#else
dir = "/tmp/";
#endif
}
/* dir must end in a */
slash = (dir[strlen(dir) - 1] == '/') ? "" : "/";
snprintf(dst, PATH_MAX, "%s%s%s", dir, slash, name);
return (dst
超级会员免费看
订阅专栏 解锁全文
951

被折叠的 条评论
为什么被折叠?



