嵌入式学习day23 Linux

时间获取:

1.time

time_t time(time_t *tloc);

功能:

返回1970-1-1到现在的秒数(格林威治时间)

参数:

tloc:存放秒数空间首地址

返回值:

成功返回秒数

失败返回-1

2.localtime

struct tm *localtime(const time_t *timep);

功能:

将秒数转换为本地时间

参数:

timep:存放秒数空间首地址

返回值:

成功返回结构体时间

失败返回NULL

struct tm {

int tm_sec; /* Seconds (0-60) */

int tm_min; /* Minutes (0-59) */

int tm_hour; /* Hours (0-23) */

int tm_mday; /* Day of the month (1-31) */

int tm_mon; /* Month (0-11) */

int tm_year; /* Year - 1900 */

int tm_wday; /* Day of the week (0-6, Sunday = 0) */

int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */

int tm_isdst; /* Daylight saving time */

};

3.mktime

time_t mktime(struct tm *tm);

功能:

将本地时间转换为秒数

文件属性和权限的获取:

1.stat

int stat(const char *pathname, struct stat *statbuf);

功能:

将pathname对应的文件信息放入statbuf中

参数:

pathname:文件路径字符串的首地址

statbuf:存放文件信息空间的首地址

返回值:

成功返回0

失败返回-1

struct stat {

dev_t st_dev; /* ID of device containing file */

ino_t st_ino; /* Inode number */

mode_t st_mode; /* File type and mode */

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. */

struct timespec st_atim; /* Time of last access */

struct timespec st_mtim; /* Time of last modification */

struct timespec st_ctim; /* Time of last status change */

#define st_atime st_atim.tv_sec /* Backward compatibility */

#define st_mtime st_mtim.tv_sec

#define st_ctime st_ctim.tv_sec

};

/etc/passwd 口令文件

/etc/group 组信息文件

2.getpwuid

struct passwd *getpwuid(uid_t uid);

功能:

通过UID获得对应的用户信息

参数:

uid:用户的ID号

返回值:

成功返回包含用户信息的结构体

失败返回NULL

struct passwd {

char *pw_name; /* username */

char *pw_passwd; /* user password */

uid_t pw_uid; /* user ID */

gid_t pw_gid; /* group ID */

char *pw_gecos; /* user information */

char *pw_dir; /* home directory */

char *pw_shell; /* shell program */

};

3.getgrgid

struct group *getgrgid(gid_t gid);

功能:

通过组ID获得组信息

参数:

gid:组的ID号

返回值:

成功返回包含组信息的结构体

失败返回NULL

struct group {

char *gr_name; /* group name */

char *gr_passwd; /* group password */

gid_t gr_gid; /* group ID */

char **gr_mem; /* NULL-terminated array of pointers

to names of group members */

};

4.readlink

ssize_t readlink(const char *pathname, char *buf, size_t bufsiz);

功能:

读取连接文件本身的内容

参数:

pathname:链接文件的路径

buf:存放数据空间首地址

bufsiz:最大存放数据字节数

返回值:

成功返回读到字节个数

失败返回-1

软连接和硬链接:

1.软连接(符号链接)

通过文件名链接,所有能够看到的连接文件均为软连接文件

ln -s file.txt a.txt

2.硬链接

通过文件对应的inode节点链接

ln file.txt b.txt

相关推荐
java1234_小锋19 小时前
Scikit-learn Python机器学习 - 分类算法 - K-近邻(KNN)算法
python·算法·机器学习
智者知已应修善业19 小时前
【矩阵找最大小所在位置】2022-11-13
c语言·c++·经验分享·笔记·算法·矩阵
shan&cen19 小时前
Day04 前缀和&差分 1109. 航班预订统计 、304. 二维区域和检索 - 矩阵不可变
java·数据结构·算法
手握风云-19 小时前
回溯剪枝的 “减法艺术”:化解超时危机的 “救命稻草”(二)
算法·机器学习·剪枝
存储服务专家StorageExpert19 小时前
手搓一个 DELL EMC Unity存储系统健康检查清单
linux·运维·服务器·存储维护·emc存储
_hermit:19 小时前
【从零开始java学习|小结】记录学习和编程中的问题
java·学习
QiZhang | UESTC19 小时前
JAVA算法练习题day11
java·开发语言·python·算法·hot100
屁股割了还要学19 小时前
【数据结构入门】排序算法(4)归并排序
c语言·数据结构·学习·算法·排序算法
笑口常开xpr20 小时前
Linux 库开发入门:静态库与动态库的 2 种构建方式 + 5 个编译差异 + 3 个加载技巧,新手速看
linux·c语言·动态库·静态库
努力学习的小廉20 小时前
我爱学算法之—— 位运算(上)
c++·算法