分类: LINUX
2008-11-04 18:02:33
#include #include #include #include #include #define SHM_SIZE (1024*1024*1024+256*1024*1024) #define SHM_MODE 0600 int main() { int shmid = 0; char *shmptr = NULL; shmid = shmget(IPC_PRIVATE, SHM_SIZE, SHM_MODE); if(shmid<0) { perror("shmget"); exit(1); } shmptr = shmat( shmid, 0, 0); if(shmptr==(void *)-1) { perror("shmat"); exit(1); } printf("shm(%u) from 0x%x to 0x%x.\n", SHM_SIZE, shmptr, shmptr+SHM_SIZE); memset(shmptr, 0x41, SHM_SIZE); //'A' getchar(); memset(shmptr, 0, SHM_SIZE); //0 if( shmctl(shmid, IPC_RMID, 0) < 0) { perror("shmctl"); exit(1); } return 0; } |