这是我在proc内核模块中读取函数的代码
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;
}
在这段代码中,我只能从缓冲区中读取最后一个零号PID过程,但我想读取所有正在运行的进程及其PID
我修改了此链接中的代码: https://jlmedina123.wordpress.com/2013/08/13/current-variable-and-task_struct/
我的输出:
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
我想读取已复制到缓冲区中的所有进程ID和运行进程!请告诉我我做错了什么?