static int memory_killer_get_candidates(enum memory_killer_range range, GSList **candidates)
{
int ret;
- pid_t pid;
+ pid_t pid, pid_max;
DIR *dp;
struct dirent *de;
struct memory_killer_candidate *candidate;
struct procfs_pid_stat pps;
char label[64];
+ ret = procfs_get_pid_max(&pid_max);
+ if (ret < 0) {
+ _E("Failed to get the maximum value of PID");
+ return ret;
+ }
+
dp = opendir("/proc");
if (!dp) {
_E("Failed to open /proc : %m");
continue;
pid = (pid_t)atoi(de->d_name);
- if (pid < 1 || !getpgid(pid))
+ if (pid < 1)
+ continue;
+
+ if (pid > pid_max) {
+ _W("PID %u is bigger than PID_MAX(%u). Ignore it", pid, pid_max);
+ continue;
+ }
+
+ if (getpgid(pid) == 0)
continue;
candidate = g_new(struct memory_killer_candidate, 1);
GSList *proc_usage_application_get_list(void)
{
int ret;
- pid_t pid;
+ pid_t pid, pid_max;
DIR *dp;
struct dirent *de;
char label[64];
GSList *applist = NULL;
struct proc_usage_application *pua;
+ ret = procfs_get_pid_max(&pid_max);
+ if (ret < 0) {
+ _E("Failed to get the maximum value of PID");
+ return NULL;
+ }
+
dp = opendir("/proc");
if (!dp) {
_E("Failed to open /proc : %m");
continue;
pid = (pid_t)atoi(de->d_name);
- if (pid < 1 || !getpgid(pid))
+ if (pid < 1)
+ continue;
+
+ if (pid > pid_max) {
+ _W("PID %u is bigger than PID_MAX(%u). Ignore it", pid, pid_max);
+ continue;
+ }
+
+ if (getpgid(pid) == 0)
continue;
/* Distinguish Tizen application with checking SMACK label */