📄 a.c
字号:
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include "shm_com.h"
int main()
{
int running=1;
shm_data* shm_buff;
int shmid;
srand((unsigned int)getpid());
shmid = shmget((key_t)1234, sizeof(shm_data), 0666|IPC_CREAT);//0666:user/group/other quan xian is r&w
shm_buff = (shm_data *)shmat(shmid, (void*)0, 0);//hzg: '(void*)0' is auto alloc yingshe address.
shm_buff->is_written=0;
while (running){
if (shm_buff->is_written)
{
printf ("You wrote : %s", shm_buff->data);
//sleep(rand()%4);
shm_buff->is_written=0;
if (strncmp(shm_buff->data, "end", 3)==0)
running=0;
}
}
shmdt(shm_buff);
shmctl(shmid, IPC_RMID, 0);
exit(EXIT_SUCCESS);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -