您的位置:首页 > 运维架构

20121025总结——system call ——write,read,open,close,fstat

2013-09-18 21:13 357 查看
the theme of today : file opeartation

1.要想真的掌握还是需要花一点功夫。
《Linux环境高级编程》 《Linux程序设计》(这本书要看完)
2.下来后大家一定要多去看,因为操作系统这一部分呢一定要多去体会,去琢磨,去理解。

3.@search: poszx program rules
4.@search: API function, system call library function

5.about most of the OS the virtual space: 1G kernel space, 3G user space

6.user space: user program and lib function in user peogram
|
| call
V
kernel space:system call and kernel and drivers program in kernel

7.user mod -->user -->目态
kernel mod -->superrise -->管态

8.the second part of man datasheet is system function

9.文件描述符:file descriptor
head: #include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags)
int open(const char *pathname, int flags, mode_t mode) -->O_CREAT
return value: file descriptor -->success
or -1 -->fail
10.设备和文件的统一性时,可能会出现打开文件失败。因为可能有别的用户正在使用。

11.@man: exit() -->ask how to man

12.在main函数之前会有一段汇编程序先执行

13.exit(main()) -->ask what to do

14.truncated: a. 切短的, 缩短了的, 截短的, 削去尖角的
【计】 截去的

15. alter: change

16. optional: can choose
indicates

17.#man 2 read -> system function
#man 3 read -> system function

18. UNIX 是一套标准
Linux 是UNIX这套标准的一个实现

19.阻塞:
当一个程序因为一些原因不能继续进行。则称为阻塞。

20. 管道:echo hello the | ./test

定向:./test < test.c

21.每周总结这周学的东西。每周要魔鬼的训练自己。

22. @man fsync <-强制将数据真正写到磁盘或者其他下层设备上
@man lseek fseek ftrunc

23.文件在计算机中分成三部分:文件名, inode文件信息节点, 文件内容
@man stat ->将获取的文件状态保存到缓冲区 int stat(const char *path, struct stat *buf);
@man fstat ->

struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
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 ID (if special file) */ //设备文件
off_t st_size; /* total size, in bytes */ //文件的大小
blksize_t st_blksize; /* blocksize for file system I/O */ //文件块的大小,所有的文件在磁盘上都是以块存在的。
blkcnt_t st_blocks; /* number of 512B 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 */ //最后状态改变时间。//状态保存在inode中,修改inode将会改变。
};

root 的id号为0
其他的用户,id号是从500开始的。

查看文件信息的方式:
#ll test.c
或者: #stat test.c
24. 缓冲带来的好处:

检查方法:time ./test

25. > 的用法:
将很多的文件拷贝到文件里去:
cat mstat.c open.c test.c >file.in
拷一次:cat mstat.c > test
cat open.c > test

26. #ls -l 显示目录下文件的具体信息 -->
访问权限:指向该文件的链接数:等等
#ls -lh 区别与#ls -l 将文件的大小以bit显示,#ls -lh 将文件的大小以KB显示。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