linux kernel - Make a system call to get list of processes -


i'm new on modules programming , need make system call retrieve system processes , show how cpu consuming.

how can make call?

why implement system call this? don't want add syscall existing linux api. primary linux interface userspace , nobody touches syscalls except top kernel developers know do.

if want list of processes , parameters , real-time statuses, use /proc. every directory that's integer in there existing process id , contains bunch of useful dynamic files ps, top , others use print output.

if want list of processes within kernel (e.g. within module), should know processes kept internally doubly linked list starts init process (symbol init_task in kernel). should use macros defined in include/linux/sched.h processes. here's example:

#include <linux/module.h> #include <linux/printk.h> #include <linux/sched.h>  static int __init ex_init(void) {     struct task_struct *task;      for_each_process(task)         pr_info("%s [%d]\n", task->comm, task->pid);      return 0; }  static void __exit ex_fini(void) { }  module_init(ex_init); module_exit(ex_fini); 

this should okay gather information. however, don't change in there unless know you're doing (which require bit more reading).


Comments

Popular posts from this blog

Line ending issue with Mercurial or Visual Studio -

java - Jtable duplicate Rows -

java - Run a .jar on Heroku -