Script to loop process

As I would like to test the open files usage , I would like to have a process that use the open files up to a certain amount eg. 1000 .

If I want to have a script ( may be run in a loop ) that could repeatly use open files resource , so that the usage of open files increases , may I know how to write such a script ?

or simply

if I would like to have a script run in a loop that repeatly use open files resource , what can I do ?

thanks

Shells are not known for their ability to opens hundreds of files. Certainly, you could write for loops nested to hundreds of levels with input for each loop redirected (and, therefore, each loop eating up an additional file descriptor) and your shell might or might not be willing to accept and run that script.

If you want to open hundreds of file descriptors just to keep them open and do nothing with them, it would be much easier to do it in C than in shell.

thanks reply,

yes , what I would like to do is eating up an additional file descriptor , would advsie a simple script to do that ?

thanks

---------- Post updated at 12:29 PM ---------- Previous update was at 10:35 AM ----------

I just would like have a script to repeatly eating up open files , so that make it increase to a certain level

while read d1
do while read d2
   do while read d3
      do while read d4
         do while read d5
            do # whatever
            done < f5
         done < f4
      done < f3
   done < f2
done < f1

I told you exactly what to do in post #2 in this thread. Above is an example of how to waste time with five file descriptors. Feel free to increase this to a thousand file descriptors if you want. I make no guarantee that any shell will work if you nest this to 1000 levels instead of 5. And, I see no reason why doing so would be advantageous in any real-world application.

thanks reply ,

when run it , it pops the error "syntax error near unexpected token `done'
" .

besides , instead , add d1 , d2 , d3 .... , how to loop it to 1000 ?

thanks

You need to replace # whatever with some real code. You have never said what you want to do with those one thousand open files and I have no idea what you want to do with those one thousand open files. Replicate the code I provided to once thousand levels instead of five levels and replace the innermost level with code that does whatever you want to do with 1000 open files. Maybe your shell will process it; maybe it won't.

You know exactly how to expand this from five levels to one thousand levels! I'm not going to do it for you. This whole scheme seems like busywork to me.

thank reply ,

I changed the code to as below

while read d1
do while read d2
do while read d3
do while read d4
do while read d5
do echo "abc"
done < f5
done < f4
done < f3
done < f2
done < f1

after run it , it pops "

f1: No such file or directory

" .

may be there is a simpler method .
if I would like to have a script a open a certain amount of files ( eg. 1000 ) in background mode , would advise how to write such script ?

thanks

Hello ust3,

I would like to suggest you please provide complete information about what you are trying to achieve here, it is the simple error which you are getting. You are getting "f1: No such file or directory" because there will not be any file present into your path named f1 (You should provide files which are present in the path where you are trying the loop, else provide the exact files path to it.). Without knowing the complete picture of requirement we all here could only guess and increase the number of posts in this thread, hope this helps.

Thanks,
R. Singh

May I doubt that it is wise to explore the limits of your system if you don't know why f1: No such file or directory pops up and how to remedy it?

If you really really want to try sth - at your own risk - here's small example of what you could do (with a recent shell)

for i in {5..15}; do eval exec "$i>f$i"; done
lsof -p$$
for i in {5..15}; do eval exec "$i>&-"; done

thanks reply ,

the script seems create file but not eating up open file , right ?
if I would like to eating up open file , how to modify it ? thanks

Your use of the phrase "eating up open file" is a technical term that is not clear to me (and, apparently, it is not clear to the other volunteers here who are trying to help you.

I gave you code that would read lines from files (but you would have to modify that script to use filenames that you had already created and had loaded with the data you wanted to read) and left a comment where you could fill in whatever code you wanted to use to eat your files. Ravinder showed you how to change that comment into a simple echo that would let the script read your files without actually doing anything with the data found in the files. RudiC gave you code that creates files and keeps file descriptor open (i.e., eats up open file descriptors) until the script terminates. Obviously, none of these meet your goal of eating your file(s).

If you would like to explain to us exactly what you are trying to do and why you are trying to do it, we may be able to help you achieve your goal.