forks.c 中的total_forks 在哪里初始化?
您好,我正在尝试创建一个计数器,它只计算 Linux 内核源代码中 fork.c 中调用系统调用 vfork() 的次数。我正在关注total_forks是如何实现的。 Total_forks 在 sched.h 中定义。但我找不到它在哪里初始化为零。
Hi I am trying to create a counter that will just count the number of times the system call vfork() has been called in fork.c in the Linux kernel source. I'am following how total_forks is implemented. Total_forks is defined in sched.h. But I can't find where it is initialized to zero.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜您正在谈论 Linux 内核,以及
sched.h
中声明的变量和定义 此处。它是一个全局变量(在文件范围定义,而不是静态
) - 这些变量被隐式初始化为零。在您自己的代码中尝试一下:I'm guessing you are talking about the Linux kernel, and the variable declared in
sched.h
and defined here. It's a global variable (defined at file scope and notstatic
) - these are implicitly initialized to zero. Try this in you own code:我不熟悉您正在查看的源代码,但我想到了一些想法:
当
init
启动时,它可能会初始化为 1。它可能被初始化为 0,因为它位于 BSS 段中;运行时系统知道要初始化变量的一部分内存,并在早期启动时将其交给“主”内核进程之前将其全部清除。
I'm unfamiliar with the source you're looking at, but a few thoughts spring to mind:
It may be initialized to 1 when
init
is started.It may be initialized to 0 because it is in the BSS segment; the runtime system knows to initialize a portion of memory for variables and clears it all before giving it to the 'main' kernel process at early boot.