69,371
社区成员
发帖
与我相关
我的任务
分享
a-/home/a/etc/ipckey>ls -li
2097174 -rwxrw-r--. 1 a a 0 Sep 22 2013 comm
程序调试:
64 sprintf(strPath,"%s/etc/ipckey/comm",getenv("HOME"));
(gdb) p strPath
$1 = "/home/a/etc/ipckey/comm", '\000' <repeats 91 times>
(gdb) n
67 if ((ilShareKey = ftok(strPath,1)) == (key_t)-1)
(gdb) p ilShareKey
$2 = 16908310
用户b:
b-/home/b/etc/ipckey>ls -li
2228246 drwxr-xr-x. 2 b b 4096 Sep 22 2013 trnlog
程序调试:
64 sprintf(strPath,"%s/etc/ipckey/trnlog",getenv("HOME"));
(gdb) p strPath
$1 = "/home/b/etc/ipckey/trnlog", '\000' <repeats 89 times>
(gdb) n
67 if ((ilShareKey = ftok(strPath,1)) == (key_t)-1)
(gdb) p ilShareKey
$2 = 16908310
key = ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((proj_id & 0xff) << 24));
用户a:
a-/home/a/etc/ipckey>stat -c "%i %d" comm
2097174 64770
用户b:
b-/home/b/etc/ipckey>stat -c "%i %d" trnlog
2228246 64770
按照ftok的实现经过计算,的确得出相同的结果。
所以说,ftok的使用不只是大家所说的,如果生成key值的文件在使用,不允许删除重建,否则会出现意想不到的问题;而且,相同的机器,我们也需要注意我遇到的这种情况。
通过以上,我明白了ftok产生的问题,让我纠结了几天的问题。 ~~~结贴~~~