I am working on a linux kernel module which would take care of all the processes that are running for a specific task. Is it possible to know if the certain process named 'X' is still running or not and whats its current state???
Asked
Active
Viewed 551 times
2
-
2is it that u only want the process info only, if yes then may be you can use task_struct structure – Anshul Mar 07 '13 at 05:34
-
1basically yes,, once i know all the name of running processes I will take some action on certain set of processes – Mar 07 '13 at 05:35
2 Answers
1
well the code is ready.. you can try this..
#include<linux/init.h>
#include<linux/module.h>
#include<linux/sched.h>
MODULE_LICENSE("GPL");
static int info_init(void)
{
struct task_struct *iTask;
for_each_process(iTask) {
printk(KERN_INFO "Process Info \nName: %s\nState:%ld\n",iTask->comm, iTask->state);
}
return 0;
}
static void info_exit(void)
{
printk(KERN_INFO "Tata Bye-bye from Anshul");
}
module_init(info_init);
module_exit(info_exit);
~
After executing it run a
dmesg
command and you can see all the process namess and their states.

Anshul
- 1,416
- 1
- 16
- 42
1
Every Task in Linux is being represented by a structure (PCB/TCB) i.e. process/task control block. This is implemented as struct task_struct. It contains all the information about a process. All the PCBs are arranged in a link list and you can traverse through it and extract necessary information. Inside your module you can initiate a kernel thread as a helper to do this work for you.

flying-high
- 219
- 2
- 7