• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Prayer

            在一般中尋求卓越
            posts - 1256, comments - 190, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            ftok點滴

            Posted on 2008-08-21 20:05 Prayer 閱讀(677) 評論(0)  編輯 收藏 引用 所屬分類: LINUX/UNIX/AIX
            1, Redhat9.0的man手冊
            FTOK(3)                                         Linux Programmers Manual                          
            NAME
                   ftok - convert a pathname and a project identifier to a System V IPC key
            SYNOPSIS
                   # include <sys/types.h>
                   # include <sys/ipc.h>
                   key_t ftok(const char *pathname, int proj_id);
            DESCRIPTION
                   The  ftok  function  uses  the  identity of the file named by the given pathname (which must refer to an existing,
                   accessible file) and the least significant 8 bits of proj_id (which must be nonzero) to generate a key_t type Sys-
                   tem V IPC key, suitable for use with msgget(2), semget(2), or shmget(2).
                   The resulting value is the same for all pathnames that name the same file, when the same value of proj_id is used.
                   The value returned should be different when the (simultaneously existing) files or the project IDs differ.
            RETURN VALUE
                   On success the generated key_t value is returned. On failure -1 is returned, with errno indicating  the  error  as
                   for the stat(2) system call.
             

            2, 參數(shù)說明
                   pathname必須存在且可以訪問,如果是32位系統(tǒng),屢次返回為4294967295時請注意,它實際是16進(jìn)制的FFFFFFFF,換成2進(jìn)制就是32個1,計算機一般采用補碼表示,最高位(復(fù)用的)1表示它是個負(fù)數(shù), 對它進(jìn)行取反再加1(考慮是負(fù)數(shù))得到-1, 也就是說ftok調(diào)用失敗。對于其他位數(shù)的系統(tǒng)類似。
             
             
            3,dos格式和unix格式轉(zhuǎn)換問題
                   由于dos的回車換行和unix的不太一樣,有可能導(dǎo)致pathname找不到。
             
             
            4,The resulting value is the same for all pathnames that  name  the  same file, when the same value of proj_id is used.
                   一般來說,ftok對應(yīng)文件的inode,因此,無論多少連接,指向的都是同一個inode。
             
             
            5,在一般的UNIX實現(xiàn)中,是將文件的索引節(jié)點號取出,前面加上子序號得到key_t的返回值。
            如指定文件的索引節(jié)點號為65538,換算成16進(jìn)制為0x010002,而你指定的ID值為38,換算成16進(jìn)制為0x26,則最后的key_t返回值為0x26010002。
            查詢文件索引節(jié)點號的方法是: ls -i
            當(dāng)刪除重建文件后,索引節(jié)點號由操作系統(tǒng)根據(jù)當(dāng)時文件系統(tǒng)的使用情況分配,因此與原來不同,所以得到的索引節(jié)點號也不同。
            如果要確保key_t值不變,要目確保ftok的文件不被刪除,要么不用ftok,指定一個固定的key_t值。
            另外說一句:在aix等操作系統(tǒng)上,有多個文件系統(tǒng),會出現(xiàn)分布在不同的文件系統(tǒng)上的兩個文件具有相同的索引節(jié)點號,此時用ftok對這兩個文件進(jìn)行操作,只要id參數(shù)不變,得到的key_t值相同,造成創(chuàng)建消息隊列失敗。不過這種情況相當(dāng)少見罷了。
             
             
            6,也有人說如果pathname是二進(jìn)制文件,則ftok會完全破壞該文件,我沒有測試過,所以不知道是真是假。

            久久精品国产99国产电影网| 狠狠精品久久久无码中文字幕| 精品久久久久久久久久久久久久久| 大美女久久久久久j久久| 亚洲欧美一级久久精品| yy6080久久| 91精品国产综合久久婷婷| 热久久国产欧美一区二区精品| 久久综合色区| 亚洲精品国产美女久久久| 久久精品亚洲精品国产色婷| 国产精品久久久久久久久鸭| 亚洲国产精品热久久| 久久久久国产成人精品亚洲午夜| 久久亚洲精品无码播放| 一本色道久久88精品综合| 97久久精品无码一区二区| 久久久WWW成人免费精品| 蜜臀av性久久久久蜜臀aⅴ | 麻豆亚洲AV永久无码精品久久 | 久久人与动人物a级毛片| 三级三级久久三级久久| 久久99精品综合国产首页| 91精品国产综合久久久久久| 久久se精品一区二区影院| 午夜精品久久久久久久久| 久久99免费视频| 亚洲AV无码久久精品色欲| 国产成人精品久久综合| 天堂无码久久综合东京热| 久久av无码专区亚洲av桃花岛| 久久青青国产| 精品国产一区二区三区久久| 美女久久久久久| 亚洲国产精品久久久久网站 | 伊人久久大香线蕉av不卡| 久久婷婷国产综合精品| 伊人色综合久久天天网| 久久久亚洲精品蜜桃臀| 老司机国内精品久久久久| 久久人人爽人人爽人人片AV不|