开发者

Where is total_forks from forks.c initialized?

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 c开发者_如何学运维an't find where it is initialized to zero.


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 not static) - these are implicitly initialized to zero. Try this in you own code:

#include <stdio.h>

int var;

int main( int argc, char* argv[] ) {
    printf( "var is %d\n", var );
    return 0;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