Return (size_t)(psinfo.pr_rssize * 1024L) If ( read( fd, &psinfo, sizeof(psinfo) ) != sizeof(psinfo) ) If ( (fd = open( "/proc/self/psinfo", O_RDONLY )) = -1 ) GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) ) * memory use) measured in bytes, or zero if the value cannot be * Returns the peak (maximum so far) resident set size (physical #error "Cannot define getPeakRSS( ) or getCurrentRSS( ) for an unknown OS." #elif defined(_linux_) || defined(_linux) || defined(linux) || defined(_gnu_linux_) #elif defined(_unix_) || defined(_unix) || defined(unix) || (defined(_APPLE_) & defined(_MACH_)) * License: Creative Commons Attribution 3.0 Unported License Long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024 // in case x86-64 is configured to use 2MB pagesĬout << "VM: " << vm << " RSS: " << rss << endl ĭavid Robert Nadeau has put a good self contained multi-platform C function to get the process resident set size (physical memory use) in his website: /* > O > itrealvalue > starttime > vsize > rss // don't care about the rest > utime > stime > cutime > cstime > priority > nice > tpgid > flags > minflt > cminflt > majflt > cmajflt Stat_stream > pid > comm > state > ppid > pgrp > session > tty_nr String utime, stime, cutime, cstime, priority, nice String tpgid, flags, minflt, cminflt, majflt, cmajflt String pid, comm, state, ppid, pgrp, session, tty_nr dummy vars for leading entries in stat that we don't care about Ifstream stat_stream("/proc/self/stat",ios_base::in) 'file' stat seems to give the most reliable results Void process_mem_usage(double& vm_usage, double& resident_set) size and resident set size, and return the results in KB. attempts to read the system-dependent data for a process' virtual memory process_mem_usage(double &, double &) - takes two doubles by reference, Here's the one we settled on (the question was tagged C++, and we handled I/O using C++ constructs, but it should be easily adaptable to C i/o routines if you need to): #include There are a number of these files which give differing results. For our applications, we coded a general utility routine based on reading files in /proc/pid. On Linux, I've never found an ioctl() solution.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |