shmctl() - Unix, Linux System Call

Unix - Home
Unix - Getting Started
Unix - File Management
Unix - Directories
Unix - File Permission
Unix - Environment
Unix - Basic Utilities
Unix - Pipes & Filters
Unix - Processes
Unix - Communication
Unix - The vi Editor
Unix - What is Shell?
Unix - Using Variables
Unix - Special Variables
Unix - Using Arrays
Unix - Basic Operators
Unix - Decision Making
Unix - Shell Loops
Unix - Loop Control
Unix - Shell Substitutions
Unix - Quoting Mechanisms
Unix - IO Redirections
Unix - Shell Functions
Unix - Manpage Help
Unix - Regular Expressions
Unix - File System Basics
Unix - User Administration
Unix - System Performance
Unix - System Logging
Unix - Signals and Traps
Unix - Useful Commands
Unix - Quick Guide
Unix - Builtin Functions
Unix - System Calls
Unix - Commands List
Unix Useful Resources
Computer Glossary
Who is Who
Copyright © 2014 by tutorialspoint

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


The
buf argument is a pointer to a shmid_ds structure,
defined in <sys/shm.h> as follows:




struct shmid_ds {
    struct ipc_perm shm_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()/shmdt() */
    shmatt_t        shm_nattch;  /* No. of current attaches */
    ...
};


The
ipc_perm structure is defined in <sys/ipc.h> as follows
(the highlighted fields are settable using
IPC_SET): 



struct ipc_perm {
    key_t key;            /* Key supplied to shmget() */
    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 */
    unsigned short mode;  /* Permissions + SHM_DEST and
                             SHM_LOCKED flags */
    unsigned short seq;   /* Sequence number */
};


Valid values for
cmd are:



struct  shminfo {
    unsigned long shmmax; /* Max. segment size */
    unsigned long shmmin; /* Min. segment size; always 1 */
    unsigned long shmmni; /* Max. # of segments */
    unsigned long shmseg; /* Max. # of segments that a
                             process can attach; unused */
    unsigned long shmall; /* Max. # of pages of shared
                             memory, system-wide */
};




struct  shminfo {
    unsigned long shmmax; /* Max. segment size */
    unsigned long shmmin; /* Min. segment size; always 1 */
    unsigned long shmmni; /* Max. # of segments */
    unsigned long shmseg; /* Max. # of segments that a
                             process can attach; unused */
    unsigned long shmall; /* Max. # of pages of shared
                             memory, system-wide */
};






struct shm_info {
    int used_ids;           /* # of currently existing
                               segments */
    unsigned long shm_tot;  /* Total number of shared
                               memory pages */
    unsigned long shm_rss;  /* # of resident shared
                               memory pages */
    unsigned long shm_swp;  /* # of swapped shared
                               memory pages */
    unsigned long swap_attempts;  /* Unused since Linux 2.4 */
    unsigned long swap_successes; /* Unused since Linux 2.4 */
};




struct shm_info {
    int used_ids;           /* # of currently existing
                               segments */
    unsigned long shm_tot;  /* Total number of shared
                               memory pages */
    unsigned long shm_rss;  /* # of resident shared
                               memory pages */
    unsigned long shm_swp;  /* # of swapped shared
                               memory pages */
    unsigned long swap_attempts;  /* Unused since Linux 2.4 */
    unsigned long swap_successes; /* Unused since Linux 2.4 */
};





On error, -1 is returned, and
errno is set appropriately.


Or (in kernels before 2.6.9),
SHM_LOCK or
SHM_UNLOCK was specified, but the process was not privileged
(Linux: did not have the
CAP_IPC_LOCK capability).
(Since Linux 2.6.9, this error can also occur if the
RLIMIT_MEMLOCK is 0 and the caller is not privileged.)


Linux permits a process to attach
(shmat()) a shared memory segment that has already been marked for deletion
using
shmctl(IPC_RMID). This feature is not available on other Unix implementations;
portable applications should avoid relying on it.


Various fields in a struct shmid_ds were shorts under Linux 2.2
and have become longs 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 IPC_64 flag in
cmd.) 
mlock (2)
mlock (2)
setrlimit (2)
setrlimit (2)
shmget (2)
shmget (2)
shmop (2)
shmop (2)

Advertisements


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page