structshmid_ds { structipc_permshm_perm;/* Ownership and permissions */ size_t shm_segsz; /* Size of segment (bytes) */ time_t shm_atime; /* Last attach time */ time_t shm_dtime; /* Last detach time */ time_t shm_ctime; /* Last change time */ pid_t shm_cpid; /* PID of creator */ pid_t shm_lpid; /* PID of last shmat(2)/shmdt(2) */ shmatt_t shm_nattch; /* No. of current attaches */ ... };
structipc_perm { key_t __key; /* Key supplied to shmget(2) */ uid_t uid; /* Effective UID of owner */ gid_t gid; /* Effective GID of owner */ uid_t cuid; /* Effective UID of creator */ gid_t cgid; /* Effective GID of creator */ unsignedshort mode; /* Permissions + SHM_DEST and SHM_LOCKED flags */ unsignedshort __seq; /* Sequence number */ };
ipcs shows information on System V inter-process communication facilities. By default it shows information about all three resources: shared memory segments, message queues, and semaphore arrays.
constchar *contents = R"( Wer, wenn ich schriee, hörte mich denn aus der Engel Ordnungen? und gesetzt selbst, es nähme einer mich plötzlich ans Herz: ich verginge von seinem stärkeren Dasein. Denn das Schöne ist nichts als des Schrecklichen Anfang, den wir noch grade ertragen, und wir bewundern es so, weil es gelassen verschmäht, uns zu zerstören. Ein jeder Engel ist schrecklich. exit )";
intmain(){ int fd = shm_open("/shmem_0", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd == -1) exit_on_error("shm_open");
if (munmap(addr, 4096) == -1) exit_on_error("munmap");
if (close(fd) == -1) exit_on_error("close");
if (sem_close(sem) == -1) exit_on_error("sem_close"); if (sem_close(sem_empty_buf) == -1) exit_on_error("sem_close"); if (sem_close(sem_full_buf) == -1) exit_on_error("sem_close");
if (shm_unlink("/shmem_0") == -1) exit_on_error("shm_unlink");
if (sem_unlink("/sem_0") == -1) exit_on_error("sem_unlink"); if (sem_unlink("/sem_empty_buf") == -1) exit_on_error("sem_unlink"); if (sem_unlink("/sem_full_buf") == -1) exit_on_error("sem_unlink");
if (munmap(addr, 4096) == -1) exit_on_error("munmap");
if (close(fd) == -1) exit_on_error("close");
if (sem_close(sem) == -1) exit_on_error("sem_close"); if (sem_close(sem_empty_buf) == -1) exit_on_error("sem_close"); if (sem_close(sem_full_buf) == -1) exit_on_error("sem_close");