訊息佇列的小程式

2021-08-07 06:59:20 字數 1189 閱讀 5845

proto.h

#ifndef proto_h__

#define proto_h__

#define keypath            "/etc/hosts"

#define keyproj            'a'

#define namesize        32

#define msg_stu            1

struct msg_st

;#endif

snder.c

#include

#include

#include

#include

#include

#include

#include "proto.h"

int main()

msgid = msgget(key,0);

if(msgid < 0)

sbuf.mtype = msg_stu;

strcpy(sbuf.name,"alan");

sbuf.math = rand()%100;

sbuf.chinese = rand()%100;

if(msgsnd(msgid,&sbuf,sizeof(sbuf)-sizeof(long),0) < 0)

puts("ok!");

exit(0);

}rcver.c

#include

#include

#include

#include

#include

#include

#include "proto.h"

int main()

msgid = msgget(key,ipc_creat|0600);

if(msgid < 0)

while(1)

if(rbuf.mtype == msg_stu)

}msgctl(msgid,ipc_rmid,null);//這段**執行不到,可以把這段**寫到訊號處理函式中,然後ctrl+c結束

/*if error*/

exit(0);

}可以用ipcs命令檢視建的訊息佇列

用ipcrm -s+semid  刪除乙個訊息佇列

訊息佇列程式

前面我分享了一篇有關於訊息佇列的部落格,這裡附上我寫的一段訊息佇列的程式 send.c 傳送端 include include include include include include struct msgbuf int main int msgid msgget key,ipc creat ...

小程式訊息推送

小程式開發模板訊息的時候 出現 errcode 41028,errmsg invalid form id hint 大家知道獲取到的prepay id 還非常的詭異 他不是直接乙個引數 而是還帶了字串 比如 prepay id wx2017xx 這樣格式的 最後檢驗是需要去除掉prepay id 這...

小程式 訊息訂閱

desc 小程式訂閱功能 param tmplids 訂閱列表 returns 返回promise 永久關閉訂閱則代表點選了我不在接受此訊息,再次訂閱是無法彈起授權視窗的。普通關閉時可以再次彈起授權視窗。export const subscribe tmplids 申請訂閱功能 function r...