Linux/UNIX系统数据文件和信息

本文发布时间: 2019-Mar-22
系统数据文件和信息口令文件存储在/etc/passwd中,可用以下函数获取口令文件项。#include <sys/types.h>#include <pwd.h>struct passwd *getpwnam(const char *name);struct passwd *getpwuid(uid_t uid);如果要查看的只是登录名或用户ID,上述两个函数能满足要求,但有些程序要查看整个口令文件。下面三个函数可用于此种目的。#include <sys/types.h>#include <pwd.h>struct passwd *getpwent(void);void setpwent(void);void endpwent(void);阴影口令阴影口令文件:存放加密口令以下函数用于访问阴影口令文件:#include <shadow.h>struct spwd *getspnam(const char *name);struct spwd *getspent(void);void setspent(void);void endspent(void);组文件以下函数用来查看组名或数值组ID#include <sys/types.h>#include <grp.h>struct group *getgrnam(const char *name);struct group *getgrgid(gid_t gid);如需搜索整个组文件,可用以下是三个函数:#include <sys/types.h>#include <grp.h>struct group *getgrent(void);void setgrent(void); void endgrent(void);附加组ID为获取和设置附加组ID,可用如下三个函数#include <sys/types.h>#include <unistd.h>int getgroups(int size, gid_t list[]);#include <grp.h>#include <unistd.h>int setgroups(size_t size, const gid_t*list);#include <sys/types.h>#include <grp.h>int initgroups(const char *user, gid_tgroup);时间和日期例程#include <time.h>time_t time(time_t *t);该函数用于返回当前时间和日期。#include <sys/time.h>int gettimeofday(struct timeval *tv, structtimezone *tz);上述函数也用于获取当前时间和日期,不过其分辨率更高(最高为微秒级)。 #include <time.h>double difftime(time_t time1, time_ttime0);该函数用于计算两个时间值之间的差,并将time1-time2的值作为浮点数返回。


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:10pm
栏目列表