【发布时间】:2013-08-22 01:28:16
【问题描述】:
这是来自 UNP Richard Stevens 的代码副本
#include "apue.h"
#include <sys/ipc.h>
int main(int argc,char * argv[])
{
struct stat stat_buf;
if(argc != 2)
err_quit("usage ftock <pathname>");
stat(argv[1],&stat_buf);
printf("st_dev :%08lx, st_info : %08lx ,key :%08x\n",(unsigned long)stat_buf.st_dev,(unsigned long)stat_buf.st_ino,ftok(argv[1],0x57));
}
输出:
st_dev :00000803, st_ino : 018e17c3 ,key :570317c3
所以密钥从 id 获取 8 位,从 st_dev 获取 8 位,从 st_ino 获取 16 位。
我使用 SUSE gcc。
我知道这本书有点旧了。新工具有新方法。
谁能告诉我ftok工作原理?从st_ino 中选择更多位的原因是什么?
【问题讨论】: