關於錯誤"ftok: No such file or directory"
在使用ftok時候遇到了以下的錯誤
ftok: No such file or directory
解決方式:創建一個文件或者文件夾
比如代碼中
if((key = ftok("./ap", 123)) < 0){
perror("ftok");
return 0;
}
那么就需要在當前文件夾下創建一個文件夾(mkdir ap)或者文件(touch ap)
ftok的簡單介紹
函數原型:key_t ftok(const char *pathname, int proj_id);
-
pathname: 存在的目錄或是文件的具體路徑
-
proj_id: 在UNIX系統上,它的取值是1到255;
作用: 共享內存、消息隊列、信號量都要找一個中間介質來進行通信的,而ftok()作用正是產生這個中間介質的,具體的說,中間介質是pathname,然后ftok可以根據pathname來產生一個key,這個key相當與是通信ID,可以用來避免沖突。