How my script executed? from flash line by line? what if have a loop? or it goes full to RAM?

i wrote a script and there is a loop while in few points
and i wonder does the system reads script every time while looping or my script goes to memory and then executed ?
i just dont want my script reads all the time inside while loop

It would be helpful to post the script....

2 Likes
###################setup part####################################
echo "do somthing "

######################loop part##########################
while :
	do
                sleep 10
               echo "do somthing "
	done
####################################################

The qwestion is how this script executes?
1st part it reads form flash memory
2d part it reads onece and then stays in RAM ? or it reads always from flash memory ?

easy to test,
modify the script while it loops, if the changes have no effect, you've got your answer ...

3 Likes

just tested it does not stop the loop so loop part executes in memory which is good
one more qwestion
dir /tmp/ in RAM ?

yes, it's RAM.

1 Like

if a script executes an other script and another script does not loop it always reads from flash ?
so i have to put those scripts in tmp directory so flash wont be use?

is it good to execut scripts from tmp directory ?

Reading is never a problem, writing is, and that only applies to flash.

2 Likes

No, Linux caches reads from external memory in RAM. It will read the file again from flash, but only if it changes or if it gets purged from the cache if you fill the ram with other data.

2 Likes

in my case inside of loop there is executing other scripts wich is not loopy so every time they reads from flash i gues (if they in bin directory for example )
so i have to put and execute those to tmp , right ?

###################setup part####################################
echo "do somthing "

######################loop part##########################
while :
	do
                sleep 10
               echo "do somthing "
/bin/ash  /bin/mykika.sh 
	done
####################################################

like in this case mykika.sh always will be read from flash memory?

Why do you think you need to put them in tmp? The script will be read once and then used from cache in ram.

Do you know that what you are trying to do (copy it to /tmp on boot) is almost exactly the same as just calling the file directly from /bin. The same code is used for caching files when read from external storage and for storing files temporarily in memory, just with different settings.

But also, reading from flash is not going to kill it no matter how many times you do it - in your case will be once per boot.

4 Likes

what if i have exit 0 at the end os mukika.sh script ?
no, look at the last script there is child script executes every 10 secunds and has exit 0 at the end

Disk caching is a standard feature of the Linux kernel. There is no need to copy scripts or binaries to a RAM disk. If a file is executed repeatedly, a cached copy in RAM will almost certainly be used unless RAM space is very tight.

4 Likes

i hope so, reading from flash every 5 seconds is not good

Why, where is the problem?

1 Like

u can read from RAM almost unlimited times , reading from flash has limit , it is a big number but not really
between 10,000 to 100,000 so lets say i use china low quality flash AP (10 000 *5)/60/60/24 days only

about 16 hours or few days

I think you're getting confused between reading and writing.

3 Likes

no i googled