Manual Pages for Linux CentOS command on man shmctl
MyWebUniversity

Manual Pages for Linux CentOS command on man shmctl

SHMCTL(2) Linux Programmer's Manual SHMCTL(2)

NAME

shmctl - System V shared memory control SYNOPSIS

#include

#include int shmctl(int shmid, int cmd, struct shmidds *buf); DESCRIPTION shmctl() performs the control operation specified by cmd on the System V shared memory segment whose identifier is given in shmid. The buf argument is a pointer to a shmidds structure, defined in as follows: struct shmidds { struct ipcperm shmperm; /* Ownership and permissions */ sizet shmsegsz; /* Size of segment (bytes) */ timet shmatime; /* Last attach time */ timet shmdtime; /* Last detach time */ timet shmctime; /* Last change time */ pidt shmcpid; /* PID of creator */ pidt shmlpid; /* PID of last shmat(2)/shmdt(2) */ shmattt shmnattch; /* No. of current attaches */ ... }; The ipcperm structure is defined as follows (the highlighted fields are settable using IPCSET): struct ipcperm { keyt key; /* Key supplied to shmget(2) */ uidt uid; /* Effective UID of owner */ gidt gid; /* Effective GID of owner */ uidt cuid; /* Effective UID of creator */ gidt cgid; /* Effective GID of creator */ unsigned short mode; /* Permissions + SHMDEST and SHMLOCKED flags */ unsigned short seq; /* Sequence number */ }; Valid values for cmd are: IPCSTAT Copy information from the kernel data structure associated with shmid into the shmidds structure pointed to by buf. The caller must have read permission on the shared memory segment. IPCSET Write the values of some members of the shmidds structure pointed to by buf to the kernel data structure associated with this shared memory segment, updating also its shmctime member. The following fields can be changed: shmperm.uid, shmperm.gid, and (the least significant 9 bits of) shmperm.mode. The effective UID of the calling process must match the owner (shmperm.uid) or creator (shmperm.cuid) of the shared memory segment, or the caller must be privileged. IPCRMID Mark the segment to be destroyed. The segment will only actually be destroyed after the last process detaches it (i.e., when the shmnattch member of the associated structure shmidds is zero). The caller must be the owner or creator, or be privileged. If a segment has been marked for destruc‐ tion, then the (nonstandard) SHMDEST flag of the shmperm.mode field in the associated data structure retrieved by IPCSTAT will be set. The caller must ensure that a segment is eventually destroyed; otherwise its pages that were faulted in will remain in memory or swap. See also the description of /proc/sys/kernel/shmrmidforced in proc(5).

IPCINFO (Linux-specific)

Returns information about system-wide shared memory limits and parameters in the structure pointed to by buf. This structure is of type shminfo (thus, a cast is required), defined in if the GNUSOURCE feature test macro is defined: struct shminfo { unsigned long shmmax; /* Maximum segment size */ unsigned long shmmin; /* Minimum segment size; always 1 */ unsigned long shmmni; /* Maximum number of segments */ unsigned long shmseg; /* Maximum number of segments that a process can attach; unused within kernel */ unsigned long shmall; /* Maximum number of pages of

shared memory, system-wide */ }; The shmmni, shmmax, and shmall settings can be changed via /proc files of the same name; see proc(5) for details.

SHMINFO (Linux-specific) Returns a shminfo structure whose fields contain information about system resources consumed by shared memory. This structure is defined in if the GNUSOURCE fea‐ ture test macro is defined: struct shminfo {

int usedids; /* # of currently existing segments */ unsigned long shmtot; /* Total number of shared memory pages */

unsigned long shmrss; /* # of resident shared memory pages */

unsigned long shmswp; /* # of swapped shared memory pages */ unsigned long swapattempts; /* Unused since Linux 2.4 */ unsigned long swapsuccesses; /* Unused since Linux 2.4 */ };

