env export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/dachuang/Downloads/CppWeb/Lesson06/library/lib echo$LD_LIBRARY_PATH ldd main
# path will disappear after close path # user level setting vim .bashrc export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/dachuang/Downloads/CppWeb/Lesson06/library/lib
File* fp int _fileno; char* _IO_read_ptr; /* Current read pointer */ char* _IO_read_end; /* End of get area. */ char* _IO_read_base; /* Start of putback+get area. */ char* _IO_write_base; /* Start of put area. */ char* _IO_write_ptr; /* Current put pointer. */ char* _IO_write_end; /* End of put area. */ char* _IO_buf_base; /* Start of reserve area. */ char* _IO_buf_end; /* End of reserve area. */ /* The following fields are used to support backing up and undo. */ char *_IO_save_base; /* Pointer to start of non-current get area. */ char *_IO_backup_base; /* Pointer to first valid character of backup area */ char *_IO_save_end; /* Pointer to end of non-current get area. */
虚拟地址空间
MMU 虚拟地址映射到真实地址 0-3G 用户区
0-4k 保护区
.text
data
heap 由低到高
Stack < heap 由高到低
Args 3G-4G内核区
内存管理
进程管理
设备驱动
Virtual File System
文件描述符
PCB 文件描述符表 1024
0 STDIN_FILENO 1 STDOUT_FILENO 2 STDERR_FILENO
Fopen 同一个文件的文件描述符不同,打开最小的文件描述符
open创建新文件
1 2
man 2 open umask 022 # set umask
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/** @param flags: O_RDONLY, O_WRONLY, O_RDWR optionly O_CREAT @param mode: mode(oct num rwxrwxrwx) of file is (mode & ~umask) int open(const char *pathname, int flags, mode_t mode); */ #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<stdio.h> #include<unistd.h> intmain() { int fd = open("create.txt", O_RDWR | O_CREAT, 0777); if (fd==-1) perror("open"); close(fd); return0; }
intstat(constchar *pathname, struct stat *statbuf); intfstat(int fd, struct stat *statbuf); intlstat(constchar *pathname, struct stat *statbuf);
truct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* Inode number */ mode_t st_mode; /* File type and mode */ 0-2: others 3-5: group 6-8: user 9-11:特殊权限位 12-15:文件类型 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; /* Block size for filesystem I/O */ blkcnt_t st_blocks; /* Number of 512B blocks allocated */ /* Since Linux 2.6, the kernel supports nanosecond precision for the following timestamp fields. For the details before Linux 2.6, see NOTES. */
structtimespecst_atim;/* Time of last access */ structtimespecst_mtim;/* Time of last modification */ structtimespecst_ctim;/* Time of last status change */
#include<unistd.h> /** The dup() system call creates a copy of the file descriptor oldfd, using the lowest-numbered unused file descriptor for the new descriptor. */ intdup(int oldfd); /** The dup2() system call performs the same task as dup(), but instead of using the lowest-numbered unused file descriptor, it uses the file descriptor number specified in newfd. If the file descriptor newfd was previously open, it is silently closed before being reused. */ intdup2(int oldfd, int newfd);
/** fcntl() performs one of the operations described below on the open file descriptor fd. The operation is determined by cmd. */ intfcntl(int fd, int cmd, ... /* arg */ );