Number of Running Processes on a Minix system from C code

前端 未结 8 1016
盖世英雄少女心
盖世英雄少女心 2021-01-03 06:14

So, this seemed simple at first, but after crawling Google and here, the answer doesn\'t seem as simple as I first thought.

Basically, I\'m editing a MINIX kernel as

8条回答
  •  离开以前
    2021-01-03 07:09

    If you're editing the kernel, the most efficient way to solve this problem is to maintain a count every time a process (i.e., a task_struct entry) is created (and make sure you decrement the count every where a process terminates).

    You could always loop through the list of processes in the kernel using the built-in macro (but its expensive, so you should try to avoid it):

    struct task_struct *p;
    unsigned int count = 0;
    for_each_process(task) {
        count++;
    }
    

提交回复
热议问题