zoukankan      html  css  js  c++  java
  • IPC机制key值的各位组成

    key_t ftok(const char *_pathname, int _proj_id)

    key值的第31~24位为ftok()第二个参数的低8位;

    key值的第23~16位为ftok()第一个参数文件属性的st_dev成员的低8位;

    key值的第15~0位为ftok()第一个参数文件属性的st_ino属性的低16位。

    #include <sys/ipc.h>
    #include <sys/types.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/stat.h>
    
    int main(int argc, char *argv[])
    {
        key_t key;
        int i;
        struct stat buf;
        if(argc!=3)
        {
            printf("use: command path number
    ");
            return 1;
        }
        i=atoi(argv[2]);
        if(stat(argv[1],&buf)==-1)
        {
            perror("stat");
            exit(EXIT_FAILURE);
        }
        printf("file st_dev=%x
    ",buf.st_dev);
        printf("file st_ino=%x
    ",buf.st_ino);
        printf("number=%x
    ",i);
        key=ftok(argv[1],i);
        printf("key=0x%x	key>>24=%x	key&0xffff=%x	(key>>16)&0xff=%x
    ",key,key>>24,key&0xffff,(key>>16)&0xff);
        return 0;
    
    }

  • 相关阅读:
    命名规范
    操作文件和目录
    使用本地shadow socks代理
    发送邮件
    sql参数化
    定义常量
    获取嵌套字典值的方法
    通过字符串调用函数
    用字典优化过长的if 语句
    操作文件和目录
  • 原文地址:https://www.cnblogs.com/lakeone/p/3784582.html
Copyright © 2011-2022 走看看