bneupaane
bneupaane

Reputation: 537

In Linux how do I retrieve the pid of the process making a system call

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)

Upvotes: 3

Views: 5726

Answers (1)

Jesus Ramos
Jesus Ramos

Reputation: 23266

In the system call context (which is the context of the calling process) you can check the global variable current which is of type struct task_struct this containts a pid field you can get the pid from.

Just do current->pid to 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.

Upvotes: 8

Related Questions