shm_1.c
来自「Linux大学上机源码学习」· C语言 代码 · 共 28 行
C
28 行
#include <sys/types.h>#include <sys/ipc.h>#include <sys/shm.h>#include <stdio.h>#define SHMSZ 27int main(void){ char c; int shmid; key_t key; char * shm,*s; /*create a share_memory named 5678*/ key=5678; if((shmid=shmget(key,SHMSZ,IPC_CREAT|0666))<0) exit(0); /* connecting this share_memory to this process */ if ((shm=shmat(shmid,NULL,0))==NULL) exit(0);/* writting some letters to this memory for other process */ s=shm; for(c='a';c<='z';c++) *s++=c; *s='#';/* waitting for another process change this memory */ while( *shm !='*') sleep(1); exit(0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?