NodeJs 的 main 函数在 node_main.cc 文件中, NodeJs 区分了 WIN32 、 UNIX 、 LINUX 。我们主要分析 Linux 部分。
简化一下代码,我们得到 main 函数的主要代码。
int main(int argc, char* argv[]) { node::per_process::linux_at_secure = getauxval(AT_SECURE); // Disable stdio buffering, it interacts poorly with printf() // calls elsewhere in the program (e.g., any logging from V8.) setvbuf(stdout, nullptr, _IONBF, 0); setvbuf(stderr, nullptr, _IONBF, 0); return node::Start(argc, argv); } node 是 NodeJs 部分的 namespace ,与 V8 的相区分。