Advertisement

编程共享内存--mmap shmget 两种方式实现

阅读量:

mmapread.c

复制代码
    #include <stdio.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <sys/mman.h>
    #include <unistd.h>
    #include <semaphore.h>
    #include <string.h>
    #include <errno.h>
    
    
    
    int main(int argc,char **argv)
    {
    int shm_id;
    char *ptr;
    sem_t *sem;
    
    if (argc!=2)
    {
        printf("usage:shm_open<pathname>\n");
        return -1;
    }
    
    shm_id=shm_open(argv[1],O_RDWR|O_CREAT,0644);/*第一步:创建共享内存区*/
    if (shm_id==-1)
    {
        printf( "open shared memory error.errno=%d,desc=%s.\n", errno, strerror(errno));

全部评论 (0)

还没有任何评论哟~