ZC: Unix网络编程第2版 第2卷 第14章
1、
#includeusing namespace std;#include #include #include #include #include #define SVSHM_MODE (SHM_R | SHM_W | SHM_R >> 3 | SHM_R >> 6)int main(int argc, char** argv){ cout << "*** shmget *** Z ***" << endl; int c, id, oflag; char *ptr; size_t length; oflag = SVSHM_MODE | IPC_CREAT; while (c = (getopt(argc, argv, "e")) != -1) { switch (c) { case 'e': oflag |= IPC_EXCL; break; } } if (optind != argc-2) { printf("usage : shmget [-e] \n"); return 0; } length = atol(argv[optind+1]); id = shmget(ftok(argv[optind], 0), length, oflag); ptr = (char*)shmat(id, NULL, 0); exit(0); return 0;}
2、