famdestiny
全部博文(38)
2011年(1)
2009年(37)
erhu_wan
sunder33
竹蜻蜓vY
xiaofeng
bcbc3502
otomans
lxy57253
应梦先森
xieyingt
分类: LINUX
2009-08-21 11:27:41
#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/shm.h>#include <errno.h>#include <signal.h>void sig_int(int sig){ printf("quit?! no door!\n"); exit(0);};int main(){ signal(SIGINT, sig_int); key_t key = ftok("/home/ddb/13.jpg", 1); int shm_no; if((shm_no=shmget(key, 1024, 0644 | IPC_CREAT | IPC_EXCL)) == -1) { printf("shnget error, %s\n", strerror(errno)); } char *p = NULL; if((p = (char *)shmat(shm_no, NULL, 0)) == -1) { printf("shmat error, %s\n", strerror(errno)); } while(1) { gets(p); } return 0;}
client
#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/shm.h>#include <errno.h>int main(){ key_t key = ftok("/home/ddb/13.jpg", 1); int shm_no; if((shm_no=shmget(key, 1024, 0)) == -1) { printf("shnget error, %s\n", strerror(errno)); } char *p = NULL; if((p = (char *)shmat(shm_no, NULL, 0)) == -1) { printf("shmat error, %s\n", strerror(errno)); } while(1) { printf("p = %s\n", p); if(strcmp(p, "quit") == 0) { break; } sleep(1); } shmctl(shm_no, IPC_RMID, NULL); return 0;}
上一篇:信号量的使用
下一篇:unix的标准化及实现
登录 注册