1 #define _GNU_SOURCE 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <assert.h> 5 #include <sys/ipc.h> 6 #include <sys/shm.h> 7 #include <sys/stat.h> 8 #include <sys/mman.h> 9 mkmap(unsigned sz)10static void *mkmap(unsigned sz) 11 { 12 int shmid = shmget(IPC_PRIVATE, sz, 13 IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR); 14 assert(shmid != -1); 15 16 void *addr = shmat(shmid, NULL, 0); 17 assert(addr != (void *)-1); 18 19 return addr; 20 } 21 main()22int main() 23 { 24 void *np, *p; 25 26 p = mkmap(1024*1024); 27 np = mremap(p, 1024*1024, 2048*1024, MREMAP_MAYMOVE); /* grow, maymove */ 28 assert(np != (void *)-1); 29 30 return 0; 31 } 32