[英]Why use the mkdir () function is much faster than using system ('mkdir path')?
I am creating an application and I need to create multiple folders and creating folders are inside a go. 我正在创建一个应用程序,并且需要创建多个文件夹,并且可以在其中创建文件夹。
Gotta make the most optimized, then I realized that mkdir () is considerably faster than system ('mkdir path'); 必须进行最优化,然后我才意识到mkdir()比系统(“ mkdir path”)要快得多;
Does anyone know the reason? 有人知道原因吗?
system ("mkdir path");
calls a program mkdir
, that is spawns a new process with all that it implies. 调用程序mkdir
,该程序将产生一个包含其所有含义的新进程。
mkdir()
just calls a system routine. mkdir()
只是调用系统例程。
mkdir()
calls the system call documented by man 2 mkdir
. mkdir()
调用man 2 mkdir
记录的系统调用。 The function is run within the same process. 该功能在同一过程中运行。
system('mkdir path')
forks a new process which runs the mkdir
command, documented by man 1 mkdir
, which despite the same name is a separate command that provides a command-line interface to mkdir
system call. system('mkdir path')
派生一个新进程,该进程运行mkdir
命令,该命令由man 1 mkdir
,尽管同名,但它是一个单独的命令,为mkdir
系统调用提供了命令行界面。
从shell调用mkdir
产生大量开销(shell本身,产生新进程等 ),直到最终直接调用相同的内核代码mkdir()
为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.