Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-01-2009, 04:32 AM
|
#1
|
|
LQ Newbie
Registered: May 2009
Posts: 2
Rep:
|
Is there any system function/api to get values like /proc/<pid>/status ???
Hello All,
I want memory log of my application and for that i want any system function that will give information similar to /proc/<My_App_Pid>/status.
basically i need all Virtual memory values like VmSize, VmPeak, VmRSS etc. and number of threads running.
Regards
Kunal Nandi
|
|
|
|
05-01-2009, 09:16 PM
|
#2
|
|
Member
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372
Rep: 
|
Nope. You don't need one. The proc filesystem is "in storage" and ascii, so a standard read of it is really efficient.
All of the utilities that I've ever seen that access the proc filesystem use standard open/read/close.
Here's a function that'll work.
Code:
static int read_proc_file(char *file_name, char *buffer, int size)
{
int num_bytes_read, fp;
fp = open(file_name, O_RDONLY);
if (!fp) {
syslog(LOG_ERR, "Failed to open %s: %s\n", file_name,
strerror(errno));
return -1;
}
num_bytes_read = read(fp, buffer, size);
if (num_bytes_read < 0) {
syslog(LOG_ERR, "Failed to read %s\n", file_name);
close(fp);
return -1;
}
close(fp);
return num_bytes_read;
}
|
|
|
|
05-02-2009, 01:22 AM
|
#3
|
|
LQ Newbie
Registered: May 2009
Posts: 2
Original Poster
Rep:
|
actually i hv already tried this before but, i was looking for some system function any ways thanks for your reply
Quote:
Originally Posted by tommylovell
Nope. You don't need one. The proc filesystem is "in storage" and ascii, so a standard read of it is really efficient.
All of the utilities that I've ever seen that access the proc filesystem use standard open/read/close.
Here's a function that'll work.
Code:
static int read_proc_file(char *file_name, char *buffer, int size)
{
int num_bytes_read, fp;
fp = open(file_name, O_RDONLY);
if (!fp) {
syslog(LOG_ERR, "Failed to open %s: %s\n", file_name,
strerror(errno));
return -1;
}
num_bytes_read = read(fp, buffer, size);
if (num_bytes_read < 0) {
syslog(LOG_ERR, "Failed to read %s\n", file_name);
close(fp);
return -1;
}
close(fp);
return num_bytes_read;
}
|
Regards
Kunal Nandi
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:34 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|