1211
来源:互联网 发布:importnew java面试 编辑:程序博客网 时间:2024/05/19 13:27
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/shm.h>
#include "shmdata.c"
#include <string.h>
int main()
{
int running = 1;
void *shm = NULL;
struct shared_use_st * shared;
int shmid;
shmid = shmget((key_t)1234,sizeof(struct shared_use_st),0666|IPC_CREAT);
if(shmid == -1)
{
fprintf(stderr,"shmget failed\n");
exit(EXIT_FAILURE);
}
shm = shmat(shmid,0,0);
if(shm == (void*)-1)
{
fprintf(stderr,"shmat failed\n");
exit(EXIT_FAILURE);
}
printf("\n memary attached at %d\n",(int)shm);
shared = (struct shared_use_st *)shm;
shared->written = 0;
while(running)
{
if(shared->written != 0)
{
printf("you wrote : %s\n",shared->text);
sleep(rand()%3);
shared->written = 0;
if(strncmp(shared->text,"end",3) == 0)
running = 0;
}
else
sleep(1);
}
if(shmdt(shm) == -1)
{
fprintf(stderr,"shmdt failed\n");
exit(EXIT_FAILURE);
}
if(shmctl(shmid,IPC_RMID,0) == -1)
{
fprintf(stderr,"stmctl failed\n");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
return 0;
}
#include <unistd.h>
#include <stdlib.h>
#include <sys/shm.h>
#include "shmdata.c"
#include <string.h>
int main()
{
int running = 1;
void *shm = NULL;
struct shared_use_st * shared;
int shmid;
shmid = shmget((key_t)1234,sizeof(struct shared_use_st),0666|IPC_CREAT);
if(shmid == -1)
{
fprintf(stderr,"shmget failed\n");
exit(EXIT_FAILURE);
}
shm = shmat(shmid,0,0);
if(shm == (void*)-1)
{
fprintf(stderr,"shmat failed\n");
exit(EXIT_FAILURE);
}
printf("\n memary attached at %d\n",(int)shm);
shared = (struct shared_use_st *)shm;
shared->written = 0;
while(running)
{
if(shared->written != 0)
{
printf("you wrote : %s\n",shared->text);
sleep(rand()%3);
shared->written = 0;
if(strncmp(shared->text,"end",3) == 0)
running = 0;
}
else
sleep(1);
}
if(shmdt(shm) == -1)
{
fprintf(stderr,"shmdt failed\n");
exit(EXIT_FAILURE);
}
if(shmctl(shmid,IPC_RMID,0) == -1)
{
fprintf(stderr,"stmctl failed\n");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
return 0;
}
0 0
- 1211
- 1211
- 1211
- 1211
- 1211塌方
- sicily 1211
- HDU 1211
- 1211 -- 统计数字
- bzoj 1211
- Lightoj 1211
- sdut 1211
- 1211 模式匹配
- hdu 1211 RSA
- pz之1211
- hdoj 1211-RSA
- hdu 1211 RSA 解密
- hdu 1211 RSA
- HDU 1211 求逆元
- git的常用操作
- 移动端点击事件、滑动事件、长按事件封装
- [问题记录]NotServingRegionException: Region hbase:meta
- VelocityTracker的简单使用
- git learn
- 1211
- POJ 3159 Candies(差分约束+dijkstra+heap)
- Haproxy+etcd+confd+Docker搭建节点自动发现的高可用负载均衡框架
- Substring() 截取string字符串
- GDB调试命令以及GDB调试段错误
- 1212
- 4-DCL
- Atitit 教育与培训学校 的计划策划 v2
- 关于char 的考题