exit(1);
}
- pmstat = fopen(statmname, "r");
- if (pmstat == NULL) {
- perror("open /proc/$pid/statm");
- exit(1);
+ // Sometimes we can't successfully open /proc/$pid files due to strange
+ // permission problems, so we retry to open it several times.
+
+ int retry = 0;
+ const int max_retry = 10;
+
+ for (; retry < max_retry; ++retry)
+ {
+ pmstat = fopen(statmname, "r");
+ if (pmstat == NULL) {
+ perror("open /proc/$pid/statm");
+ usleep(100000);
+ continue;
+ }
+ break;
+ }
+
+ for (; retry < max_retry; ++retry)
+ {
+ pstat = fopen(statname, "r");
+ if (pstat == NULL) {
+ perror("open /proc/$pid/stat");
+ usleep(100000);
+ continue;
+ }
+ break;
}
- pstat = fopen(statname, "r");
- if (pstat == NULL) {
- perror("open /proc/$pid/stat");
+ if (statmname == NULL || statname == NULL)
+ {
exit(1);
}