LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   How to use kernel functions like get_current() in user programs (https://www.linuxquestions.org/questions/linux-kernel-70/how-to-use-kernel-functions-like-get_current-in-user-programs-479661/)

Sreeram B S 09-02-2006 01:29 AM

How to use kernel functions like get_current() in user programs
 
Hi friends,
I have started looking at data structures in Kernel very very recently. However, whenever I come across a data structure, I feel like calling them from my user program just to know its working or current value.
Say, for example, the kernel function get_current(). This is a function, which many system calls like "getpid", "getppid" use. If I want to call this function directly from my program ie, without using system call interface, what libraries should I include?

I tried the following program, but failed !!

#include <stdio.h>
#include <linux/kernel.h>
#include <unistd.h>

int main()
{
struct task_struct *p;

p = get_current();
printf ("UID = %d\n", p->uid);

return 0;
}


This program does not work, it says "Invalid dereferencing". What is the correct procedure to use such kernel functions?
Please guide.

Thanks,
Sreeram

theoffset 09-02-2006 09:09 PM

I might be wrong, but I don't think you can do that without some level of hacking in the kernel source.


All times are GMT -5. The time now is 07:15 PM.