| 522 | |
| 523 | #ifdef __linux |
| 524 | static int CPLGetProcessMemorySize() |
| 525 | { |
| 526 | FILE *fp = fopen("/proc/self/status", "r"); |
| 527 | if (fp == nullptr) |
| 528 | return -1; |
| 529 | int nRet = -1; |
| 530 | char szLine[128] = {}; |
| 531 | while (fgets(szLine, sizeof(szLine), fp) != nullptr) |
| 532 | { |
| 533 | if (STARTS_WITH(szLine, "VmSize:")) |
| 534 | { |
| 535 | const char *pszPtr = szLine; |
| 536 | while (!(*pszPtr == '\0' || (*pszPtr >= '0' && *pszPtr <= '9'))) |
| 537 | pszPtr++; |
| 538 | nRet = atoi(pszPtr); |
| 539 | break; |
| 540 | } |
| 541 | } |
| 542 | fclose(fp); |
| 543 | return nRet; |
| 544 | } |
| 545 | #else |
| 546 | #error CPLGetProcessMemorySize() unimplemented for this OS |
| 547 | #endif |