expert , alternative for sleep not use memory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expert , alternative for sleep not use memory
# 1  
Old 10-08-2011
expert , alternative for sleep not use memory

Code:
while sleep 1; do
pgrep Polo || {
                  kill `pidof Polo` >/dev/null 
    
    /var/bin/polo_start.sh start &
    echo `date` R >> /var/log/Check_Polo .log
    }
done
exit 0

well , i use that script as a watchdog in my box (with has just 32 mb memory) which check every second if Polo binary is not running , it would start it. this works functionally right here.
but the problem is , it always use memory for sleep 1 command (since my box has a few memory and this watchdog is always running so it's really important for me to save memory of them ) as in top command always shows:
Code:
Command                                %MEM  
sleep 1                                4.7% 
[pgrep]                                 5 %

i need expert advice , how to change or improvw my script (esp those command) to would not use memory for sleep 1, ... or on the other words use least memory resources. would really appreciate any helps.

P.s : Linux 2.6.23.17_stm23_A21 #1 PREEMPT sh4 GNU/Linux
and pgrep , ... comes from busybox.
Best Regards.

Last edited by pooyair; 10-08-2011 at 08:23 AM..
# 2  
Old 10-08-2011
As an alternate to sleep, have you considered using ping? Read the man page appropriate to your OS and define it to ping the local host twice. This usually takes one second, but do check it. Various OS have different options, so you might have one of the following:-
Code:
ping -c2 localhost >/dev/null 2>&1
ping -n 2 localhost >/dev/null 2>&1
ping -c 2 -t 1 localhost  >/dev/null 2>&1

I'm not sure if that is lighter on memory, but it's worth a try.


I hope that this helps,
Robin
Liverpool/Blackburn
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 10-08-2011
Quote:
Originally Posted by pooyair
Code:
while sleep 1; do
pgrep Polo || {
                  kill `pidof Polo` >/dev/null 
    
    /var/bin/polo_start.sh start &
    echo `date` R >> /var/log/Check_Polo .log
    }
done
exit 0

well , i use that script as a watchdog in my box (with has just 32 mb memory) which check every second if Polo binary is not running , it would start it. this works functionally right here.
but the problem is , it always use memory for sleep 1 command (since my box has a few memory and this watchdog is always running so it's really important for me to save memory of them ) as in top command always shows:
Code:
Command                                %MEM  
sleep 1                                4.7% 
[pgrep]                                 5 %

i need expert advice , how to change or improvw my script (esp those command) to would not use memory for sleep 1, ... or on the other words use least memory resources. would really appreciate any helps.

P.s : Linux 2.6.23.17_stm23_A21 #1 PREEMPT sh4 GNU/Linux
and pgrep , ... comes from busybox.
Best Regards.

I have no experience with busybox (that I'm aware of) and haven't used linux very much during the past few years. That said, I think you may be overestimating the memory impact of running sleep.

All of sleep's code, the text segment of the executable, is already in ram since the shell running that script is the same exact binary. Since sleep, pgrep, pidof, date, echo, kill, sh, sleep, et al, are all instances of the busybox binary (only thing that differs is the name used to exec them), the kernel is able to run many instances of the binary using only a single copy of their code (the memory management subsystem maps that single copy of the text segment into each process' address space).

By the way, ping is also busybox, so that won't save anything (it will probably hurt a bit, as a ping is more complicated than a sleep).

Resorting to a non-busybox binary that isn't already in use will certainly be counterproductive. Its text segment is not shared with another extant process and so it will consume an amount of ram equal to its size (whereas a shared text segment consumes nearly nothing for each additional instance of that binary).

Are you certain you have a problem?

Regards,
Alister

Last edited by alister; 10-08-2011 at 04:48 PM..
This User Gave Thanks to alister For This Post:
# 4  
Old 10-08-2011
Thanks both guys for reply.
alister , u are right , ping not save any memory even it use a bit more than sleep. (i tested it) .

Last edited by pooyair; 10-09-2011 at 11:45 AM..
# 5  
Old 10-08-2011
Quote:
Originally Posted by pooyair
Code:
while sleep 1; do
pgrep Polo || {
                  kill `pidof Polo` >/dev/null 
    
    /var/bin/polo_start.sh start &
    echo `date` R >> /var/log/Check_Polo .log
    }
done
exit 0

well , i use that script as a watchdog in my box (with has just 32 mb memory) which check every second if Polo binary is not running , it would start it. this works functionally right here.
but the problem is , it always use memory for sleep 1 command (since my box has a few memory and this watchdog is always running so it's really important for me to save memory of them ) as in top command always shows:
Code:
Command                                %MEM  
sleep 1                                4.7% 
[pgrep]                                 5 %

i need expert advice , how to change or improvw my script (esp those command) to would not use memory for sleep 1, ... or on the other words use least memory resources. would really appreciate any helps.

P.s : Linux 2.6.23.17_stm23_A21 #1 PREEMPT sh4 GNU/Linux
and pgrep , ... comes from busybox.
Best Regards.
Are you sure that 4.7% is right? Are you sure that percent doesn't count shared memory? That sounds inflated...
# 6  
Old 10-09-2011
solved

Last edited by pooyair; 10-09-2011 at 07:48 AM..
# 7  
Old 10-09-2011
Pooyair, rather than just leaving a cryptic message "solved", it would be nice to tell people how you solved the problem.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Alternative to Sleep?

Greetings. I've been wondering about this one for some time: Is there an alternative to sleep in bash? The reason: I'd like to simply limit the amount of processor usage in continuous while : script scenarios without spawning endless sleep processes as well. After beating the manpages, I... (14 Replies)
Discussion started by: LinQ
14 Replies

2. Solaris

Becoming a Solaris expert?

Hello everyone, how do you really study to become an expert in solaris OS? Thanks (3 Replies)
Discussion started by: cjashu
3 Replies

3. Shell Programming and Scripting

Expert cp command

How can I use the cp command to copy every file that I can find inside several folders cp -R *test* folder Supose there is ./122342343teste122343.txt ./bound/123teste1223453.txt ./feed/123teste1223453.txt and i want the files 122342343teste122343.txt, bound/123teste1223453.txt... (12 Replies)
Discussion started by: lipe.82
12 Replies

4. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

5. UNIX for Advanced & Expert Users

Expert Opinion

This perhaps does not belong in ths category; apologies, however, we have a heated debate going and your input will decide the result. Should UNIX (HP, AIX, etc) be rebooted following a monthly cycle (Every month, or a qtr, etc.). We have some UX admins (grumps) who say they have seen a UX... (6 Replies)
Discussion started by: rsheikh
6 Replies

6. Solaris

expert vi commands

:) Hi UNIX friends, Where do I get advanced vi commands to practice. Please Help Me. Love (4 Replies)
Discussion started by: Love
4 Replies
Login or Register to Ask a Question