Mapping socket to task

Lal learner.kernel at gmail.com
Fri Oct 12 00:48:20 EDT 2012


How to get task_struct of a socket owner process? i.e. how to get
task_struct* from sock*

I have tried following (on 2.6.38) but didn't work.

struct sock* sk = xxx;
(i) sk->sk_socket->file->f_cred->uid
(ii) tsk = get_pid_task(sk->sk_socket->file->f_owner->pid,
sk->sk_socket->file->f_owner->pid_type)

The goal is know which process opened the socket. (I know netstat -p
option, and /proc/<pid>/fd methods, but I want to do it in kernel
module only).

Thank you
Lal



More information about the Kernelnewbies mailing list