- 论坛徽章:
- 0
|
急求附接共享存储区的算法!在线等!
#include <sys/types.h>;
#include <sys/ipc.h>;
#include <sys/shm.h>;
#define SHMKEY 75
#define K 1024
int shmid;
main()
{
int i=0, *pint;
char *addr1, *addr2;
extern char *shmat(); /* 上面的附接共享存储区的实现 */
extern cleanup();
while(i++<20) signal(i, cleanup);
shimd=shmget(SHMKEY, 128*K, 0777|IPC_CREAT);
addr1=shmat(shmid, 0, 0);
addr2=shmat(shmid, 0, 0);
printf("addr1 0x%x addr2 0x%x\n", addr1, addr2);
pint=(int *)addr1;
for (i=0; i<256; i++) *pint++=1;
pint=(int *)addr1;
*pint=256;
pint=(int *)addr2;
for (i=0; i<256; i++) printf("index %d \ tvalue %d\n", i, *pint++);
pause();
}
cleanup()
{
shmctl(shmid, IPC_RMID, 0);
exit();
} |
|