Sunday 15 May 2011

objective c - How to run only N thread at time of curl in Bash? -



objective c - How to run only N thread at time of curl in Bash? -

i writing console programme in objective-c. create 10k urls download. when create url, can download with:

system("curl --url 'url' --output 'path'");

downloading 1 1 slow work. tried utilize thread hard implement. so, create dirty algorithm:

for(x in 1 n) write 'finish' in file name_x.txt while(there url) { thread=-1; for(x in 1 n){ check file name_x.txt exist , if can delete it; if (true) delete file , set thread=x } if(thread!=-1) { download(url, thread) } else { wait(1) // , seek 1 time again } } function download(url, thread) { system("curl --url '%s' -o 'myfile.html' && echo 'finish' > name_%i.txt &", url, thread); }

and... work perfectly. know not best strategy, increment speed download insanely more.

but... log show lot of error messages. download 70% of page want. download rest in 1 thread.

the log show errors in way:

sh: fork: resource temporarily unavailable scheme homecoming = 32768 // or 0x8000 sh: fork: resource temporarily unavailable scheme homecoming = 32768 ....

and

sh: fork: resource temporarily unavailable sh: fork: resource temporarily unavailable .... scheme homecoming = -1 // or 0xffff scheme homecoming = -1 ....

what mean? scheme (mac os x 10.7.5) can't run number of jobs set (45)? decrease , see same error..

how can solve it, or how can download 10k pages downloading n pages @ time?

objective-c c multithreading bash curl

No comments:

Post a Comment