msgctl()函数
int msgctl(int msqid, int cmd, struct msqid_ds *buf);
--参数
msqid:有msgget函数返回的消息队列标识码
cmd:是将要采取的动作
--成功返回0,失败返回-
--cmd的三个取值
IPC_STAT--把msqid_ds结构中的数据设置为消息队列的当前关联值
IPC_SET--在进程有足够权限的前提下,把消息队列的当前关联值设置为msqid_ds数据结构中给出的值
IPC_RMID--删除消息队列
struct msqid_ds {
struct ipc_perm msg_perm; /* Ownership and permissions */
time_t msg_stime; /* Time of last msgsnd(2) */
time_t msg_rtime; /* Time of last msgrcv(2) */
time_t msg_ctime; /* Time of last change */
unsigned long __msg_cbytes; /* Current number of bytes in
queue (non-standard) */
msgqnum_t msg_qnum; /* Current number of messages
in queue */
msglen_t msg_qbytes; /* Maximum number of bytes
allowed in queue */
pid_t msg_lspid; /* PID of last msgsnd(2) */
pid_t msg_lrpid; /* PID of last msgrcv(2) */
};
struct ipc_perm {
key_t __key; /* Key supplied to msgget(2) */
uid_t uid; /* Effective UID of owner */
gid_t gid; /* Effective GID of owner */
uid_t cuid; /* Effective UID of creator */
gid_t cgid; /* Effective GID of creator */
unsigned short mode; /* Permissions */
unsigned short __seq; /* Sequence number */
};
//消息队列--msgctl()函数
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h> int main(int arg, char * args[])
{
int ret = ;
int msgid = msgget(0x1234, );
if (msgid == -)
{
perror("msgget() err");
return -;
}
printf("访问消息队列成功!msqid=%d\n", msgid);
struct msqid_ds buf;
memset(&buf, , sizeof(buf));
ret = msgctl(msgid, IPC_STAT, &buf);
if (ret == -)
{
perror("msgctl() err");
return -;
}
printf("权限位:%o\n", buf.msg_perm.mode);
//想要修改ipcs,需要先获取,然后再修改(这是正确的做法)
buf.msg_perm.mode = ;
ret = msgctl(msgid, IPC_SET, &buf);
if (ret == -)
{
perror("msgctl() err");
return -;
}
printf("修改ipcs成功!\n");
sleep();
ret = msgctl(msgid, IPC_RMID,NULL);
if (ret == -)
{
perror("msgctl() err");
return -;
}
printf("删除ipcs成功!\n");
return ;
}

Linux 进程间通讯详解三的更多相关文章

  1. Linux 进程间通讯详解一

    进程间的通讯 两台主机间的进程通讯 --socket 一台主机间的进程通讯 --管道(匿名管道,有名管道) --System V进程间通信(IPC)包括System V消息队列,System V信号量 ...

  2. Linux 进程间通讯详解二

    消息队列 --消息队列提供了本机上从一个进程向另外一个进程发送一块数据的方法 --每个数据块都被认为有一个类型,接收者进程接收的数据块可以有不同的类型值 --消息队列也有管道一样的不足,就是每个消息的 ...

  3. Linux 进程间通讯详解七

    上图的一台主机服务器架构的重大缺陷是容易死锁 因为客户端,服务器都往同一消息队列中发送接收消息,假设消息队列已经满了,此时客户端无法向队列中发送消息,阻塞了,而服务器接收完一条消息后,想向消息队列发送 ...

  4. Linux 进程间通讯详解六

    ftok()函数 key_t ftok(const char *pathname, int proj_id); --功能:创建系统建立IPC通讯 (消息队列.信号量和共享内存) 时key值 --参数 ...

  5. Linux 进程间通讯详解五

    msgrcv函数 ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp,int msgflg); --功能:是从一个消息队列接 ...

  6. Linux 进程间通讯详解四

    msgsnd函数 int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg); --功能:把一条消息添加到消息队列中 --参数 ...

  7. Linux 进程间通讯方式 pipe()函数 (转载)

    转自:http://blog.csdn.net/ta893115871/article/details/7478779 Linux 进程间通讯方式有以下几种: 1->管道(pipe)和有名管道( ...

  8. Linux 进程间通讯

    一.Linux 下进程间通讯方式 1)管道(Pipe)及有名管道(named pipe): 管道可用于具有亲缘关系进程间的通信,有名管道克服了管道没有名字的限制,因此,除具有管道所具有的功能外,它还允 ...

  9. [转] linux系统文件流、文件描述符与进程间关系详解

    http://blog.sina.com.cn/s/blog_67b74aea01018ycx.html linux(unix)进程与文件的关系错综复杂,本教程试图详细的阐述这个问题. 包括:     ...

随机推荐

  1. json中含有Unicode的处理办法 C#

    public static class StringExtension { #region unicode 字符转义 /// <summary> /// 转换输入字符串中的任何转义字符.如 ...

  2. 用好spring mvc validator可以简化代码

    表单的数据检验对一个程序来讲非常重要,因为对于客户端的数据不能完全信任,常规的检验类型有: 参数为空,根据不同的业务规定要求表单项是必填项 参数值的有效性,比如产品的价格,一定不能是负数 多个表单项组 ...

  3. 设计模式学习之路——Decorator装饰模式(结构模式)

    子类复子类,子类何其多 假如我们需要为游戏中开发一种坦克,除了各种不同型号的坦克外,我们还希望在不同场合中为其增加以下一种或多种功能:比如红外线夜视功能,比如水陆两栖功能,比如卫星定位功能等等. 动机 ...

  4. jQuery静态方法isFunction,isArray,isWindow,isNumeric使用和源码分析

    上一篇随笔中总结了js数据类型检测的几个方法和jQuery的工具方法type方法,本篇要分析几个方法都依赖type方法,所以不了解type方法的请先参看http://www.cnblogs.com/y ...

  5. UIWindow

    title: UIWindow相关知识date: 2016-1-21 20:50categories: IOS tags: UIWindow 小小程序猿我的博客:http://daycoding.co ...

  6. 解决:eclipse删除工程会弹出一个对话框提示“[project_name]”contains resources that are not in sync with"[workspace_name...\xx\..xx\..\xx]"

    提示“[project_name]”contains resources that are not in sync with"[workspace_name...\xx\..xx\..\xx ...

  7. <<你的灯亮着吗?>>读书笔记

    本书是美国计算机传奇人物杰拉尔德.温伯格和唐纳德.高斯所著,我在网上买到的2003年版的本书,发现本书用20则幽默的现代寓言故事,60幅精美插图,以及一系列的适当提问和建议,让我们的思考方式慢慢得以扩 ...

  8. 深圳 Maker Faire 2016 & Microsoft Booth

    首先,感谢Hackster.io和微软,因为发表在Hackster.io的项目<A fall detection system based on Arduino, Windows and Azu ...

  9. 0024 Java学习笔记-面向对象-包装类、对象的比较、String常量池问题

    包装类 基本类型-->包装类 byte-->Byte short-->Short int-->Integer long-->Long char-->Characte ...

  10. forward和redirect的区别(转)

    Redirect Forward 不同的request 不同的对象,但是可以渠道上一个页面的内容 send后面的语句会继续执行,除非return Forward后面的语句不会继续发送给客户端 速度慢 ...