【问题标题】:Where the system call function “sys_getpid” is located in the linux kernel?系统调用函数“sys_getpid”在linux内核的什么位置?
【发布时间】:2012-02-18 11:47:40
【问题描述】:

我正在内核中搜索“getpid”函数,但是我找不到实际的函数。

应该是这样的:

asmlinkage long sys_getpid(void)
{
return current-> tgetid;
}

我能找到的只是系统调用表,而不是这个系统调用的实际实现。

内核版本为:3.0.20

提前致谢。

【问题讨论】:

    标签: operating-system linux-kernel kernel


    【解决方案1】:

    实际定义在kernel/timer.c:

    /**
     * sys_getpid - return the thread group id of the current process
     *
     * Note, despite the name, this returns the tgid not the pid.  The tgid and
     * the pid are identical unless CLONE_THREAD was specified on clone() in
     * which case the tgid is the same in all threads of the same group.
     *
     * This is SMP safe as current->tgid does not change.
     */
    SYSCALL_DEFINE0(getpid)
    {
        return task_tgid_vnr(current);
    }
    

    task_tgid_vnrinclude/linux/sched.h 中的静态内联。

    【讨论】:

    • 抱歉,我仍然无法找到该文件。在不同的目录 (arch) 中有很多 timer.c。我需要看哪一个?
    • kernel_source_dir/kernel/timer.c,如上所述。
    • 内核3.0.20的kernel_source_dir根目录下没有这个目录。我也有 2.6.32.56,我可以在你说的目录中看到这个 timer.c 文件,但是我再次在 3.0.20 的根目录中找不到名为 kernel 的目录。
    • 至少以下版本有这样的目录:linux-3.0.3-gentoo/kernel/timer.c linux-3.1.0-gentoo/kernel/timer.c linux-3.1。 4-gentoo/kernel/timer.c linux-3.1.5-gentoo/kernel/timer.c linux-3.1.6-gentoo/kernel/timer.c linux-3.2.1-gentoo/kernel/timer.c linux- 3.2.5-gentoo/kernel/timer.c - 我相信它也存在于所有 2.6 版本中。请确保您有完整的内核源代码提取。您还可以在线查看源代码,例如这里:git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=tree
    • 谢谢你,Mat,我认为我拥有的内核缺少一些目录。
    猜你喜欢
    • 1970-01-01
    • 2015-05-05
    • 2010-09-20
    • 1970-01-01
    • 2012-11-18
    • 1970-01-01
    • 2016-02-20
    • 2020-01-17
    • 2013-07-13
    相关资源
    最近更新 更多