I am new in Linux kernel development. I have implemented a system call say my_pid in linux kernel 2.6. I want to call getpid system call from my system call. How can I do it?
There is no generic way of doing this.
If you are in kernel space, you should invoke kernel functions that implement the system call functionality directly instead of using syscall
-type instructions, or use other means of extracting the desired information / affecting the desired action.
For the specific case of getpid()
, you can simply use current->pid
.
The kernel name current
is always a pointer to the current task_struct
, which is defined via <linux/sched.h> (search for struct task_struct
). Code that accesses members of that usually gets inlined, i.e. there's not even a function call (and much less a system call) required to get these when your code is running as part of the kernel.