This paper introduces some information acquisition operations in Linux system, and then finds the system information structure in the source code.
1, System Information structure description and access method:
Meaning:
struct SysInfo {
Long uptime; /* Start to the current elapsed time */
unsigned long loads[3];
/* 1, 5, and minute load averages */
unsigned long totalram; /* Total available memory size */
unsigned long freeram; /* Memory size not yet in use */
unsigned long sharedram; /* The size of the shared memory */
unsigned long bufferram; /* The size of the shared memory */
unsigned long totalswap; /* Swap Area Size */
unsigned long freeswap; /* Swap area size Available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* High memory size available */
unsigned int mem_unit; /* Memory size in bytes */
Char _f[20-2*sizeof (long)-sizeof (int)];
/* Patch for LIBC5
};
Get method:
struct SysInfo s_info;//System Information Structure body
memset (&s_info, 0, sizeof (s_info));
SysInfo (&s_info);//Get System Information
2. File Query Access function
Defined:
int access (const char * pathname, int mode);
Function Description:
Access () checks whether a file that already exists can be read/written. The parameter mode has several case combinations, R_OK,W_OK,X_OK and F_OK. R_OK,W_OK and X_OK are used to check whether a file has read, write, and execute permissions. The F_OK is used to determine whether the file exists. Because Access () only checks for permissions, ignores file patterns or file contents, if a directory is represented as "writable", it means that operations such as creating new files in the directory can be made, rather than implying that the directory can be treated as a file. For example, you will find that DOS files have "executable" permissions, but will fail when executed with EXECVE ().
How to use:
if (Access ("/var/run/wpa_supplicant/wlan0", 0) = = 0)//query whether a readable file exists
Linux System Information Operations 20170330