Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

find_task_by_pid() problem

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


vale.pistis at gmail

Aug 9, 2010, 6:14 PM

Post #1 of 3 (6191 views)
Permalink
find_task_by_pid() problem

Hello everyone,

first of all, thank you all for your work on the Linux kernel.

I am not very practical programming kernel, I admit, but studying how
to build a kernel module I found a possible problem.

I'm using the routine find_task_by_vpid () linux / sched.h (the oldest
find_task_by_pid() don't exist), but when I try to compile the file I
hello_world.c returns an error:

foo [at] siduxbo: ~ / LPSO / modules / hello_world $ make
make-C / usr/src/linux-2.6.34.2 subdirs = / home / foo / LPSO /
modules / modules hello_world
make [1]: Entering directory `/ usr/src/linux-2.6.34.2 '
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "find_task_by_vpid [/
home/foo/LPSO/modules/hello_world/hello_world_6.ko] undefined!
make [1]: Leaving directory `/ usr/src/linux-2.6.34.2 '
foo [at] siduxbo: ~ / LPSO / modules / $ hello_world

My surprise is why the function is undefined if it is present in sched.h?

In any case, the function is not defined in sched.c, but directly to
the file pid.c.
Given that pid.h not present the prototype of the function in question.

I'm using Debian Sidux with Linux 2.6.34.2 compiled.

I just can not understand why give me this problem .

I tried to use kernel 2.6.20 for using the old "DEFINE
find_task_by_pid" , but I have problems compiling the kernel and can
not use them.

You could at least tell me if this is a bug or am I not use good routines.


Thank you all


================
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/pid.h>
MODULE_LICENSE ("Dual BSD/GPL");

//static int num=1;
//static char *string="Ciao";

static int p=0;

/*struct task_struct *find_task(pid_t pid)
{
    struct task_struct *task = current;

    do
    { if(task->pid == pid)
        return(task);
        task = task->next_task;
    }
    while(task != current);

    return(NULL);
}
*/
static int hello_init (void)
{
    printk(KERN_ALERT "*********** INIT **********\n");
    printk(KERN_ALERT "Hello, world\n");

    pid_t pid = p;
    struct task_struct *task, *parent;
    task=current;
    parent=find_task_by_vpid(pid);


    printk(KERN_ALERT "Some info from some Process\n");

    //Always initialize the task_struct

    printk("\nThe current task is: %s [%d]\n",task->comm , task->pid);
    printk("\nThe parent task is: %s [%d]\n",parent->comm , parent->pid);

    printk("\nThe credential of current task is:\n Priority = %d\n
euid = %d\n egid = %d\n",task->prio , task->real_cred->euid,
task->real_cred->egid);
    printk("\nThe credential of parent task is:\n Priority = %d\n euid
= %d\n egid = %d\n",parent->prio , parent->real_cred->euid,
parent->real_cred->egid);

    return 0;
}

static void hello_exit (void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
    printk(KERN_ALERT "*********** EXIT **********\n");
}

module_init(hello_init);
module_exit(hello_exit);
//module_param(num, int, S_IRUGO);
//module_param(string, charp, S_IRUGO);
module_param(p, int, S_IRUGO);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


namhyung at gmail

Aug 9, 2010, 8:32 PM

Post #2 of 3 (5958 views)
Permalink
RE: find_task_by_pid() problem [In reply to]

> I'm using the routine find_task_by_vpid () linux / sched.h (the oldest
> find_task_by_pid() don't exist), but when I try to compile the file I
> hello_world.c returns an error:

You can only use kernel's EXPORTed symbol, ie. EXPORT_SYMBOL*(), when you
write a module program because kernel links it on its own way.
Try this instead.

pid_task(find_vpid(...), PIDTYPE_PID)

--
Regards,
Namhyung Kim


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


vale.pistis at gmail

Aug 10, 2010, 1:39 AM

Post #3 of 3 (5974 views)
Permalink
Re: find_task_by_pid() problem [In reply to]

2010/8/10 Namhyung Kim <namhyung [at] gmail>:
>> I'm using the routine find_task_by_vpid () linux / sched.h (the oldest
>> find_task_by_pid() don't exist), but when I try to compile the file I
>> hello_world.c returns an error:
>
> You can only use kernel's EXPORTed symbol, ie. EXPORT_SYMBOL*(), when you
> write a module program because kernel links it on its own way.
> Try this instead.
>
> pid_task(find_vpid(...), PIDTYPE_PID)
>
Great!
It works!

pid_task(find_vpid(pid), PIDTYPE_PID);

> --
> Regards,
> Namhyung Kim
>
>
>

Thank you!
Ciao
Valentino from Sardegna!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.