Re: portable way to get system load average
by bluescreen (Friar) on Jun 25, 2010 at 15:54 UTC
|
I don't think Perl's core has something like that, but you can use Unix::Uptime which is multi-platform, but gotcha is that you have to recompile in each platform ( maybe this is what you trying to avoid, but unfortunately Perl doesn't ship that in its core )
| [reply] |
|
|
Unix::Uptime is not multi-platform. For example on Solaris you get this on installation:
OS unsupported
BEGIN failed--compilation aborted at Build.PL line 1.
| [reply] [d/l] |
|
|
| [reply] |
Re: portable way to get system load average
by sierpinski (Chaplain) on Jun 25, 2010 at 15:46 UTC
|
Just curious, why no pipes to uptime? You can capture the output from uptime, or the 'w |head -1' command to get the load average very quickly, and seemingly reliably on unix systems (which I assume you are on due to the reference to /proc)
If you have those limitations, what else can you use or not use? | [reply] |
|
|
considering that there is a simple libc call getloadavg(), i find opening a pipe, running an external command (that doesn't even have to be there, or not in $PATH, or maybe i wont have shell access, or 10 other reasons why it could fail) and processing it's output simply too expensive for such a simple task.
every other script langauge has a call for this.. perl being the system tool it is, how is this even possible? i am disappointed there is no pure perl solution in the core :/
| [reply] [d/l] |
|
|
i am disappointed there is no pure perl solution in the core :/
The reason is quite simple.
If there was any demand for it, it would either be in core, or someone would have made it available as a module amongst the 18000? modules on CPAN. But there is no demand, so it isn't. Indeed, the fact that it isn't there shows there is no demand for it.
So what use would you make of it, were it available?
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
|
|
|
|
|
|
|
|
|
|
|
|
|
every other script langauge has a call for this.. perl being the system tool it is, how is this even possible? i am disappointed there is no pure perl solution in the core :/
I didn't say there wasn't one (I don't have the information to accurately answer that question), but I was merely asking why you have such a restriction. If there is some technical reason, perhaps it can be mitigated another way.
If you don't have a shell, how is your program running? If you don't know what commands are available on the host, how can you assume that any program/shell/script/whatever is available? There is no cure-all for every environment or platform.
One thing that perl does that I think is a great thing, is that it doesn't re-invent the wheel all of the time. If there is a command that exists on all version of a particular platform (like ls, cp, etc), it doesn't try to create it's own version. You have to make some assumptions to expect any script to work on any particular system. (is perl installed, is it the correct version, do I have access to /bin, is my script executable, or whatever) You can check for these assumptions, but if you want a script to execute on _any_ environment regardless of what you have access to, what exists on the box, or anything, then I'd imagine it would be rather difficult and/or tedious.
| [reply] |
|
|
|
|
| [reply] |
|
|