I am trying to loop through every process in a /proc utility I’m writing (a kernel module in /fs/proc). The problem is, I am only seeing processes in the root namespace. I’m trying to use the macro for_each_process() from sched.h.
I can type ps in a shell and see plenty of processes, but my for_each_process() loop doesn’t see them. What gives?
Note: I am wondering if it has something to do with rcu_read_lock()? I’m afraid to put an rcu_read_lock() and I don’t know where it should go. The trouble is, the documentation I read seems to say that in a preemptive kernel (mine is), it is illegal to sleep inside of rcu_read_lock(). I need to call down_read(mmap_sem) which I am afraid will sleep. So that means I can’t use rcu_read_lock()?
It should show you all the processes. I have written code like this.
This is printing all the processes. I suspect your
proc_readfunction. Can you paste yourproc_readfunction over here?