Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux Bash中的Xargs并行性_Linux_Bash_Shell_Command Line Arguments_Xargs - Fatal编程技术网

Linux Bash中的Xargs并行性

Linux Bash中的Xargs并行性,linux,bash,shell,command-line-arguments,xargs,Linux,Bash,Shell,Command Line Arguments,Xargs,所以我在BASH中有一个函数,我正试图理解它——它使用并行性: function get_cache_files() { ## The maximum number of parallel processes. 16 since the cache ## naming scheme is hex based. local max_parallel=${3-16} ## Get the cache files running grep in parallel for

所以我在BASH中有一个函数,我正试图理解它——它使用并行性:

function get_cache_files() {
    ## The maximum number of parallel processes. 16 since the cache
    ## naming scheme is hex based.
    local max_parallel=${3-16}
    ## Get the cache files running grep in parallel for each top level
    ## cache dir.
    find $2 -maxdepth 1 -type d | xargs -P $max_parallel -n 1 grep -Rl "KEY:.*$1" | sort -u
} # get_cache_files
所以我的问题是:

注释:16因为缓存命名方案是基于十六进制的-命名示例如下: php2-mindaugasb.c9.io/5c/c6/348e9a5b0e11fb6cd5948155c02cc65c-当命名方案是基于十六进制的十六进制系统时,为什么使用16个进程很重要? XARGS的-P选项用于max procs: 一次运行最多个进程;默认值为1。如果max procs为0,xargs将一次运行尽可能多的进程。将-n选项与-P一起使用;否则,很可能只会执行一个exec

好的,那么:xargs-p$max_parallel-n1是正确的,将启动16个进程?或者n也应该等于$max_parallel

据我所知,并联的条件是:

将在其上执行操作的资源的独立性,类似于将在其上执行操作的类似文件; 操作在独立的计算机上执行; 您可以并行化的其他条件和情况是什么

好的,那么:xargs-p$max_parallel-n1是正确的,将启动16个进程?或者n也应该等于$max_parallel

想想商店里的几个付账台和大量等待付账的顾客-P在类比中是这里的账单计数器的数量,16-n是一个柜台一次能够处理的客户数量,1。在这种情况下,很容易在每个柜台上画出大小大致相同的队列,对吗

从问题的角度来看,max_parallel=${3-16}意味着如果$3参数未传递给函数,则变量被设置为16。xargs启动grep的16-P参数并行进程。每个进程从xargs的stdin中只获取一个line-n参数作为最后一个命令行参数。在本例中,xargs的stdin是find命令的输出。总的来说,find命令将列出所有目录,它的输出将被16个grep进程逐行使用。每个grep进程将被调用为:

grep -R1 "KEY:.*$1" <one line from find-output/xargs-input>
注释:16由于缓存命名方案是基于十六进制的-命名示例如下:php2-mindaugasb.c9.io/5c/c6/348e9a5b0e11fb6cd5948155c02cc65c-当命名方案是基于十六进制的十六进制系统时,为什么使用16个进程很重要


我无法理解这背后的逻辑;但我认为更多的是数据的分布和数量。如果find的输出行总数是16的倍数,那么它可能有一定的意义。

我喜欢这样。需要注意的一点是,max_parallel=${3-16}本质上意味着,如果传递给else,则max_parallel设置为$316@1_CR哦,我错过了那部分的写作。让我把它添加到我的答案中。谢谢是的,我也无法理解特定并行数背后的逻辑-据我所见,输出没有向n*16倾斜,它使用排序唯一性排序-最后使用u来消除重复-你能告诉我,如果它产生重复,为什么要使用并行吗?对我来说似乎毫无意义