System V IPC分为三种:node
#include <sys/ipc.h> /* Generates key for System V style IPC. */ key_t ftok (const char *pathname, int proj_id);
pathname 一般是跟本应用用关的目录;proj_id指的是本应用所用到的IPC的一个序列号;成功返回IPC键,失败返回-1;
使用ftok()须要注意的问题:编程
struct stat { dev_t st_dev; /* device */ ino_t st_ino; /* inode */ mode_t st_mode; /* protection */ nlink_t st_nlink; /* number of hard links */ uid_t st_uid; /* user ID of owner */ gid_t st_gid; /* group ID of owner */ dev_t st_rdev; /* device type (if inode device) */ off_t st_size; /* total size, in bytes */ blksize_t st_blksize; /* blocksize for filesystem I/O */ blkcnt_t st_blocks; /* number of blocks allocated */ time_t st_atime; /* time of last access */ time_t st_mtime; /* time of last modification */ time_t st_ctime; /* time of last status change */ };
获取文件属性的函数有以下几个:
int stat(const char *file_name, struct stat *buf); int fstat(int filedes, struct stat *buf); int lstat(const char *file_name, struct stat *buf);
下面经过例子来看一下如何获取:
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> int main() { const char fname[] = "main.c"; struct stat stat_info; if(0 != stat(fname, &stat_info)) { perror("取得文件信息失败!"); exit(1); } printf("文件所在设备编号:%ld\r\n", stat_info.st_dev); printf("文件所在文件系统索引:%ld\r\n", stat_info.st_ino); printf("文件的类型和存取的权限:%d\r\n", stat_info.st_mode); printf("连到该文件的硬链接数目:%d\r\n", stat_info.st_nlink); printf("文件全部者的用户识别码:%d\r\n", stat_info.st_uid); printf("文件全部者的组识别码:%d\r\n", stat_info.st_gid); printf("装置设备文件:%ld\r\n", stat_info.st_rdev); printf("文件大小:%ld\r\n", stat_info.st_size); printf("文件系统的I/O缓冲区大小:%ld\r\n", stat_info.st_blksize); printf("占用文件区块的个数(每一区块大小为512个字节):%ld\r\n", stat_info.st_blocks); printf("文件最近一次被存取或被执行的时间:%ld\r\n", stat_info.st_atime); printf("文件最后一次被修改的时间:%ld\r\n", stat_info.st_mtime); printf("最近一次被更改的时间:%ld\r\n", stat_info.st_ctime); return 0; }