用Luajit玩Linux共享記憶體

2021-05-24 15:46:07 字數 1225 閱讀 6534

1. shmtest_wirte.lua

ffi = require 'ffi'

ffi.cdef[[

int shmget(int key,int size,int flag);

void * shmat(int shmid,const void* ptr,int flag);

void perror(const char* msg);

char * strcpy(char * dest,const char* src);

local ipc_creat = 01000

local shmid = ffi.c.shmget(798,30000000,ipc_creat)

print(shmid)

ffi.c.perror("creat shm")

local ptr = ffi.c.shmat(shmid,nil,0)

local str = ffi.cast("char *",ptr)

ffi.c.strcpy(str,"hello world")

ffi.c.perror("str cpy")

2. shmtest_read.lua

ffi = require 'ffi'

ffi.cdef[[

int shmget(int key,int size,int flag);

void * shmat(int shmid,const void* ptr,int flag);

void perror(const char* msg);

char * strcpy(char * dest,const char* src); ]]

local shmid = ffi.c.shmget(798,30000000,0)

if shmid==-1 then

ffi.c.perror('')

os.exit(0)

endprint(shmid)

ffi.c.perror("get shm by key")

local ptr = ffi.c.shmat(shmid,nil,0)

local str = ffi.cast('char *',ptr)

print(ffi.string(str,30))

3. 管理

ipcs命令檢視

ipcrm刪除共享記憶體

linux用nfs共享資料夾

1 服務端配置引數 nfs服務的配置檔案為 etc exports,這個檔案是nfs的主要配置檔案,不過系統並沒有預設值,要使用vim手動建立,然後在檔案裡面寫入配置內容。etc exports檔案內容格式 輸出目錄 客戶端1 選項 訪問許可權,使用者對映,其他 客戶端2 選項 訪問許可權,使用者對...

來玩一玩Linux常見命令

這次我們一起來玩一玩常見的linux相關命令,有點意思 那麼我們解釋一下這些 root代表當前登入使用者,localhost代表主機名,代表當前主機目錄,代表使用者許可權 表示超級使用者,表示普通使用者 我們首先看一下根目錄 下的 bin 和 sbin 在user下也有bin和sbin 看看兩者的區...

mac玩rust用什麼畫質 玩彩虹六號用什麼加速器

玩彩虹六號 是育碧旗下的致命模擬射擊遊戲彩虹六號從15年發行開始,就靠著自身過硬的遊戲品質和工作室良好的態度吸引了一批又一批新人入坑,講道理彩虹六號這款遊戲,對於沒玩過射擊遊戲的新玩家來說還是具有一定難度的,可是試問哪乙個男性同胞心裡沒有乙個英雄夢呢是吧。遊戲模式共三種,分別是人質模式 守衛模式 炸...