没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
进程间共享存储区通信机制的使用
使用共享内存机制实现一定长度的消息的发送和接收。
#include<stdio.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#define buffersize 1024
#define Key 1
int main()
{
int p;
while((p=fork())==-1);
if(p==0)
{
int pid;
sleep(5);
pid=shmget(Key,buffersize,IPC_CREAT|0600);
char *addr;
addr=(char *)shmat(pid,NULL,0);
printf("receive msg is:%s\n",addr);
shmdt(addr);
}
else
{
int pid;
pid=shmget(Key,buffersize,IPC_CREAT|0600);
char *addr;
addr=(char *)shmat(pid,NULL,0);
strcpy(addr," This is the message which the parent have sent!");
使用共享内存机制实现一定长度的消息的发送和接收。
#include<stdio.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#define buffersize 1024
#define Key 1
int main()
{
int p;
while((p=fork())==-1);
if(p==0)
{
int pid;
sleep(5);
pid=shmget(Key,buffersize,IPC_CREAT|0600);
char *addr;
addr=(char *)shmat(pid,NULL,0);
printf("receive msg is:%s\n",addr);
shmdt(addr);
}
else
{
int pid;
pid=shmget(Key,buffersize,IPC_CREAT|0600);
char *addr;
addr=(char *)shmat(pid,NULL,0);
strcpy(addr," This is the message which the parent have sent!");
资源评论
ka838469965
- 粉丝: 7
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功