I’m trying to understand how system call works in Linux kernel. One question I have is, how can I retrieve the pid of the process making a system call?
e.g. I’m looking at read() call (sync read) which I think is defined in fs/read_write.c as
ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
In the system call context (which is the context of the calling process) you can check the global variable
currentwhich is of typestruct task_structthis containts apidfield you can get the pid from.Just do
current->pidto get the pid of the current task context you are in.I’m assuming you mean the actual code for the system call defined in the kernel.