bash 管道限制
我有一个我想要下载的 url 的 txt 列表,
n=1
end=`cat done1 |wc -l`
while [ $n -lt $end ]
do
nextUrls=`sed -n "${n}p" < done1`
wget -N nH --random-wait -t 3 -a download.log -A$1 $nextUrls
let "n++"
done
我想用管道更快地完成它,但如果我这样做,
wget -N nH --random-wait -t 3 -a download.log -A$1 $nextUrls &
我的内存就会填满并完全阻止我的电脑。 有人知道如何限制同时创建的管道数量为 10 个吗?
i got a txt list of urls i want to download
n=1
end=`cat done1 |wc -l`
while [ $n -lt $end ]
do
nextUrls=`sed -n "${n}p" < done1`
wget -N nH --random-wait -t 3 -a download.log -A$1 $nextUrls
let "n++"
done
i want to do it faster with pipes but if i do this
wget -N nH --random-wait -t 3 -a download.log -A$1 $nextUrls &
my ram fills up and blocks my PC completely.
Any1 know how to limit pipes created to like 10 at the same time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不是在创建管道 (
|
),而是在创建后台进程 (&
)。每次while
执行其主体时,您都会创建一个新的wget
进程,并且不等待它退出,这(取决于end
的值) code>)可能会非常快地创建很多个wget
进程。要么按顺序执行(删除&
),要么您可以尝试 并行执行n个进程并等待它们。顺便说一句,
cat
的使用毫无用处:您可以简单地执行以下操作:You are not creating pipes (
|
), you are creating background processes (&
). Everytime yourwhile
executes its body, you create a newwget
process and don't wait for it to exit, which (depending on the value ofend
) may create lot ofwget
processes very fast. Either do sequentially (remove the&
) or you can try executing n processes in parallel and wait for them.BTW, useless use of
cat
: you can simply do:所以这里有一个最短的方法来做到这一点。以下命令并行运行 10 个线程,从文件 *txt_list_of_urls* 中包含的列表下载 URL:
So here's a shortest way to do that. The following command downloads the URL from the list contained in file *txt_list_of_urls* parallely running 10 threads: