Why doesn't for_each_process show every task?

I am trying to loop every process in the /proc utility that I am writing (kernel module in /fs/proc ). The problem is that I see processes in the root namespace. I am trying to use the for_each_process macro from sched.h .

I can type ps in the shell and see many processes, but my for_each_process loop for_each_process not see them. What gives?

Note: I am wondering if this is related to rcu_read_lock ? I am afraid to put rcu_read_lock , and I do not know where it should go. The trouble is that the documentation . I read, it seems, says that in the explicit kernel (mine) I cannot sleep inside rcu_read_lock , I need to call down_read(mmap_sem) , which I'm afraid will sleep. So I can not use rcu_read_lock ?

+4
source share
4 answers

He should show you all the processes. I wrote such code.

 struct task_struct *task; for_each_process(p) { printk("Task %s (pid = %d)\n",p->comm, task_pid_nr(p)); } 

This is the seal of all processes. I suspect your proc_read function. Can you insert the proc_read function proc_read ?

+4
source

I think for_each_process() just gives you the thread group leader.

This is an iteration over all task_struct variables (defined in sched.h).

 struct task_struct *g, *p; do_each_thread(g, p) { //do something with p } while_each_thread(g, p); 
+3
source

This example displays a long list, it looks like it can print almost all of them .... thought I didn’t count them

http://tuxthink.blogspot.in/2011/03/using-foreachprocess-in-proc-entry.html

0
source

for_each_process is a kernel level function, and it really is not how you should go through processes on unix. Something is much simpler, for example this (python, easily implemented in other languages) may be the solution you want.

 #Print each process id import re,os for fn in os.listdir( '/proc' ): if re.match('\d+', fn): print 'process %s'%fn 
-2
source

Source: https://habr.com/ru/post/1400788/


All Articles