I know this might be a stupid question for guru. But I am newbie to the Gnu/ Linux kernel, there are many parts that I do not understand very well. Hope someone can give me advice.
After reading book and searching online document, it says that set_task_state will `change the process's state (Linux kernel development)'.
So I write a simple kernel module to test the EXIT_ZOMBIE state. The source of kernel module looks as A). Beside, I write a infinite programme. Its source code mainly do the loop infinitely, as B).
What I expect is after `insmod set_state.ko` (infinite programme will run first), the infinite should be terminated (because it is set to EXIT_ZOMBIE). However, from the result I think I am wrong. I do not know where did I do it wrong due to the programme infinite is stilling running when `ps -ef | grep infinite` (as C). I think either I misunderstand the meaning of EXIT_ZOMBIE or some steps I miss in order to terminate the process.
What should I do in order to obtain the outcome I expect.
Thanks in advice.
A) set_state.c
Code:
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/module.h>
int
init_module(void)
{
struct task_struct *task;
for_each_process(task){
if(strcmp(task->comm, "infinite")==0){
set_task_state(task, EXIT_ZOMBIE);
}
}
return 0;
}
void
cleanup_module(void)
{
printk(KERN_INFO " Cleaning Up.\n");
}
B.) infinite.c
Code:
int
main(int argc, int *argv[])
{
while(1);
}
C.) ps -ef | grep infinite
Code:
user1 3865 1 0 02:10 ? 00:00:02 ./infinite