4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongGi Jang <dg0402.jang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include <sys/types.h>
36 int set_oomadj(int pid, int oomadj_val)
41 snprintf(buf, BUFF_MAX, "/proc/%d/oom_adj", pid);
45 fprintf(fp, "%d", oomadj_val);
51 int check_and_setpmon(int pid, int idx, char **argv, char type)
57 snprintf(buf, BUFF_MAX, "/proc/%d/cmdline", pid);
58 fd = open(buf, O_RDONLY);
62 read(fd, buf, BUFF_MAX);
68 filename = strrchr(buf, '/');
72 filename = filename + 1;
74 while (idx > 1) { /* argv[1] is monitoring type */
75 if (!strcmp(argv[idx], filename)) {
78 printf("====> found, %s - set vip\n",
83 printf("====> found, %s - set permanent\n",
85 sysconf_set_permanent_bypid(pid);
96 int main(int argc, char **argv)
101 struct dirent *dentry;
105 argv[1][1] == '\0' || (argv[1][1] != 'v' && argv[1][1] != 'p')) {
106 printf("Usage: %s <monitoring type> <process name>\n", argv[0]);
107 printf("Monitoring types: -v \t VIP process\n");
108 printf(" -p \t Permanent process\n");
112 dp = opendir("/proc");
114 printf("open /proc : %s\n", strerror(errno));
119 while ((dentry = readdir(dp)) != NULL) {
120 if (!isdigit(dentry->d_name[0]))
123 pid = atoi(dentry->d_name);
124 check_and_setpmon(pid, argc - 1, argv, type);