|
|
@ -158,90 +158,16 @@ const char* OS::GetProcessTitle(int *len) { |
|
|
|
|
|
|
|
|
|
|
|
int OS::GetMemory(size_t *rss, size_t *vsize) { |
|
|
|
FILE *f = fopen("/proc/self/stat", "r"); |
|
|
|
if (!f) return -1; |
|
|
|
|
|
|
|
int itmp; |
|
|
|
char ctmp; |
|
|
|
size_t page_size = getpagesize(); |
|
|
|
|
|
|
|
/* PID */ |
|
|
|
if (fscanf(f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Exec file */ |
|
|
|
if (fscanf (f, "%s ", buf) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* State */ |
|
|
|
if (fscanf (f, "%c ", &ctmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Parent process */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Process group */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Session id */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* TTY */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* TTY owner process group */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Flags */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Minor faults (no memory page) */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Minor faults, children */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Major faults (memory page faults) */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Major faults, children */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* utime */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* stime */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* utime, children */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* stime, children */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* jiffies remaining in current time slice */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* 'nice' value */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* jiffies until next timeout */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* jiffies until next SIGALRM */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* start time (jiffies since system boot) */ |
|
|
|
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
|
|
|
|
/* Virtual memory size */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
*vsize = (size_t) itmp; |
|
|
|
|
|
|
|
/* Resident set size */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
*rss = (size_t) itmp * page_size; |
|
|
|
|
|
|
|
/* rlim */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Start of text */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* End of text */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
/* Start of stack */ |
|
|
|
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ |
|
|
|
|
|
|
|
fclose (f); |
|
|
|
|
|
|
|
// Not implemented
|
|
|
|
*rss = 0; |
|
|
|
*vsize = 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
error: |
|
|
|
fclose (f); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int OS::GetExecutablePath(char* buffer, size_t* size) { |
|
|
|
*size = readlink("/proc/self/exe", buffer, *size - 1); |
|
|
|
if (*size <= 0) return -1; |
|
|
|
buffer[*size] = '\0'; |
|
|
|
return 0; |
|
|
|
*size = 0; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace node
|
|
|
|