-/* Copyright 2014 Samsung Electronics Co., Ltd All Rights Reserved
+/* Copyright 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
static int sum;
static int verbos;
static int use_gpu_mem_info = 0;
+static int pid_max = 0;
/* reads file contents into memory */
static char* cread(const char* path)
return NULL;
} /* cgets */
+/* get pid_max value */
+static inline int get_pid_max(void)
+{
+ static const char pid_max_path[] = "/proc/sys/kernel/pid_max";
+ char* line;
+
+ line = cread(pid_max_path);
+ if (line == NULL) {
+ fprintf(stderr, "cannot open %s\n", pid_max_path);
+ return 0;
+ }
+
+ return strtoul(line, NULL, 10);
+}
+
static unsigned get_peak_rss(unsigned int pid)
{
errno = 0;
while ((curdir = readdir(pDir)) != NULL && !errno) {
pid = atoi(curdir->d_name);
- if (pid < 1 || pid > 32768 || pid == getpid())
+ if (pid < 1 || pid > pid_max || pid == getpid())
continue;
if (get_cmdline(pid, cmdline) < 0)
errno = 0;
while ((curdir = readdir(pDir)) != NULL && !errno) {
pid = atoi(curdir->d_name);
- if (pid < 1 || pid > 32768 || pid == getpid())
+ if (pid < 1 || pid > pid_max || pid == getpid())
continue;
if (get_cmdline(pid, cmdline) < 0)
int usage = 1;
sum = 0;
+ pid_max = get_pid_max();
+
if (argc > 1) {
if (!strncmp(argv[1], "-r", strlen("-r")+1)) {
if (argc >= 3)