[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cronjobs and top not getting along




charles@lunarmedia.net wrote:
> 
> > 181     int user = Procinfo::cpu_time[Procinfo::CPU_USER]
> > 182                - Procinfo::old_cpu_time[Procinfo::CPU_USER];
> > 183     int nice = Procinfo::cpu_time[Procinfo::CPU_NICE]
> > 184                - Procinfo::old_cpu_time[Procinfo::CPU_NICE];
> > 185     int system = Procinfo::cpu_time[Procinfo::CPU_SYSTEM]
> > 186                  - Procinfo::old_cpu_time[Procinfo::CPU_SYSTEM];
> > 187     int idle = Procinfo::cpu_time[Procinfo::CPU_IDLE]
> > 188                - Procinfo::old_cpu_time[Procinfo::CPU_IDLE];
> >
> > Then it does a couple calculations:
> >
> > 196         float tot = (float)(user + nice + system + idle) / 100;
> > 197         s.sprintf("cpu %.1f%% user, %.1f%% nice\n%.1f%% system,
> > %.1f%% idle",
> > 198                   user / tot, nice / tot, system / tot, idle / tot);
> >
> > That should do it.
> >
> 
>         Not to seem ungrateful, but that is great for understanding
>         top's development, but it doesnt look as though it can be
>         used within a shell script, unless of course, I am missing
>         it in my rudimentary ability to script :)

Well, you can either do a series of expr's to do the math (math just
isn't easy with shell scripts), or use another easier language for this
sort of stuff, like PHP, Perl, or Python (it would seem to make a good
scripting language, it needs to start with a P).

Or you could, for instance, just put this calculation into a separate
executable, then call it from your script if you don't want to convert
your entire script to that language.

--
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.