最近編寫的乙個linux 訊息佇列例子!

2021-08-26 10:44:47 字數 993 閱讀 4958

所謂訊息佇列就是指乙個訊息鍊錶。

int msgget(key_t, int flag):建立和開啟佇列

int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int flag):傳送訊息,msgid是訊息佇列的id,msgp是訊息內容所在的緩衝區,msgsz是訊息的大小,msg***是標誌。

int msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int flag):接受訊息,msgtyp是期望接收的訊息型別。

msgqueue.c檔案內容如下;

makefile檔案型別如下;

all:msgqueue # which compiler cc = gcc # where are include file kept include = . # where to install instdir = /usr/local/bin # options for development cflags = -g -wall -ansi msgqueue:msgqueue.o $(cc) -d_reentrant -o msgqueue msgqueue.o -lpthread msgqueue.o:msgqueue.c # $(cc) -i$(include) $(cflags) -c msgqueue.c # $(cc) -d_reentrant -c msgqueue.c -lpthread $(cc) -c msgqueue.c clean: -rm msgqueue.o msgqueue install:msgqueue @if [-d $(instdir) ];\ then \ cp msgqueue $(instdir);\ chmod a+x $(instdir)/msgqueue;\ chmod og-w $(instdir)/msgqueue;\ echo "install in $(instdir)";\ else \ echo "sorry,$(instdir) does not exist";\ fi

編寫乙個程式,實現鏈隊的各種基本運算

完成如下功能 1 初始化鏈隊q 2 判斷鏈隊q是否非空 3 依次進隊元素a,b,c 4 出隊乙個元素,並輸出該元素 5 輸出鏈隊q的元素個數 6 依次進鏈隊元素d,e,f 7 輸出鏈隊q的元素個數 8 輸出出隊序列 9 釋放鏈隊 include iostream using namespace st...

linux下編寫乙個簡單的執行緒

建立執行緒 int pthread create pthread t thread,const pthread attr t attr,void start routine void void arg thread 若建立成功則儲存被建立執行緒的執行緒控制代碼 attr 執行緒屬性 start ro...

Linux 下編寫乙個 PHP 擴充套件

假設需求 開發乙個叫做 helloword 的擴充套件。擴充套件裡有乙個函式,helloword echo helloword tom 返回 hello world tom 本地環境php版本 5.6.9 系統 linux centos release 6.5 final 最終效果 實現流程 第一步...