2

I have added a custom system call in Linux Kernel. Now I want to find out the id of the process which issued that system call. If I use current pointer in the system call, I will get the information of the currently running process. It may not be the actual process which issued the system call especially in a multi-process environment. For example, in a user space program I have the code.

int pid = fork();
if(pid < 0) {
    <statements>;
} else if(pid == 0) {
    mysystemcall();
}

This is just an illustration. Now we don't know the order of execution of the parent and child process. Inside a system call, the current pointer may not be pointing to the task_struct of the parent process which issued that system call. So how can I find that process

Kanishk
  • 506
  • 3
  • 14
  • 3
    `current` is always the process that issued the system call. See [here](http://stackoverflow.com/questions/12434651/what-is-the-current-in-linux-kernel-source). – n. m. could be an AI Oct 26 '14 at 21:34

1 Answers1

1

current always points the task_struct for the process which invokes your custom syscall, therefore read and return the current->tgid, as this returns the pid of the process which invokes the system call. Note the pid is the process id and tgid is the thread group id, so for heavy weight process, as invoked by fork(), pid == tgid.

askb
  • 6,501
  • 30
  • 43