1.函数creat 可以使用creat函数创建一个新文件. #include<fcntl.h> int creat(const char *path, mode_t mode); 返回值: 若成功,返回为只写打开的文件描述符: 若失败,返回- 上述函数原型等价于: open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); 使用creat函数的一个不足之处是它以只写的凡是打开创建的新文件.在没有open新版本函数之前,如果要创建一个临时文件,并要先写该文件,…
4.2 文件函数 #include <sys/stat.h> int stat(const char *restrict pathname, struct stat *restrict buf ); int fstat(int fd, struct stat *buf ); int lstat(const char *restrict pathname, struct stat *restrict buf ); int fstatat(int fd, const char *restrict…
获取文件属性 #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> int stat(const char *pathname, struct stat *buf); int fstat(int fd, struct stat *buf); int lstat(const char *pathname, struct stat *buf); #include <fcntl.h> #i…
apue第七章学习总结 1.main函数 程序是如何执行有关的c程序的? C程序总是从main函数开始执行.main函数的原型是 int main(int argc,char *argv[]); 其中,argc是命令行参数的数目,argv是指向参数的各个指针所构成的数组. 当内核执行C程序时(使用一个exec函数),在调用main前先调用一个特殊的启动例程.可执行程序文件将此启动例程指定为程序的起始地址--这是由连接编辑器设置的,而连接编辑器则由C编译器(通常是cc)调用.启动例程从内核取得命令…
本章将描述文件系统的其他特性和文件的性质. 函数stat.fstat.fstatat和lstat #include <sys/stat.h> int stat(const char *restrict pathname,struct stat *restrict buf); int fstat(int fd,struct stat *buf); int lstat(const char *restrict pathname,struct stat *restrict buf); int fst…
在给出用户登录名或数值用户ID后,这两个函数就能查看相关项. #include <sys/types.h> #include <pwd.h> struct passwd *getpwuid(uid_t uid); struct passwd *getpwnam(const char *name); 两个函数返回值:成功返回指针,出错返回NULLuid:需要获取信息的uid号 getpwuid例程 #include <pwd.h> #include <sys/typ…
1.文件共享 UNIX系统支持在不同的进程间共享打开文件.为了说明这种共享,以下介绍内核用于所有I/O的数据结构. 内核使用3种数据结构表示打开文件,它们之间的关系决定了在文件共享方面一个进程对另一个进程可能产生的影响. (1)每个进程在进程表中都有一个记录项,记录项中包含一张打开文件描述符表,可将其视为一个矢量每个描述符占用一项.与每个文件描述符相关联的是: 文件描述符标志: 指向一个文件表项的指针. (2)内核为所有打开文件维护一张文件表.每个文件表项包含: 文件状态标志(读.写.添加.同步…
4 - 文件和目录 1. 函数 stat.fstat.fstatat 和 lstat #inlcude <sys/stat.h> int stat(const char *restrict pathname, struct stat *restrict buf); int fstat(int fd, struct stat *buf); int lstat(const char *restrict pathname, struct stat *restrict buf); int fstata…
3 - 文件I/O Github 地址 1. 文件描述符 对于内核而言,所有打开的文件都通过 文件描述符 (file descriptor) 引用.当打开一个现有文件或创建一个新文件时,内核向进程返回一个文件描述符.当读.写一个文件时,使用 open 或 creat 返回的文件描述符标识该文件,将其作为参数传送给 read 或者 write . UNIX系统shell把 文件描述符 \(0\) 与进程的标准输入( STDIN_FILENO )关联,文件描述符 \(1\) 与标准输出( STDOU…
apue第六章学习总结 1.关于阴影文件与口令 在口令文件当中,常见的字段有(以root为例): root(用户名):x(加密口令):0(uid):0(gid):root(注释字段):/root(用户所在根目录):/bin/bash(用户的shell所在目录) 注意:这里的加密口令只是一个占位符号,真正的加密口令存于阴影文件当中,阴影口令文件不应是一般用户可以读取的.仅有少数几个程序需要存取加密口令,例如login(1)和passwd(1),这些程序常常是设置用户ID为root的程序.用了阴影口…