[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cronjobs and top not getting along
charles@lunarmedia.net wrote:
>
> >
> > That error is because top can't figure out what sort of terminal the
> > cron session is in, because it isn't in one. So top gets confused
> > trying to figure out how to clear the screen and stuff. The proper
> > approach would be to look at top's sources and figure out how it
> > computes the numbers. It's somewhere in the /proc files, I'm just not
> > sure which one(s).
> >
>
> yeah, i have waded through /proc looking for where top
> gets the actual percentage number and it just isnt there.
> i am suspecting that top takes another number from within
> /proc file and generates an actual xx% value.
> anyone else have ideas on how to get a % value out of a
> /proc file? I know there must be some way since there are
> all those grovvy little applets for WM that do essentially
> what I want but from a gui
Well, looking through the sources for kpm, it takes two readings from
/proc/stat (the first line is CPU numbers for user/nice/system/idle in
that order). The it subtracts the two values like so:
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.
--
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.