<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div>Hi all,<br><br>I am a Fedora user and I have a module (just an example) that does not work for the latest kernels (FC6).<br>The kernel simbol tasklist_lock (sched.h) is not found by the compiler (I searched and found a kernel patch, but I do not want to recompile the kernel) .<br>What is the adviced way to do this working?<br><br>Thanks for your help,<br>V.D.<br><br>The module is:<br><br>/*
==================================<br> <br> pidstate.c - How to show the task state for a given PID.<br><br> Compile with this:<br> 1) Write a file named Makefile containing only this line:<br> obj-m += pidstate.o<br> (no spaces allowed before obj-m!!!)<br> 2) Issue the following command:<br> make -C /lib/modules/`uname -r`/build SUBDIRS=$PWD modules<br> <br> Then, load the module with (example):<br> insmod
./pidstate.ko my_target_pid=2718<br><br> Finaly, remove the module:<br> rmmod pidstate<br><br> Warning: you need the kernel source installed.<br><br> Tested using kernel 2.6.16 and mot working with 2.6.18 - 2.6.20<br><br> */<br><br>#include <linux/module.h><br>#include <linux/moduleparam.h><br>#include <linux/kernel.h><br>#include <linux/init.h><br>#include <linux/stat.h><br>#include <linux/sched.h><br><br>MODULE_LICENSE("GPL");<br>MODULE_AUTHOR("Cristian Sava");<br>MODULE_DESCRIPTION("Show the task state for a given PID");<br><br>static int my_target_pid = 0;<br>static struct task_struct
*my_target_task;<br><br>/* <br> * module_param(foo, int, 0000) <br> * The first param is the parameters
name <br> * The second param is it's data type <br> * The final argument is the permissions bits, <br> * for exposing parameters in sysfs (if non-zero) at a later stage.
<br> */ <br><br>module_param(my_target_pid, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); <br>MODULE_PARM_DESC(my_target_pid, "The PID must be an integer"); <br><br>/*<br> * The task state array is a strange "bitmap" of reasons to
sleep.<br> * Thus "running" is zero, and you can test for combinations of<br> * others with simple bit tests.<br> * (this is from fs/proc/array.c - because we do not have access there)<br> */<br>static const char *task_state_array[] = {<br> "R (running)", /* 0 */<br> "S (sleeping)", /* 1 */<br> "D (disk sleep)", /* 2 */<br> "T (stopped)", /* 4 */<br> "T (tracing stop)", /* 8 */<br> "Z (zombie)", /* 16 */<br> "X (dead)" /* 32 */<br>};<br><br>/* This is from fs/proc/array.c */<br>static inline const char * get_task_state(struct task_struct *tsk)<br>{<br> unsigned int
state = (tsk->state & (TASK_RUNNING |<br> TASK_INTERRUPTIBLE |<br> TASK_UNINTERRUPTIBLE |<br> TASK_STOPPED |<br> TASK_TRACED)) |<br> (tsk->exit_state & (EXIT_ZOMBIE |<br> EXIT_DEAD));<br> const char **p = &task_state_array[0];<br><br> while (state) {<br>
p++;<br> state >>= 1;<br> }<br> return *p;<br>}<br><br>static int __init pidstate_init(void) <br>{ <br> printk(KERN_ALERT "Hello,
pidstate!\n================\n"); <br> printk(KERN_ALERT "my_target_pid is an integer: %d\n", my_target_pid); <br><br> /*<br> * First we need to lock the task list for reading<br> */<br><br> read_lock(&tasklist_lock);<br><br> /*<br> * Each process has a task_struct (defined in linux/sched.h)<br> * Using the PID we get the task_struct for it<br> */<br><br> my_target_task = find_task_by_pid(my_target_pid);<br><br> /*<br> * Only if the PID exists (we test if we really have my_target_task)<br> * we will use pid_alive to find out if the process is
alive<br> * and we show the task state using get_task_state<br> */<br><br> if (my_target_task)<br> {<br> if (pid_alive(my_target_task))<br> printk(KERN_ALERT "my_target_pid: %d is alive \n", my_target_pid);<br> printk(KERN_ALERT "State: %s \n", get_task_state(my_target_task));<br> }<br><br> /*<br> * Now we unlock the task list<br> */<br><br> read_unlock(&tasklist_lock);<br><br> return 0;<br>}<br><br>static void __exit pidstate_exit(void)<br>{<br> printk(KERN_ALERT "Goodbye, pidstate\n");<br>}<br><br>module_init(pidstate_init);<br>module_exit(pidstate_exit);<br><br></div></div><br>
<hr size=1>Ahhh...imagining that irresistible "new car" smell?<br> Check out
<a href="http://us.rd.yahoo.com/evt=48245/*http://autos.yahoo.com/new_cars.html;_ylc=X3oDMTE1YW1jcXJ2BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDbmV3LWNhcnM-">new cars at Yahoo! Autos.</a>
</body></html>