Script to loop process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to loop process
# 1  
Old 01-27-2016
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
# 2  
Old 01-27-2016
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.
# 3  
Old 01-28-2016
Quote:
Originally Posted by Don Cragun
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
# 4  
Old 01-28-2016
Quote:
Originally Posted by ust
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 repeatedly eating up open files , so that make it increase to a certain level
Code:
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.
# 5  
Old 01-28-2016
Quote:
Originally Posted by Don Cragun
Code:
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
# 6  
Old 01-28-2016
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.
# 7  
Old 01-28-2016
thank reply ,

I changed the code to as below

Code:
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 "
Code:
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

Last edited by Scrutinizer; 01-28-2016 at 05:07 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Process files in loop which have spaces in name

I have a folder with files and I have to process them in a loop. However the filenames have space characters, so the list get split. $ touch "File Number_1" $ touch "File Number_2" $ ls "/tmp/File Number"_* /tmp/File Number_1 /tmp/File Number_2 I tried following (sorry for using the... (3 Replies)
Discussion started by: Wernfried
3 Replies

2. UNIX for Dummies Questions & Answers

For loop in process each file

Hi I have following codecd /tmp/test/ for vfile in `ls -1` do for vlink in `ls -l /tmp/testfile/*|bin/grep "local/init\.d/$vfile$"|bin/awk -F"->" '{print($1)}'|bin/awk -F"/" '{print($NF)}'` I know `ls -1` list only file, but I don't... (3 Replies)
Discussion started by: stew
3 Replies

3. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

4. Shell Programming and Scripting

Infinite while loop script shows more than one process

Hi, I have a script which triggers an infinite loop. #!bin/bash trig=`ls /home/trig.tch |wc -l` function callj { some commands... } while do callj & done The number of process after doing a ps -ef |grep Mon.sh returns processes even after the script is killed by deleting the... (4 Replies)
Discussion started by: chetan.c
4 Replies

5. Shell Programming and Scripting

need to process for loop faster

I have the following code running against a file. The file can have upwards of 10000 lines. problem is, the for loop takes a while to go through all those lines. is there a faster way to go about it? for line in `grep -P "${MONTH} ${DAY}," file | ${AWK} -F" " '{print $4}' | awk -F":"... (2 Replies)
Discussion started by: SkySmart
2 Replies

6. UNIX for Dummies Questions & Answers

Writing a loop to process multiple input files by a shell script

I have multiple input files that I want to manipulate using a shell script. The files are called 250.1 through 250.1000 but I only want the script to manipulate 250.300 through 250.1000. Before I was using the following script to manipulate the text files: for i in 250.*; do || awk... (4 Replies)
Discussion started by: evelibertine
4 Replies

7. Shell Programming and Scripting

Process checking loop

Hi, I want to create a script who will check if the java process is running & if it finds the process is still there it continues to execute & when the process completes it exit from the script. I have written a code to check & notify the process existence but i am not getting how to write... (4 Replies)
Discussion started by: d8011
4 Replies

8. Shell Programming and Scripting

How to loop this process?

for two txt files, f1 and f2, I like to do the following grep "abcde" f1 > abcde$f1 grep "xyz" f1 > xyz$f1 can I use a loop to get this done? Thanks for i in f1 f2 do grep "abcde" $i > abcde$i grep "xyz" $i > xyz$i ... done (11 Replies)
Discussion started by: ksgreen
11 Replies

9. Shell Programming and Scripting

script to loop all process ids and take pmap

Hi all, I need a script that will loop around all the current processes and take a pmap -x <process id> and output each pmap to a separate file. Would anyone have a quick command to do this? (2 Replies)
Discussion started by: borderblaster
2 Replies

10. Shell Programming and Scripting

loop when process running

Hi Gurus, Could you please help me to create a shell script that will be started by a cron job once every night at 24.00 h (that should bee easy:)) The shell script should control every 30 seconds the name of a process, and when the process doesn't run anymore it should execute a few further... (12 Replies)
Discussion started by: blackwire
12 Replies
Login or Register to Ask a Question