#include #include #include #include #include #define MEM_SIZE (64*1024) // 64k #define MY_KEY 0xBAD02152 // Arbitrary key to "name" memory segment int main(int args, char* argv) { int mem_handle; // Create (IPC_CREAT) new (IPC_EXCL) segment with permission to use // for everybody 0666 = 110 110 110 (rwx for owner, group world) // Then anybody can clean up if needed mem_handle = shmget(MY_KEY, MEM_SIZE, IPC_CREAT | IPC_EXCL | 0666); if (mem_handle==-1) { fprintf(stderr,"Memory [key=%08X] could not be created: ",MY_KEY); perror(0); // Print out specific error in errno exit(1); } exit(0); }