修改当前CPU使用率段错误

This commit is contained in:
szm-min 2024-04-29 15:43:00 +08:00
parent ec858098c2
commit b641d410fb
1 changed files with 33 additions and 13 deletions

View File

@ -278,22 +278,42 @@ static int _get_cpu_data(unsigned long *user, unsigned long *sys, unsigned long
{
if (strstartswith(buffer, "cpu") == 0)
{
char **list = strsplit(buffer, ' ');
if (!list)
// char **list = strsplit(buffer, ' ');
// if (!list)
// {
// fclose(fp);
// return 1;
// }
char list1[32] = {0};
char list3[32] = {0};
char list4[32] = {0};
char list5[32] = {0};
sscanf(buffer, "%*s %s %*s %s %s %s %*s", list1, list3, list4, list5);
klog_info("list1 = %s, list3 = %s, list4 = %s, list5 = %s\n", list1, list3, list4, list5);
if(strlen(list1) == 0)
{
fclose(fp);
return 1;
}
klog_info("list1 = %s, list3 = %s, list4 = %s, list5 = %s\n", list[1], list[3], list[4], list[5]);
if(list[1])
*user = atol(list[1]);
if(list[3])
*sys = atol(list[3]);
if(list[4])
*idle = atol(list[4]);
if(list[5])
*iowait = atol(list[5]);
free(list);
*user = atol(list1);
if(strlen(list3) == 0)
{
return 1;
}
*sys = atol(list3);
if(strlen(list4) == 0)
{
return 1;
}
*idle = atol(list4);
if(strlen(list5) == 0)
{
return 1;
}
*iowait = atol(list5);
// free(list);
break;
}
else