Here is my code for read function in proc kernel module
int read_proc(struct file *filp,char *buf,size_t count,loff_t *offset )
{
struct task_struct *task = current;
ssize_t bytes = count < (MAX_MSG_LEN-(*offset)) ? count : (MAX_MSG_LEN-(*offset));
do
{
task = task->parent;
sprintf(buf, "assignment: parent process: %s, PID: %d Utime: %d , stime: %ld \n ", task->comm, task->pid,task->utime,task->stime) ;
} while (task->pid != 0);
(*offset) += bytes;
return bytes;
}
In this code I'm only able to read the last zero number PID process from the buffer but I want to read all the running processes and its PID
I have modified the code from this link: https://jlmedina123.wordpress.com/2013/08/13/current-variable-and-task_struct/
My output:
assignment: parent process: swapper/0, PID: 0 Utime: 0 , stime: 1201744387 668726 assignment: parent process: swapper/0, PID: 0 Utime: 0 , stime: 1201761343 195869 assignment: parent process: swapper/0, PID: 0 Utime: 0 , stime: 1201791953
I want to read all the process id and running process which i have copied into the buffer !!! please tell me where I have done wrong?