Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';无法从结构套接字获取所有者信息:sk_peer_pid始终为空_C_Linux_Sockets_Linux Kernel - Fatal编程技术网

Can';无法从结构套接字获取所有者信息:sk_peer_pid始终为空

Can';无法从结构套接字获取所有者信息:sk_peer_pid始终为空,c,linux,sockets,linux-kernel,C,Linux,Sockets,Linux Kernel,我试图从struct sock中查找PID,因此我使用了以下代码: struct task_struct *get_task_from_sock(struct sock *sk) { struct task_struct *task = NULL; if (sk == NULL) { pr_info("sk is NULL"); return 0; } if (sk->sk_peer_pid ==

我试图从
struct sock
中查找PID,因此我使用了以下代码:

struct task_struct *get_task_from_sock(struct sock *sk)
{
    struct task_struct *task = NULL;
    if (sk == NULL)
    {
        pr_info("sk is NULL");
        return 0;
    }

    if (sk->sk_peer_pid == NULL)
    {
        pr_info("sk_peer_pid is NULL");
        return 0;
    }

    return get_pid_task(sk->sk_peer_pid, PIDTYPE_PID);
}
但是sk_peer_pid总是空的。所以我参考了源代码:

# grep sk_peer_pid -r
include/net/sock.h:  *  @sk_peer_pid: &struct pid for this socket's peer
include/net/sock.h: struct pid      *sk_peer_pid;
net/core/sock.c:        cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
net/core/sock.c:    put_pid(sk->sk_peer_pid);
net/core/sock.c:    sk->sk_peer_pid     =   NULL;
net/unix/af_unix.c: put_pid(sk->sk_peer_pid);
net/unix/af_unix.c: sk->sk_peer_pid  = get_pid(task_tgid(current));
net/unix/af_unix.c: put_pid(sk->sk_peer_pid);
net/unix/af_unix.c: sk->sk_peer_pid  = get_pid(peersk->sk_peer_pid);
它只适用于unix本地套接字吗

如何找到
struct sock
的所有者?我读过,它从来没有提到如何从struct sock获取PID

有人知道吗