IPC key chose 8 bits from st_dev and 16 bits from st_ino
This is a code copy from 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));
}
Output:
st_dev :00000803, st_ino : 018e17c3 ,key :570317c3
So the key take 8 bit from id , 8 bit from st_dev and 16 bit from st_ino.
I use SUSE gcc .
I know the book is kind of old. new implement had its new method.
Can anyone tell me the principle of ftok works? And the reason choose more
bits from st_ino?
No comments:
Post a Comment