劳驾大神帮俺编个程!!我被逼绝路了。。
linux吧
全部回复
仅看楼主
level 3
laiyinan1234 楼主
题目是 要求用mmap编写一个建议的聊天程序。1.c和2.c之间可以相互对话。
马上要交了 什么都不会 麻烦各位大神了!!
2012年09月01日 03点09分 1
level 3
laiyinan1234 楼主
简易的
2012年09月01日 03点09分 2
题意是mmap共享内存方式写进程通信吧,我看过国嵌的教程 有个示例程序 要的到115下载,我等会给链接 帮你做是不可能了,编程不是简单的事儿
2012年09月01日 07点09分
115现在不是好友分享不了了,要的给邮箱 共享内存 刚看了没有mmap这个函数,不过也差不多了
2012年09月01日 07点09分
回复 double_crane :[email protected] 谢谢
2012年09月01日 07点09分
level 12
[睡觉]
2012年09月01日 04点09分 3
。。。。。e ....囧 。。。。。
2012年09月01日 04点09分
level 11
1.c
#include <stdio.h>
int main(void)
{
printf("Hello 2.c\n");
return 0;
}
2.c
#include <stdio.h>
int main(void)
{
printf("Hello 1.c\n");
return 0;
}
2012年09月01日 04点09分 4
pu。。。。我想吐槽了
2012年09月01日 04点09分
代码写的很规范。
2012年09月01日 11点09分
@_青_霉_素_ 碉堡...........
2012年09月01日 13点09分
学习了
2012年09月01日 13点09分
level 6
100元可以包办。
2012年09月01日 04点09分 5
办好截图证明 我给钱
2012年09月01日 04点09分
居然跑过来拉生意[啊!]
2012年09月01日 10点09分
10块可以包办
2012年09月01日 12点09分
level 13
1.c:
#!/bin/bash
echo "echo hello 2.c" >> 2.c
2.c|1.c &
2.c:
#!/bin/bash
echo "echo hello 1.c" >> 1.c
1.c|2.c &
然后
chmod +x 1.c
chmod +X 2.c
1.c|2.c &
2012年09月01日 04点09分 6
亲 用mmap谢谢。。。
2012年09月01日 04点09分
回复 laiyinan1234 :我只会bash[睡觉]
2012年09月01日 04点09分
level 11
我先知道mmap是个啥……
2012年09月01日 04点09分 7
linux C里的一个函数
2012年09月01日 05点09分
level 10
mmap是让你用文件映射的方式共享数据。
两个程序中都把一个文件映射到内存,就可以共享数据了,但是真正的像聊天,还需要一点同步的机制,用个System V或者POSIX的信号量同步下。
不过你们这题目也太DT了,竟然要聊天~擦[拍砖]
2012年09月01日 05点09分 8
排版实在是抗不住啊~这作业不写也罢,没意思啊
2012年09月01日 05点09分
回复 handsoul :[88]
2012年09月01日 05点09分
level 3
laiyinan1234 楼主
#include <sys/mman.h>#
include
#include <fcntl.h>#
include
#include <stdio.h>#
include #include
typedef struct{ char msg[50]; int flag; //这里我规定1表示1——>2信息,2表示2——>1信息,其他flag表示无效信息}comn;
int main(){ int fd,i; comn *address; char temp[50]; if (fd=open("temp",O_CREAT|O_RDWR|O_TRUNC,022)<0) { perror("file link error!\n"); exit(1); } lseek(fd, sizeof(comn)*5-1, SEEK_SET); write(fd,"",1); address=(comn *)mmap(NULL,sizeof(comn)*5,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_ANONYMOUS,fd,0); close(fd); printf("please input your message\n"); while (1) { for (i=1;i<=5;i++) { if ((*(address+i-1)).flag==1) { printf("端口1:%s",(*(address+i-1)).msg); (*(address+i-1)).flag=3; } } scanf("%s",temp); for (i=1;i<=5;i++) { if ((*(address+i-1)).flag==3) { memcpy((*(address+i-1)).msg,&temp,50); (*(address+i-1)).flag=2; } } } munmap(address,sizeof(comn)*5); return 0;}

2012年09月01日 05点09分 9
排版,要么贴链接
2012年09月01日 05点09分
回复 reverland :稍等一下
2012年09月01日 06点09分
2012年09月01日 06点09分
level 3
laiyinan1234 楼主
#include <sys/mman.h>#
include
#include <fcntl.h>#
include
#include <stdio.h>#
include #include
typedef struct{ char msg[50]; int flag; //这里我规定1表示1——>2信息,2表示2——>1信息,其他flag表示无效信息}comn;
int main(){ int fd,i; comn *address; char temp[50]; if (fd=open("temp",O_CREAT|O_RDWR|O_TRUNC,00777)<0) { perror("file link error!\n"); exit(1); } lseek(fd, sizeof(comn)*5-1, SEEK_SET); write(fd,"",1); address=(comn *)mmap(NULL,sizeof(comn)*5,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_ANONYMOUS,fd,0); close(fd); printf("please input your message\n"); for (i=1;i<=5;i++) { (*(address+i-1)).flag = 3; } while (1) { for (i=1;i<=5;i++) { if ((*(address+i-1)).flag == 1) { printf("端口1:%s\n",(*(address+i-1)).msg); (*(address+i-1)).flag=3; } } scanf("%s",temp); for (i=1;i<=5;i++) { if ((*(address+i-1)).flag == 3 ) { memcpy((*(address+i-1)).msg,&temp,50); (*(address+i-1)).flag=2; } } } munmap(address,sizeof(comn)*5); return 0;}

2012年09月01日 06点09分 10
怎么还是这样的。。。
2012年09月01日 06点09分
level 8
进程间通信???
2012年09月01日 07点09分 12

2012年09月01日 08点09分
level 8
楼主这种伸手党真是悲剧
连作业毕业设计都要伸手的
到了社会简直一无是处
2012年09月01日 07点09分 13
你塔码算什么狗 谁告诉你是什么毕业作业了 这么难度的毕业作业只有配你这种杂种 滚出我视线
2012年09月01日 08点09分
回复 laiyinan1234 :呵呵!笑而不语……
2012年09月01日 08点09分
无论怎么说伸手党是不对的
2012年09月01日 09点09分
回复 叠搭宝箱 :网络上多的是这种弄不清楚就胡乱说的人,好像自己高高在上,充满官僚之风,自大之气,我最不屑了。刚才爆了爆粗口,他应得的。 程序我已经自己写好了
2012年09月01日 10点09分
level 8
啦啦啦,啊哈黑马警长..............[俯卧撑]
2012年09月01日 10点09分 14
level 9
刷怪了 一起来爆菊花
2012年09月01日 13点09分 15
越来越多boss,世界末日了么?
2012年09月01日 13点09分
好吧 我错了 我high了。。
2012年09月01日 13点09分
回复 cxbii :这个不是boss 只是带有重生、击晕技能的小怪
2012年09月01日 13点09分
平均每次一点血,附带击晕一回合,停止回血的小怪
2012年09月03日 02点09分
level 8
mmap这种还要请人送代码 这个我不知道该怎么说……
2012年09月03日 01点09分 16
1