Linux System Information Operations 20170330

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.