为了限制系统内各模块的cpu占用,用到cpulimit工具,如下限制test的cpu占用110%,最大cpu占用=cpu核个数*100%。
./cpulimit -e test -l 110
在arm平台下代码存在bug,basename函数会返回无效值,我做了如下修改
int find_process_by_name(const char *process_name)
{
//pid of the target process
pid_t pid = -1;
//process iterator
struct process_iterator it;
struct process proc;
struct process_filter filter;
filter.pid = 0;
filter.include_children = 0;
init_process_iterator(&it, &filter);
while (get_next_process(&it, &proc) != -1)
{
int diff_len = strlen(proc.command) - strlen(process_name);
if (diff_len >= 0)
{
char *guess_name = proc.command + diff_len;
if (strncmp(guess_name, process_name, strlen(process_name)) == 0 && kill(pid, SIGCONT) == 0)
{
pid = proc.pid;
break;
}
}
}
if (close_process_iterator(&it) != 0)
exit(1);
if (pid >= 0)
{
//ok, the process was found
return pid;
}
else
{
//process not found
return 0;
}
}