SHMSTAT (Linux-specific) Returns a shmidds structure as for IPCSTAT. However, the shmid argument is not a segment identifier, but instead an index into the kernel's internal array that maintains infor‐ mation about all shared memory segments on the system. The caller can prevent or allow swapping of a shared memory segment with the following cmd values:

SHMLOCK (Linux-specific) Prevent swapping of the shared memory segment. The caller must fault in any pages that are required to be present after locking is enabled. If a segment has been locked, then the (nonstandard) SHMLOCKED flag of the shmperm.mode field in the associated data structure retrieved by IPCSTAT will be set.

SHMUNLOCK (Linux-specific) Unlock the segment, allowing it to be swapped out. In kernels before 2.6.10, only a privileged process could employ SHMLOCK and SHMUNLOCK. Since kernel 2.6.10, an unprivileged process can employ these operations if its effective UID matches the owner or creator UID of the segment, and (for SHMLOCK) the amount of memory to be locked falls within the RLIMITMEMLOCK resource limit (see setr‐ limit(2)). RETURN VALUE A successful IPCINFO or SHMINFO operation returns the index of the highest used entry in the kernel's internal array recording information about all shared memory segments. (This information can be used with repeated SHMSTAT operations to obtain information about all shared memory segments on the system.) A successful SHMSTAT operation returns the identifier of the shared memory segment whose index was given in shmid. Other operations return 0 on success.

On error, -1 is returned, and errno is set appropriately. ERRORS EACCES IPCSTAT or SHMSTAT is requested and shmperm.mode does not allow read access for shmid, and the calling process does not have the CAPIPCOWNER capability. EFAULT The argument cmd has value IPCSET or IPCSTAT but the address pointed to by buf isn't accessible. EIDRM shmid points to a removed identifier. EINVAL shmid is not a valid identifier, or cmd is not a valid command. Or: for a SHMSTAT operation, the index value specified in shmid referred to an array slot that is currently unused. ENOMEM (In kernels since 2.6.9), SHMLOCK was specified and the size of

the to-be-locked segment would mean that the total bytes in locked shared memory segments would exceed the limit for the real user ID of the calling process. This limit is defined by the RLIMITMEMLOCK soft resource limit (see setrlimit(2)). EOVERFLOW IPCSTAT is attempted, and the GID or UID value is too large to be stored in the structure pointed to by buf. EPERM IPCSET or IPCRMID is attempted, and the effective user ID of the calling process is not that of the creator (found in shmperm.cuid), or the owner (found in shmperm.uid), and the process was not privileged (Linux: did not have the CAPSYSADMIN capability). Or (in kernels before 2.6.9), SHMLOCK or SHMUNLOCK was speci‐ fied, but the process was not privileged (Linux: did not have the CAPIPCLOCK capability). (Since Linux 2.6.9, this error can also occur if the RLIMITMEMLOCK is 0 and the caller is not privileged.) CONFORMING TO

SVr4, POSIX.1-2001. NOTES The inclusion of and isn't required on Linux or by any version of POSIX. However, some old implementations required the inclusion of these header files, and the SVID also documented their inclusion. Applications intended to be portable to such old systems may need to include these header files. The IPCINFO, SHMSTAT and SHMINFO operations are used by the ipcs(1) program to provide information on allocated resources. In the future these may modified or moved to a /proc file system interface. Linux permits a process to attach (shmat(2)) a shared memory segment that has already been marked for deletion using shmctl(IPCRMID). This feature is not available on other UNIX implementations; portable appli‐ cations should avoid relying on it. Various fields in a struct shmidds were typed as short under Linux 2.2 and have become long under Linux 2.4. To take advantage of this, a

recompilation under glibc-2.1.91 or later should suffice. (The kernel distinguishes old and new calls by an IPC64 flag in cmd.) SEE ALSO mlock(2), setrlimit(2), shmget(2), shmop(2), capabilities(7), svipc(7) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2013-03-18 SHMCTL(2)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™