[ 永遠的UNIX::UNIX技術資料的寶庫 ]   GB | BIG5

首頁 > 編程技術 > 其它 > 正文
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)

===更多相關===
 

★  樊強制作 歡迎分享  ★