如何计算内核中活动用户的数量

时间:2022-09-23 02:16:31

We're using kernel version 2.4-20 and we need to count number of active users, in kernel mode. Objective is to change the scheduler, so we are in sched.c, modifying schedule() function.

我们使用的是内核版本2.4-20,我们需要在内核模式下计算活动用户数。目标是更改调度程序,因此我们在sched.c中修改schedule()函数。

What we do is to count the users in list_for_each macro.

我们所做的是计算list_for_each宏中的用户。

list_for_each(tmp, &runqueue_head) {
    p = list_entry(tmp, struct task_struct, run_list);
    if (can_schedule(p, this_cpu)) {
        if (unique(p->uid)) add_new_user(p->uid);
        int weight = goodness(p, this_cpu, prev->active_mm);
        if (weight > c)
            c = weight, next = p;
    }
}

which is basically adding unique users to a list. However, we get random results. Is there a concrete way to solve this problem?

这基本上是将唯一用户添加到列表中。但是,我们得到随机结果。有没有具体的方法来解决这个问题?

Thank you.

谢谢。

2 个解决方案

#1


1  

You may want to try counting the users inside the for_each_task macro. This results in counting the users that have a task which is blocked due to I/O or any other reason. This should provide better results as you can't guarantee being able to count the users who run interactive processes if you use the run queue.

您可能想尝试计算for_each_task宏内的用户。这导致计算具有由于I / O或任何其他原因而被阻止的任务的用户。这应该提供更好的结果,因为如果使用运行队列,则无法保证能够计算运行交互式进程的用户。

#2


0  

Would this work? who | awk ' { print $1 }' | sort -ud

这会有用吗?谁| awk'{print $ 1}'| sort -ud

#1


1  

You may want to try counting the users inside the for_each_task macro. This results in counting the users that have a task which is blocked due to I/O or any other reason. This should provide better results as you can't guarantee being able to count the users who run interactive processes if you use the run queue.

您可能想尝试计算for_each_task宏内的用户。这导致计算具有由于I / O或任何其他原因而被阻止的任务的用户。这应该提供更好的结果,因为如果使用运行队列,则无法保证能够计算运行交互式进程的用户。

#2


0  

Would this work? who | awk ' { print $1 }' | sort -ud

这会有用吗?谁| awk'{print $ 1}'| sort -ud