compiler error in simple module
Hi I am trying to write a simple module that sort of emulates the ps command. I am trying to get the comm string for the task, using get_task_comm, but the make command keeps telling me that the symbol get_task_comm is not defined. I have included linux/sched.h. This is the header file, which I believe has the prototype definition for the function. Am I missing something? Thanks Hanumant
On Mon, Jan 10, 2011 at 10:02 PM, Hanumant Singh <hanumant07@gmail.com> wrote:
Hi I am trying to write a simple module that sort of emulates the ps command. I am trying to get the comm string for the task, using get_task_comm, but the make command keeps telling me that the symbol get_task_comm is not defined. I have included linux/sched.h. This is the header file, which I believe has the prototype definition for the function. Am I missing something?
You can only use those symbols in your module which have been explicitly exported using EXPORT_SYMBOL() -- Thanks - Manish ================================== [$\*.^ -- I miss being one of them ==================================
Hi, yes you are missing a very vital thing and that is EXPORT_SYMBOL. Loadable Kernel modules are not part of kernel image and can not just use any symbol of kernel, They can use only exported symbols either exported through EXPORT_SYMBOL or EXPORT_SYMBOL_GPL. GPL version has limitation that your module license should be GPL too and you have to make it open source. Anyways you can always write a similar function in your module: task_lock(tsk); strncpy(buf, tsk->comm, sizeof(tsk->comm)); task_unlock(tsk); Note that task_lock is an static inline function in sched.h so you can safely use that. Rajat On Tue, Jan 11, 2011 at 11:32 AM, Hanumant Singh <hanumant07@gmail.com> wrote:
Hi I am trying to write a simple module that sort of emulates the ps command. I am trying to get the comm string for the task, using get_task_comm, but the make command keeps telling me that the symbol get_task_comm is not defined. I have included linux/sched.h. This is the header file, which I believe has the prototype definition for the function. Am I missing something? Thanks Hanumant _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Thanks On Mon, Jan 10, 2011 at 10:16 PM, Rajat Sharma <fs.rajat@gmail.com> wrote:
Hi,
yes you are missing a very vital thing and that is EXPORT_SYMBOL. Loadable Kernel modules are not part of kernel image and can not just use any symbol of kernel, They can use only exported symbols either exported through EXPORT_SYMBOL or EXPORT_SYMBOL_GPL. GPL version has limitation that your module license should be GPL too and you have to make it open source.
Anyways you can always write a similar function in your module:
task_lock(tsk); strncpy(buf, tsk->comm, sizeof(tsk->comm)); task_unlock(tsk);
Note that task_lock is an static inline function in sched.h so you can safely use that.
Rajat
On Tue, Jan 11, 2011 at 11:32 AM, Hanumant Singh <hanumant07@gmail.com> wrote:
Hi I am trying to write a simple module that sort of emulates the ps command. I am trying to get the comm string for the task, using get_task_comm, but the make command keeps telling me that the symbol get_task_comm is not defined. I have included linux/sched.h. This is the header file, which I believe has the prototype definition for the function. Am I missing something? Thanks Hanumant _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
If you are interested to print some fields of all task_structs. Use the following macro. It will walk thru the entire list of task_struct, starting from the current task. struct task_struct *tskParse; list_for_each_macro (tskParse, &(current->tasks), tasks) { printk (KERN_INFO "task name = %s \n", tskParse->comm) } Regards, Prabhu On Tue, Jan 11, 2011 at 11:32 AM, Hanumant Singh <hanumant07@gmail.com>wrote:
Hi
I am trying to write a simple module that sort of emulates the ps command. I am trying to get the comm string for the task, using get_task_comm, but the make command keeps telling me that the symbol get_task_comm is not defined. I have included linux/sched.h. This is the header file, which I believe has the prototype definition for the function. Am I missing something?
Thanks Hanumant
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Sorry, there was a typo. it is list_for_each_entry On Tue, Jan 11, 2011 at 1:25 PM, Prabhu nath <gprabhunath@gmail.com> wrote:
If you are interested to print some fields of all task_structs. Use the following macro. It will walk thru the entire list of task_struct, starting from the current task.
struct task_struct *tskParse; list_for_each_entry (tskParse, &(current->tasks), tasks) { printk (KERN_INFO "task name = %s \n", tskParse->comm)
}
Regards, Prabhu
On Tue, Jan 11, 2011 at 11:32 AM, Hanumant Singh <hanumant07@gmail.com>wrote:
Hi
I am trying to write a simple module that sort of emulates the ps command. I am trying to get the comm string for the task, using get_task_comm, but the make command keeps telling me that the symbol get_task_comm is not defined. I have included linux/sched.h. This is the header file, which I believe has the prototype definition for the function. Am I missing something?
Thanks Hanumant
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
On Mon, Jan 10, 2011 at 11:55 PM, Prabhu nath <gprabhunath@gmail.com> wrote:
Sorry, there was a typo. it is list_for_each_entry
On Tue, Jan 11, 2011 at 1:25 PM, Prabhu nath <gprabhunath@gmail.com>wrote:
If you are interested to print some fields of all task_structs. Use the following macro. It will walk thru the entire list of task_struct, starting from the current task.
struct task_struct *tskParse; list_for_each_entry (tskParse, &(current->tasks), tasks)
{ printk (KERN_INFO "task name = %s \n", tskParse->comm)
}
Regards, Prabhu
I am using a macro for_each_process () that allows you to iterate over the list of processes.
Hanumant
On Tue, Jan 11, 2011 at 11:32 AM, Hanumant Singh <hanumant07@gmail.com>wrote:
Hi
I am trying to write a simple module that sort of emulates the ps command. I am trying to get the comm string for the task, using get_task_comm, but the make command keeps telling me that the symbol get_task_comm is not defined. I have included linux/sched.h. This is the header file, which I believe has the prototype definition for the function. Am I missing something?
Thanks Hanumant
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (4)
-
Hanumant Singh -
Manish Katiyar -
Prabhu nath -
Rajat Sharma