[ 永远的UNIX::UNIX技术资料的宝库 ]

首页 > 编程技术 > 其它 > 正文
Linux程式设计-23.共享记忆体(Shared Memory)
http://www.openchess.org/noitatsko/programming/ (2001-05-27 14:08:00)
共享记忆体是指同一块记忆体区段被一个以上的行程所分享。这是我们所知速度最快的行程间通讯方式。使用共享记忆体在使用多CPU的机器上,会使机器发挥较佳的效能。 

--------------------------------------------------------------------------------

#include  
#include  
int shmget(key_t key, int size, int shmflg); 
char *shmat ( int shmid, char *shmaddr, int shmflg ) 
int shmdt ( char *shmaddr) 
int shmctl(int shmid, int cmd, struct shmid_ds *buf); 

        struct shmid_ds { 
                struct ipc_perm shm_perm;        /* operation perms */ 
                int     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 */ 
                unsigned short  shm_cpid;        /* pid of creator */ 
                unsigned short  shm_lpid;        /* pid of last operator */ 
                short   shm_nattch;              /* no. of current attaches */ 

                                                 /* the following are private */ 

                unsigned short   shm_npages;     /* size of segment (pages) */ 
                unsigned long   *shm_pages;      /* array of ptrs to frames -> SHMMAX */ 
                struct vm_area_struct *attaches; /* descriptors for attaches */ 
        }; 

shm_perm 

   This is an instance of the ipc_perm structure, which is defined for us in 
   linux/ipc.h. This holds the permission information for the segment, 
   including the access permissions, and information about the creator of the 
   segment (uid, etc). 

shm_segsz 

   Size of the segment (measured in bytes). 

shm_atime 

   Time the last process attached the segment. 

shm_dtime 

   Time the last process detached the segment. 

shm_ctime 

   Time of the last change to this structure (mode change, etc). 

shm_cpid 

   The PID of the creating process. 

shm_lpid 

   The PID of the last process to operate on the segment. 

shm_nattch 

   Number of processes currently attached to the segment. 
(http://www.fanqiang.com)
    进入【UNIX论坛

相关文章
Linux程式设计-31.工作群资讯管理(grp) (2001-05-27 22:08:00)
Linux程式设计-30.使用者资讯管理(pwd) (2001-05-27 21:04:00)
Linux程式设计-29.时间处理 (2001-05-27 20:10:01)
Linux程式设计-28.GNU Make (2001-05-27 19:00:00)
Linux程式设计-27.GNU Debugger (2001-05-27 18:08:01)
Linux程式设计-26.PIPE (2001-05-27 17:04:00)
Linux程式设计-25.Message Queues (2001-05-27 16:10:00)
Linux程式设计-24.Semaphores (2001-05-27 15:00:00)
Linux程式设计-23.共享记忆体(Shared Memory) (2001-05-27 14:08:00)
Linux程式设计-20.getopt (2001-05-27 13:04:00)

===更多相关===
 

★  樊强制作 欢迎分享  ★