RE: [opensuse] Amount of physical memory
Is there a way to obtain the amount of physical memory installed in a system from within SuSE 10 console? This is for a script.
$ cat /proc/meminfo MemTotal: 526525152 kB [...] $
Or to be more specific: cat /proc/meminfo | grep MemTotal ~Daniel
On Tuesday 25 October 2005 17:59, Daniel Hatfield wrote:
Is there a way to obtain the amount of physical memory installed in a system from within SuSE 10 console? This is for a script.
$ cat /proc/meminfo MemTotal: 526525152 kB [...] $
Or to be more specific: cat /proc/meminfo | grep MemTotal
Or to be even more specific cat /proc/meminfo | grep MemTotal|awk '{print $2}'
Anders, On Tuesday 25 October 2005 09:09, Anders Johansson wrote:
On Tuesday 25 October 2005 17:59, Daniel Hatfield wrote:
Is there a way to obtain the amount of physical memory installed in a system from within SuSE 10 console? This is for a script.
$ cat /proc/meminfo MemTotal: 526525152 kB [...] $
Or to be more specific: cat /proc/meminfo | grep MemTotal
Or to be even more specific
cat /proc/meminfo | grep MemTotal|awk '{print $2}'
Or, to be more parsimonious: % grep -h MemTotal /proc/meminfo |awk '{print $2}' If I knew anything at all about awk, I'd know whether it could handle the selection (grep) part, too, but I don't. Randall Schulz
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Randall R Schulz wrote:
On Tuesday 25 October 2005 17:59, Daniel Hatfield wrote:
Is there a way to obtain the amount of physical memory installed in a system from within SuSE 10 console? This is for a script. $ cat /proc/meminfo MemTotal: 526525152 kB [...] $ Or to be more specific: cat /proc/meminfo | grep MemTotal Or to be even more specific cat /proc/meminfo | grep MemTotal|awk '{print $2}' Or, to be more parsimonious: % grep -h MemTotal /proc/meminfo |awk '{print $2}' If I knew anything at all about awk, I'd know whether it could handle
On Tuesday 25 October 2005 09:09, Anders Johansson wrote: the selection (grep) part, too, but I don't.
Just for the record:
awk '/^MemTotal:/{print $2}' /proc/meminfo
cheers
- --
-o) Pascal Bleser http://linux01.gwdg.de/~pbleser/
/\\
hI, On Tue, 25 Oct 2005, Pascal Bleser wrote:
Randall R Schulz wrote:
On Tuesday 25 October 2005 09:09, Anders Johansson wrote:
On Tuesday 25 October 2005 17:59, Daniel Hatfield wrote:
Is there a way to obtain the amount of physical memory installed in a system from within SuSE 10 console? This is for a script. $ cat /proc/meminfo MemTotal: 526525152 kB [...] $ Or to be more specific: cat /proc/meminfo | grep MemTotal Or to be even more specific cat /proc/meminfo | grep MemTotal|awk '{print $2}' Or, to be more parsimonious: % grep -h MemTotal /proc/meminfo |awk '{print $2}' If I knew anything at all about awk, I'd know whether it could handle the selection (grep) part, too, but I don't.
Just for the record: awk '/^MemTotal:/{print $2}' /proc/meminfo
Topped: (read a b c; echo $b )
On Tue, Oct 25, 2005 at 10:13:09PM +0200, Eberhard Moenkeberg wrote:
On Tue, 25 Oct 2005, Pascal Bleser wrote:
Just for the record: awk '/^MemTotal:/{print $2}' /proc/meminfo
Topped: (read a b c; echo $b )
Why doing a fork? You could do it without a fork as well: $ read a b c
Hi, On Tue, 25 Oct 2005, Robert Schiele wrote:
On Tue, Oct 25, 2005 at 10:13:09PM +0200, Eberhard Moenkeberg wrote:
On Tue, 25 Oct 2005, Pascal Bleser wrote:
Just for the record: awk '/^MemTotal:/{print $2}' /proc/meminfo
Topped: (read a b c; echo $b )
Why doing a fork? You could do it without a fork as well:
$ read a b c
Right. Topped.
But there is a big problem with that solution anyway: It assumes that MemTotal is the first line in /proc/meminfo. If one decides to reorder this table in the kernel or add some headline all your scripts using this solution will break.
Surely. It was just a sports exercise. If I would need it, I would do grep ^MemTotal /proc/meminfo | (read a b c; echo $b ) and here bash needs the "(...)" to force the subprocess forking at the right point... By this long long traded experience of necessity, I did not see your solution. BTW: Christoph just told me that he is really upset about the ignorance of all the readers here. He had done all his best to cat a good MemTotal value from a real system, but noone did realize it... Cheers -e -- Eberhard Moenkeberg (emoenke@gwdg.de, em@kki.org)
Hello, Am Dienstag, 25. Oktober 2005 23:50 schrieb Eberhard Moenkeberg:
On Tue, 25 Oct 2005, Robert Schiele wrote:
On Tue, Oct 25, 2005 at 10:13:09PM +0200, Eberhard Moenkeberg wrote:
On Tue, 25 Oct 2005, Pascal Bleser wrote: [...] Right. Topped.
But there is a big problem with that solution anyway: It assumes that MemTotal is the first line in /proc/meminfo. If one decides to reorder this table in the kernel or add some headline all your scripts using this solution will break.
Surely. It was just a sports exercise.
If I would need it, I would do
grep ^MemTotal /proc/meminfo | (read a b c; echo $b )
and here bash needs the "(...)" to force the subprocess forking at the right point...
No, it does *not* need a subprocess. You just need to expand the pipe ;-) grep ^MemTotal /proc/meminfo | { read a b c; echo $b ; } Topped again :-) If you (or other readers) want an explanation about expanding the subshell or even need to "export" variables from subshells, have a look at my homepage [1]: http://www.cboltz.de/de/linux/bash/?os (german) http://www.cboltz.de/en/linux/bash/?os (english) Oh, there's another way ;-) set -- `grep ^MemTotal /proc/meminfo` ; echo $2 This time, I topped myself ;-) Anybody out there who wants to top one of my solutions? *eg*
BTW: Christoph just told me that he is really upset about the ignorance of all the readers here. He had done all his best to cat a good MemTotal value from a real system, but noone did realize it...
Now as you mention it - "MemTotal: 526525152 kB" (500 GB) is something I'd like to have ;-) (even all machines I have here together don't have that much _hard disk_ space...) Regards, Christian Boltz [1] new design still pending because of a problem with IE :-( -- [Debian] für meinen privaten Rechner ist es mir zu konservativ. Da bastel ich gerne mal und wälze mich wollüstig in Featureitis und Versionismus und bin erst glücklich, wenn das System ernst- lich Schaden genommen hat. [Ratti in suse-linux]
Hi, On Wed, 26 Oct 2005, Christian Boltz wrote:
Am Dienstag, 25. Oktober 2005 23:50 schrieb Eberhard Moenkeberg:
On Tue, 25 Oct 2005, Robert Schiele wrote:
On Tue, Oct 25, 2005 at 10:13:09PM +0200, Eberhard Moenkeberg wrote:
On Tue, 25 Oct 2005, Pascal Bleser wrote:
[...]
Right. Topped.
But there is a big problem with that solution anyway: It assumes that MemTotal is the first line in /proc/meminfo. If one decides to reorder this table in the kernel or add some headline all your scripts using this solution will break.
Surely. It was just a sports exercise.
If I would need it, I would do
grep ^MemTotal /proc/meminfo | (read a b c; echo $b )
and here bash needs the "(...)" to force the subprocess forking at the right point...
No, it does *not* need a subprocess. You just need to expand the pipe ;-)
grep ^MemTotal /proc/meminfo | { read a b c; echo $b ; }
Topped again :-)
Not really; the top solution does not call ANY external program.
If you (or other readers) want an explanation about expanding the subshell or even need to "export" variables from subshells, have a look at my homepage [1]: http://www.cboltz.de/de/linux/bash/?os (german) http://www.cboltz.de/en/linux/bash/?os (english)
Thanks; but just bookmarked now - too late tonight.
Oh, there's another way ;-) set -- `grep ^MemTotal /proc/meminfo` ; echo $2
This time, I topped myself ;-)
Just using bash intrinsics is the skill.
Anybody out there who wants to top one of my solutions? *eg*
BTW: Christoph just told me that he is really upset about the ignorance of all the readers here. He had done all his best to cat a good MemTotal value from a real system, but noone did realize it...
Now as you mention it - "MemTotal: 526525152 kB" (500 GB) is something I'd like to have ;-) (even all machines I have here together don't have that much _hard disk_ space...)
You know, a man's ram size is directly proportional to the size of his ... Or was that reverse proportional? Cheers -e -- Eberhard Moenkeberg (emoenke@gwdg.de, em@kki.org)
Christian, On Tuesday 25 October 2005 16:31, Christian Boltz wrote:
...
Anybody out there who wants to top one of my solutions? *eg*
Well, here's a BASH-resident (no subprocesses forked) solution: physmem() { while read fieldName value units; do if [ "$fieldName" = "MemTotal:" ]; then echo "$value" fi done \
...
Christian Boltz
Randall Schulz
On Wed, Oct 26, 2005 at 01:31:38AM +0200, Christian Boltz wrote:
Am Dienstag, 25. Oktober 2005 23:50 schrieb Eberhard Moenkeberg:
If I would need it, I would do
grep ^MemTotal /proc/meminfo | (read a b c; echo $b )
and here bash needs the "(...)" to force the subprocess forking at the right point...
No, it does *not* need a subprocess. You just need to expand the pipe ;-)
grep ^MemTotal /proc/meminfo | { read a b c; echo $b ; }
Topped again :-)
No. In this case the implementation requires forking bash like in the example above to handle the fifo queue thus there is actually no difference here. Robert -- Robert Schiele Tel.: +49-621-181-2214 Dipl.-Wirtsch.informatiker mailto:rschiele@uni-mannheim.de
On Tue, Oct 25, 2005 at 11:50:52PM +0200, Eberhard Moenkeberg wrote:
If I would need it, I would do
grep ^MemTotal /proc/meminfo | (read a b c; echo $b )
and here bash needs the "(...)" to force the subprocess forking at the right point...
And now what is the advantage of this solution to the awk script from Pascal? Robert -- Robert Schiele Tel.: +49-621-181-2214 Dipl.-Wirtsch.informatiker mailto:rschiele@uni-mannheim.de
Robert, On Tuesday 25 October 2005 21:22, Robert Schiele wrote:
On Tue, Oct 25, 2005 at 11:50:52PM +0200, Eberhard Moenkeberg wrote:
If I would need it, I would do
grep ^MemTotal /proc/meminfo | (read a b c; echo $b )
and here bash needs the "(...)" to force the subprocess forking at the right point...
And now what is the advantage of this solution to the awk script from Pascal?
You do realize this is just a puzzle / contest / obfuscated programming / mine's-(smaller|faster|cleverer|cooler)-than-yours kind of thing, right?
Robert
RRS
On Tue, Oct 25, 2005 at 11:13:25PM -0700, Randall R Schulz wrote:
You do realize this is just a puzzle / contest / obfuscated programming / mine's-(smaller|faster|cleverer|cooler)-than-yours kind of thing, right?
Sure, and I act as referee to smash down the solutions that did not win the contest. Robert -- Robert Schiele Tel.: +49-621-181-2214 Dipl.-Wirtsch.informatiker mailto:rschiele@uni-mannheim.de
Hi, On Wed, 26 Oct 2005, Robert Schiele wrote:
On Tue, Oct 25, 2005 at 11:50:52PM +0200, Eberhard Moenkeberg wrote:
If I would need it, I would do
grep ^MemTotal /proc/meminfo | (read a b c; echo $b )
and here bash needs the "(...)" to force the subprocess forking at the right point...
And now what is the advantage of this solution to the awk script from Pascal?
This is not what was set against Pascal's solution. Cheers -e -- Eberhard Moenkeberg (emoenke@gwdg.de, em@kki.org)
participants (7)
-
Anders Johansson
-
Christian Boltz
-
Daniel Hatfield
-
Eberhard Moenkeberg
-
Pascal Bleser
-
Randall R Schulz
-
Robert Schiele