CN103279360A - Method for obtaining memory information through Linux command based program - Google Patents

Method for obtaining memory information through Linux command based program Download PDF

Info

Publication number
CN103279360A
CN103279360A CN2013102290998A CN201310229099A CN103279360A CN 103279360 A CN103279360 A CN 103279360A CN 2013102290998 A CN2013102290998 A CN 2013102290998A CN 201310229099 A CN201310229099 A CN 201310229099A CN 103279360 A CN103279360 A CN 103279360A
Authority
CN
China
Prior art keywords
memory information
linux
temporary file
saved
filesync
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2013102290998A
Other languages
Chinese (zh)
Inventor
张世刚
王渭巍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Electronic Information Industry Co Ltd
Original Assignee
Inspur Electronic Information Industry Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Electronic Information Industry Co Ltd filed Critical Inspur Electronic Information Industry Co Ltd
Priority to CN2013102290998A priority Critical patent/CN103279360A/en
Publication of CN103279360A publication Critical patent/CN103279360A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a method for obtaining memory information through a Linux command based program. The memory information refers to memory total, used, free, shared, buffers or cached under a Linux system and the unit is MB (Mega Byte). According to the method for obtaining the memory information through the Linux command based program, a compiled dynamic link library can be provided for the Java to invoke through JNI (Java Native Interface); execution of the Linux commands is controlled through the C++ to obtain the memory information under the Linux system; and the memory information is obtained by directly inputting commands to a server in a traditional method. The method for obtaining the memory information through the Linux command based program has the advantages of being capable of supporting equipment monitoring software, avoiding obtaining required information by repeatedly inputting the commands and accordingly being capable of improving management efficiency of the server.

Description

A kind of method of obtaining memory information based on the program of Linux order of using
Technical field
The present invention relates to computer application field, specifically a kind of method of obtaining memory information based on the program of Linux order of using.
Background technology
Along with the expansion of computer cluster scale, traditional management method to server is more and more inapplicable, needs a cover cluster monitoring management software to come huge computer cluster is managed, to improve efficiency of managing and to reduce handling cost.The present invention, the method that provides support for the cluster monitoring management software exactly.
Traditional method is directly to server, and input command obtains institute's memory information
(total, used, free, shared, buffers, cached), this method is a kind of method that obtains memory information by program, can be used for supporting some monitoring of tools softwares, avoid the input command of repetition to obtain the information that needs, thereby can improve the efficiency of management of server.
Summary of the invention
The purpose of this invention is to provide a kind of method of obtaining memory information based on the program of LINUX order of using.
The objective of the invention is to realize in the following manner, concrete implementation step is as follows:
1) obtains the memory information of server with the Linux order, and be saved in the temporary file;
char?cmdSync[256]?=?"free?-m?|?grep?Mem?>?";
char?fileSync[]?=?"/tmp/memlc-XXXXXX";
Imkstemp (fileSync); // establishment temporary file
Strcat (cmdSync, fileSync); // splicing character string
System (cmdSync); // fill order;
2) carry out the I/O stream that Linux orders temporary file in the foundation step 1 with the C++ code, obtain the total of internal memory, used, free, shared, buffers, cached information, and be saved in the data structure body, carry out data encapsulation;
3) carry out the Linux order with the C++ code, the memory information that command execution is obtained is saved in the temporary file;
Ifstream file (fileSync); // obtain the I/O stream of temporary file
while?(?file.getline(?pszTmpln,?SIZELN?)?){
sscanf(pszTmpln,?"%s?%s?%s?%s?%s?%s?%s",?pszTmp,pszTmp,info1,?info2,?info3,?info4,?pszTmp);
}
These data that 4) will obtain are saved in set vector<vector<string〉〉 in.
The invention has the beneficial effects as follows:
This memory information refers to memory amount (total), use amount (used), idle amount (free), shared amount (shared), the buffer memory (buffers/cached) under the linux system, unit is MB, and the dynamic link library that is compiled into this method can call by JNI for Java.This method is carried out the Linux order with the C++ code, will obtain server memory information with the Linux order, and be saved in the temporary file.Create one respectively about the I/O stream of temporary file with the C++ code again, and the acquisition memory information (be total, used, free, shared, buffers, cached, unit: MB).
Embodiment
This method realizes by following steps:
1) obtains the memory information of server with the Linux order, and be saved in the temporary file;
char?cmdSync[256]?=?"free?-m?|?grep?Mem?>?";
char?fileSync[]?=?"/tmp/memlc-XXXXXX";
Imkstemp (fileSync); // establishment temporary file
Strcat (cmdSync, fileSync); // splicing character string
System (cmdSync); // fill order
2) carry out the I/O stream that Linux orders temporary file in the foundation step 1 with the C++ code, obtain memory information (being total, used, free, shared, buffers, cached, the MB of unit), and be saved in the data structure body, carry out data encapsulation;
3) carry out the Linux order with the C++ code, the memory information that command execution is obtained is saved in the temporary file;
Ifstream file (fileSync); // obtain the I/O stream of temporary file
while?(?file.getline(?pszTmpln,?SIZELN?)?){
sscanf(pszTmpln,?"%s?%s?%s?%s?%s?%s?%s",?pszTmp,pszTmp,info1,?info2,?info3,?info4,?pszTmp);
}
These data that 4) will obtain are saved in set vector<vector<string〉〉 in.
Except the described technical characterictic of instructions, be the known technology of those skilled in the art.

Claims (1)

