[NTLUG:Discuss] Script help
Wayne Walker
wwalker at solid-constructs.com
Wed Sep 15 10:37:38 CDT 2010
On Wed, Sep 15, 2010 at 08:07:57AM -0700, Fred wrote:
> On Tues 14 Sep 2010 "Patrick R. Michaud" <pmichaud at pobox.com> wrote:
>
> > Out of curiosity, why not use cron to run it periodically
> > instead of always running and sleeping?
> >
> > Pm
>
> It is my understanding that to use cron would require me to
> rewrite the script. Besides, I'm not at all sure how using cron
The rewrite would probably be limited to removing "while true; do sleep
1" and "end".
> in this instance would benefit me. I would think that the process
cron is well vetted. It "just works". But, we don't know enough about
your app to evaluate. Just pointing out a possible alternative.
> id numbers would get pretty big after a while after starting that
> program every minute. Not that big numbers are a problem
> with modern kernels, but ...
when it crosses the max number (32K I think) it just starts over. The
pid isn't a problem.
The math comes out pretty close:
[wwalker at speedy ~] [] $ date;bash -c 'echo $$';(for i in `seq 1 100000`; do sleep 0.0001; done;) > a 2>&1; date; bash -c 'echo $$'
Wed Sep 15 10:30:17 CDT 2010
16419
Wed Sep 15 10:34:14 CDT 2010
20302
[wwalker at speedy ~] [] $ ps -ef | wc -l
282
[wwalker at speedy ~] [] $ python
Python 2.6.4 (r264:75706, Jun 4 2010, 18:20:31)
[GCC 4.4.4 20100503 (Red Hat 4.4.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 16419 + 100000 + 2
116421
>>> _ - (32767 - 282)
83936
>>> _ - (32767 - 282)
51451
>>> _ - (32767 - 282)
18966
Apparently, something started 1400 processes during the time that this
was running.
While this was running, starting a new process every 3 milliseconds, I
was unable to tell that it was going on. The machine, mouse, etc. were
all still fully responsive with no indication that anything was going
on.
Process startup overhead on linux is quite low.
--
Wayne Walker
wwalker at solid-constructs.com
(512) 633-8076
Senior Consultant
Solid Constructs, LLC
More information about the Discuss
mailing list