SHMCTL(3P)

πŸ’– SHMCTL(3P) β€” bestie edition πŸ’–

okay so this one is from the POSIX Programmer's Manual, page SHMCTL(3P), and we're about to get so into shared memory control. grab a snack. πŸ“


🫢 PROLOG

real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not be implemented on Linux at all. not me warning you up front πŸ’…


✨ NAME ✨

shmctl β€” XSI shared memory control operations. yes bestie, it's giving "I manage your shared memory segments." πŸ‘‘


🌸 SYNOPSIS 🌸

#include <sys/shm.h>

int shmctl(int shmid, int cmd, struct shmid_ds *buf);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the shmctl() function operates on XSI shared memory (peep the Base Definitions volume of POSIX.1‐2017, Section 3.346, Shared Memory Object). and here's a lil caveat: it is unspecified whether this function interoperates with the realtime interprocess communication facilities defined in Section 2.8, Realtime. like, nobody's promising anything there. πŸ™ˆ

shmctl() provides a whole variety of shared memory control operations, and which one you get is decided by cmd. here are the values for cmd that are available:

  • IPC_STAT β€” place the current value of each member of the shmid_ds data structure associated with shmid into the structure pointed to by buf. the contents of that structure are defined in <sys/shm.h>. she's reading the receipts. πŸ”
  • IPC_SET β€” set the value of the following members of the shmid_ds data structure associated with shmid to the corresponding value found in the structure pointed to by buf:
    • shm_perm.uid
    • shm_perm.gid
    • shm_perm.mode β€” low-order nine bits.

also, the shm_ctime timestamp shall be set to the current time, as described in Section 2.7.1, IPC General Description.

IPC_SET can only be executed by a process that has an effective user ID equal to either that of a process with appropriate privileges or to the value of shm_perm.cuid or shm_perm.uid in the shmid_ds data structure associated with shmid. no random walk-ins allowed. 🚫
  • IPC_RMID β€” remove the shared memory identifier specified by shmid from the system and destroy the shared memory segment and the shmid_ds data structure associated with it. IPC_RMID can only be executed by a process that has an effective user ID equal to either that of a process with appropriate privileges or to the value of shm_perm.cuid or shm_perm.uid in the shmid_ds data structure associated with shmid.
πŸ’€ this one deletes the whole thing. it's not a soft delete, it's not a "oops undo", it's gone gone. permissions check first, always.

πŸŽ€ RETURN VALUE πŸŽ€

upon successful completion, shmctl() shall return 0. otherwise, it shall return -1 and set errno to indicate the error. classic 0-or-1 behavior, love that for her. ✨


πŸ’… ERRORS πŸ’…

the shmctl() function shall fail if:

  • EACCES β€” the argument cmd is equal to IPC_STAT and the calling process does not have read permission; see Section 2.7, XSI Interprocess Communication. like, you didn't have the read perms, bestie. 😭
  • EINVAL β€” the value of shmid is not a valid shared memory identifier, or the value of cmd is not a valid command. something in there is fake. πŸ™ˆ
  • EPERM β€” the argument cmd is equal to IPC_RMID or IPC_SET and the effective user ID of the calling process is not equal to that of a process with appropriate privileges and it is not equal to the value of shm_perm.cuid or shm_perm.uid in the data structure associated with shmid. who are you and why are you touching this. 🚫

the shmctl() function may fail if:

  • EOVERFLOW β€” the cmd argument is IPC_STAT and the gid or uid value is too large to be stored in the structure pointed to by the buf argument. too much. won't fit. she's overflowing. πŸ’€

the following sections are informative, so like, bonus lore. 🌈


🌸 EXAMPLES 🌸

None. nothing. empty. the void. πŸ•³οΈ (iconic of them honestly)


πŸ‘‘ APPLICATION USAGE πŸ‘‘

the POSIX Realtime Extension defines alternative interfaces for interprocess communication. application developers who need to use IPC should design their applications so that modules using the IPC routines described in Section 2.7, XSI Interprocess Communication can be easily modified to use the alternative interfaces. future-proofing is the vibe check here, fr fr. 🧚


πŸ’œ RATIONALE πŸ’œ

None. nope. nada. she said no comment. πŸ™ˆ


πŸ¦‹ FUTURE DIRECTIONS πŸ¦‹

None. nothing planned. staying exactly as she is. periodt. πŸ’…


⭐ SEE ALSO ⭐

  • Section 2.7, XSI Interprocess Communication
  • Section 2.8, Realtime
  • shmat()
  • shmdt()
  • shmget()
  • shm_open()
  • shm_unlink()
  • The Base Definitions volume of POSIX.1‐2017, Section 3.346, Shared Memory Object
  • <sys_shm.h>

go read the friends, bestie. the whole friend group is slaying. 🫢


portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie β€” brought to you by IEEE/The Open Group, 2017, page SHMCTL(3P). mwah. πŸ’‹ go manage some shared memory responsibly, ily. πŸŽ€βœ¨

πŸ“¦ where this page comes from