brief introduction ： In this section we will briefly introduce Linux Some data in the system are .（ ad locum 、 Let's just give a few examples ）
1：passwd Data files and group files .
a： First of all, let's introduce passwd Data files , This data file is stored in /etc/passwd In the file directory . The data in this file may have the following contents .
notes ： Because of different systems , The entries displayed in the key file may be different . Here's a special example ： That's how we organize for login , Here are a few ways . 1>： The shell Switch to /bin/false. 2>： The shell Switch to /bin/nologin.（ The user can be allowed to use ftp Etc ） 3>： Use command usermod -s /sbin/nologin . Next 、 Let's introduce some functions about key files . struct passwd *getpwuid(uid_t uid); struct passwd* getpwnam(const char* name); These two functions are based on the user's ID And name to get some information about the user , Please refer to ｍａｎ manual 、 I won't go into details here . And then again , Let's introduce a few functions about viewing the entire password file . struct passwd* getpwent(); void setpwent(); void endpwent(); The first function is to get the next entry in the password file , It returns a filled passwd Pointer to structure , The second function resets the file location to the beginning of the file . The third function is to release the resources that the file is .
2： System identification , Get some information about the system .
The function prototype ： int uname(struct utsname *name); This function gets some information about the system . On the terminal we can use uname Command to get some information .
3： Next 、 We're going to talk about time-dependent functions .
Here we mainly introduce the functions related to time and date . time_t time(time_t *calptr);// Return with time and date , If the parameters are not empty rings , Save the time and date to the memory space pointed by the parameter . int gettimeofday(struct timeval* tp, void* tzp);// Return to a more precise time , What he returns is the execution time of the program . meanwhile 、 We're getting this time in seconds 、 We also need to convert this kind of time into various forms of time, such as month, day, etc . meanwhile struct tm The structure is represented by year, year, day, hour, minute and second Time , We can also convert this time into other time . As shown in the figure below , Conversion of various time formats .
ad locum , Let's list all the function prototypes .