/
/消息队列的发送与接收
#include <stdio.h>
#include <sys/types.h>
#include <sys/msg.h>
#include <unistd.h>
#include <string.h>//不包含此头文件,会出现“警告:隐式声明与内建函数strcpy不兼容”
struct msg_buf
{
int mtype;
char data[255];
};
int main(int argc, char *argv[])
{
key_t key;
int msgid;
int ret;
struct msg_buf msgbuf;
key=ftok("2",'a');//2为对应文件路径 不存在也无妨,a不用管 只要不为0即可
printf("key=[%x]\n",key);
msgid=msgget(key,IPC_CREAT|0666);/
#include <stdio.h>
#include <sys/types.h>
#include <sys/msg.h>
#include <unistd.h>
#include <string.h>//不包含此头文件,会出现“警告:隐式声明与内建函数strcpy不兼容”
struct msg_buf
{
int mtype;
char data[255];
};
int main(int argc, char *argv[])
{
key_t key;
int msgid;
int ret;
struct msg_buf msgbuf;
key=ftok("2",'a');//2为对应文件路径 不存在也无妨,a不用管 只要不为0即可
printf("key=[%x]\n",key);
msgid=msgget(key,IPC_CREAT|0666);/