黑马《linux基础编程》学习笔记(66到70)

六十六. 文件描述符表

内核里的pcb进程控制块,负责进程控制

 

 六十七. open函数的使用

 

 这里我们建立了一个open.c的文件

  1 #include <sys/types.h>
  2 #include <sys/stat.h>
  3 #include <fcntl.h>
  4 #include <stdio.h>
  5 #include <unistd.h>
  6
  7 int main(int argc, const char* argv[])
  8 {
  9     //打开一个文件hello
 10     int fd = open("hello", O_RDWR | O_CREAT, 0777);
 11     if(fd ==-1)
 12     {
 13         printf("Failed to open this!\n");
 14     }
 15
 16     close(fd);
 17
 18     return 0;
 19 }

 接下来运行命令

[root@VM_0_15_centos FileIO]# gcc open.c -o open
[root@VM_0_15_centos FileIO]# ls
Block  english.txt  open  open.c
[root@VM_0_15_centos FileIO]# ./open
[root@VM_0_15_centos FileIO]# ls
Block  english.txt  hello  open  open.c
[root@VM_0_15_centos FileIO]# ll
total 128
drwxr-xr-x 2 root root   4096 Dec 15 07:26 Block
-rw-r--r-- 1 root root 109055 Dec 15 07:26 english.txt
-rwxrwxr-x 1 root root      0 Dec 17 03:18 hello
-rwxrwxr-x 1 root root   8616 Dec 17 03:18 open
-rw-rw-r-- 1 root root    304 Dec 17 03:18 open.c
[root@VM_0_15_centos FileIO]# umask
0002

 注意到hello文件并不是满权限,这是因为O_CRET创造出的权限是mode & ~umask

 

 六十八, read, write函数介绍

 

 六十九. 学习目标

 七十. makefile复习

猜你喜欢

转载自blog.csdn.net/garrulousabyss/article/details/85043265