1. one kind with the method for obtaining memory information based on the program of Linux order, it is characterized in that concrete implementation step is as follows:
1) obtains the memory information of server with the Linux order, and be saved in the temporary file;
char?cmdSync[256]?=?"free?-m?|?grep?Mem?>?";
char?fileSync[]?=?"/tmp/memlc-XXXXXX";
Imkstemp (fileSync); // establishment temporary file
Strcat (cmdSync, fileSync); // splicing character string
System (cmdSync); // fill order;
2) carry out the I/O stream that Linux orders temporary file in the foundation step 1 with the C++ code, obtain the total of internal memory, used, free, shared, buffers, cached information, and be saved in the data structure body, carry out data encapsulation;
3) carry out the Linux order with the C++ code, the memory information that command execution is obtained is saved in the temporary file;
Ifstream file (fileSync); // obtain the I/O stream of temporary file
while?(?file.getline(?pszTmpln,?SIZELN?)?){
sscanf(pszTmpln,?"%s?%s?%s?%s?%s?%s?%s",?pszTmp,pszTmp,info1,?info2,?info3,?info4,?pszTmp);
}
These data that 4) will obtain are saved in set vector<vector<string〉〉 in.
CN2013102290998A 2013-06-09 2013-06-09 Method for obtaining memory information through Linux command based program Pending CN103279360A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2013102290998A CN103279360A (en) 2013-06-09 2013-06-09 Method for obtaining memory information through Linux command based program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2013102290998A CN103279360A (en) 2013-06-09 2013-06-09 Method for obtaining memory information through Linux command based program

Publications (1)

Publication Number Publication Date
CN103279360A true CN103279360A (en) 2013-09-04

Family

ID=49061900

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2013102290998A Pending CN103279360A (en) 2013-06-09 2013-06-09 Method for obtaining memory information through Linux command based program

Country Status (1)

Country Link
CN (1) CN103279360A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105912306A (en) * 2016-04-12 2016-08-31 电子科技大学 Data processing method for high-concurrency platform server
CN108664412A (en) * 2018-05-18 2018-10-16 广州优视网络科技有限公司 I/O data method for stream processing, device, storage medium and terminal

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1480878A (en) * 2002-09-02 2004-03-10 联想(北京)有限公司 Method for obtaining information of linux operation system
CN101354675A (en) * 2008-08-19 2009-01-28 华南理工大学 Method for detecting embedded software dynamic memory
US20090193185A1 (en) * 2008-01-24 2009-07-30 Inventec Corporation Method for accessing the physical memory of an operating system
CN102073591A (en) * 2011-01-14 2011-05-25 福建星网视易信息系统有限公司 Method and system for detecting memory occupancy state of embedded system
CN102541722A (en) * 2011-12-30 2012-07-04 曙光信息产业股份有限公司 Server memory monitoring method and server memory monitoring system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1480878A (en) * 2002-09-02 2004-03-10 联想(北京)有限公司 Method for obtaining information of linux operation system
US20090193185A1 (en) * 2008-01-24 2009-07-30 Inventec Corporation Method for accessing the physical memory of an operating system
CN101354675A (en) * 2008-08-19 2009-01-28 华南理工大学 Method for detecting embedded software dynamic memory
CN102073591A (en) * 2011-01-14 2011-05-25 福建星网视易信息系统有限公司 Method and system for detecting memory occupancy state of embedded system
CN102541722A (en) * 2011-12-30 2012-07-04 曙光信息产业股份有限公司 Server memory monitoring method and server memory monitoring system

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
LINUXEDEN: "Linux系统内存监控全面讲解:free命令", 《HTTP://OS.51CTO.COM/ART/201004/193160.HTM》 *
江洪: "Linux获取系统信息", 《电脑编程技巧与维护》 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105912306A (en) * 2016-04-12 2016-08-31 电子科技大学 Data processing method for high-concurrency platform server
CN105912306B (en) * 2016-04-12 2018-05-18 电子科技大学 A kind of method of the data processing of high concurrent Platform Server
CN108664412A (en) * 2018-05-18 2018-10-16 广州优视网络科技有限公司 I/O data method for stream processing, device, storage medium and terminal

Similar Documents

Publication Publication Date Title
CN101408899B (en) Method and apparatus for switching website multiple data sources
CN107480202B (en) Data processing method and device for multiple parallel processing frameworks
Zhang et al. Research on lightweight MVC framework based on spring MVC and mybatis
CN103064667A (en) Method for controlling hardware equipment based on JavaScript extension
CN102938776A (en) Dynamic page processing system based on Asynchronous JavaScript and XML (ajax) technique
CN102479217B (en) Method and device for realizing computation balance in distributed data warehouse
CN105045856A (en) Hadoop-based data processing system for big-data remote sensing satellite
CN101478311B (en) Hardware accelerated implementation process for bzip2 compression algorithm
CN102207884A (en) File compiling method and device
CN105022631A (en) Scientific calculation-orientated floating-point data parallel lossless compression method
CN103279360A (en) Method for obtaining memory information through Linux command based program
CN104166705A (en) Access method and device of database
CN102591787A (en) Method and device for data processing of JAVA card
CN103488517A (en) PHP code compiling method and device and PHP code running method and device
CN103544415A (en) Mobile platform application software reinforcement method
CN103268245B (en) A kind of method of weather data fast processing flow
US9471344B1 (en) Hardware support for processing virtual machine instructions
CN102819445B (en) Quick transplanting method of comprehensive software of transformer substation on embedded system hardware platform
CN103473116A (en) Remote call method and device for data with large data volume
CN102629200A (en) Processing method for Web system off-line using
US20130013666A1 (en) Monitoring data access requests to optimize data transfer
US20180322179A1 (en) Processing data between data stores
CN103955424B (en) The embedded binary software defect detecting system of a kind of virtualization
CN105488147A (en) Persistence method based on SQL (Structured Query Language) template
CN105488169A (en) Multi-process file conversion method and apparatus

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20130904