2 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include <sys/types.h>
31 int set_oomadj(int pid, int oomadj_val)
36 snprintf(buf, BUFF_MAX, "/proc/%d/oom_adj", pid);
40 fprintf(fp, "%d", oomadj_val);
46 int check_and_setpmon(int pid, int idx, char **argv, char type)
52 snprintf(buf, BUFF_MAX, "/proc/%d/cmdline", pid);
53 fd = open(buf, O_RDONLY);
57 read(fd, buf, BUFF_MAX-1);
60 buf[BUFF_MAX-1] = '\0';
65 filename = strrchr(buf, '/');
69 filename = filename + 1;
71 while (idx > 1) { /* argv[1] is monitoring type */
72 if (!strcmp(argv[idx], filename)) {
75 printf("====> found, %s - set vip\n",
80 printf("====> found, %s - set permanent\n",
82 sysconf_set_permanent_bypid(pid);
93 int main(int argc, char **argv)
98 struct dirent *dentry;
102 argv[1][1] == '\0' || (argv[1][1] != 'v' && argv[1][1] != 'p')) {
103 printf("Usage: %s <monitoring type> <process name>\n", argv[0]);
104 printf("Monitoring types: -v \t VIP process\n");
105 printf(" -p \t Permanent process\n");
109 dp = opendir("/proc");
111 printf("open /proc : %s\n", strerror(errno));
116 while ((dentry = readdir(dp)) != NULL) {
117 if (!isdigit(dentry->d_name[0]))
120 pid = atoi(dentry->d_name);
121 check_and_setpmon(pid, argc - 1, argv, type);