[Solved] Adding a column.

Hi,

Please see the output below.

CPU TTY     PID USERNAME PRI NI   SIZE    RES STATE    TIME %WCPU  %CPU COMMAND
 0   ?       92 root     152 20   144K   128K run    667:31  1.85  1.85 fcachedaemon
22   ?    10957 patrol   154 30 68036K 35704K sleep  571:43  1.53  1.53 PatrolAgent
 0 pts/5  18237 bea      152 20  2500M  1822M run      3:49  1.20  1.20 java

I wish to get the sum of SIZE after trimming the 'K' letter at the end.

See the input you have provided. It has size in MB and KB also...

So it's better to get size in bytes then add and convert to readable format....

Its an output of the top command. How can I get it in bytes format ?

Assuming the SIZE (haven't used top command) shows values in K,M & G, this should work:

top|awk 'BEGIN {kmult=1024;mmult=kmult*1024;gmult=mmult*1024}
NR>1{
if($7~/K$/){totsiz+=($7+0)*kmult;next}
if($7~/M$/){totsiz+=($7+0)*mmult;next}
if($7~/G$/){totsiz+=($7+0)*gmult;next}
totsiz+=($7+0)}
END{print "Total Size : " totsiz/mmult " MB"}'

Assuming you have size upto only MB's..

Output will be printed in KB's.:slight_smile:

top |  awk '{ if ($7 ~ /K/) { {sum+=($7*1024)}}else{if ($7 ~ /M/){ {sum+=($7*1024*1024)}} else { sum+=$7}}}END { print (sum/1024) "K"}' file

just came to know the power awk...:slight_smile:

I am getting the below error executing your command.

==> ./toptest.sh
awk: Input line
System: hh cannot be longer than 3,000 bytes.
                                              The source line number is 1.
                                                                          hht011f2:/home/users/bea>

---------- Post updated at 03:31 AM ---------- Previous update was at 03:28 AM ----------

I got this output

6.22216e+07K

Now how to I convert this in MBs and GBs ?

Just replace the last part in the script mentioned in RED.

top |  awk '{ if ($7 ~ /K/) { {sum+=($7*1024)}}else{if ($7 ~ /M/){ {sum+=($7*1024*1024)}} else { sum+=$7}}}END { print (sum/1024) "K"}' file

#For MB's
{ print (sum/(1024*1024)) "MB"}

#For GB's
{ print (sum/(1024*1024*1024)) "GB"}
1 Like

I don't think that HP-UX top is suitable for further processing because the output is formatted with VDU control sequences and only the first page of process list is output.

What figure are you trying to calculate? The sum of the running sizes of processes really has no meaning on a paged Operating System.

Footnote: The output from the Berkeley format ps command is easier to deal with in scripts:
For example: Size of each process in 1024 byte units:

# The space character after UNIX95= is mandatory
UNIX95= ps -e -o vsz | grep -v "VSZ"
2 Likes

Is this output correct ?

top |  awk '{ if ($7 ~ /K/) { {sum+=($7*1024)}}else{if ($7 ~ /M/){ {sum+=($7*1024*1024)}} else { sum+=$7}}}END { print (sum/(1024*1024*1024)) "GB"}' top.out
59.3392GB

If yes, that means I have close to 60 GB of heap under use. Does that mean I better have 60 GB of swap memory for us not to fall short in the future ?

Correct me and suggest if you disagree.

---------- Post updated at 03:17 AM ---------- Previous update was at 03:16 AM ----------

As I said, I have a few java processess running. Off-late I increased the number of java processes. This lead to 99 % swap memory consumption. Now, I need to suggest what is the amount of swap that needs to be increased inorder to suffice the current running java processes.

methyl did you ask me to run ??

==>  ps -e -o vsz | grep -v "VSZ"
ps: illegal option -- o
usage: ps [-edaxzflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup] [-Z psetidlist]

You did not respect the correct syntax: UNIX95= ps -e.....

so type exactely what was given by methyl:

UNIX95= ps -e -o vsz | grep -v "VSZ"

If you were to summ all the processes memory usage, then I certainly would not have used top... and if that were what you are trying, I am sure I already gave the solution here using XPG4 syntax ( the one methyl is trying to get you use...) did you search before asking?

I am sorry for the miss. Find my output below.

==> UNIX95= ps -e -o vsz | grep -v "VSZ" | awk '{ sum += $0 } END { print sum }'
6.52404e+07

If the output is in bytes I used google to convert bytes to MBs and it says

62.218093872 MBs

This does not look feasible. The heap used by the scripts that I am currently running has to be any amount greater than 2 GB. Am I missing something ?

This is contrary to the command provided by "pamu" which showed around 59 GB of heap consumption on the system.

Also, if I wanted to ask if I have a script that starts the JVM with initial heap -xms 256MB and Maximum Heap -xmx 512MB and the current heap utilisation is 300MB what will this command count for this process 256, 300 or 512 MB ?

6.52404e+07 is around 64 GB... what are you calculating?

Could you give us your output of the following command:

swapinfo -tam

I understood that this output

6.52404e+07

is in bytes and hence I tried to use google converter to convert it in Mbs so the google coverter showed

62.218093872 MBs

May I know how were you able to convert

6.52404e+07 

to around

64 GB

?

Here is the output

==> swapinfo -tam
             Mb         Mb         Mb   PCT    START/       Mb
TYPE      AVAIL    USED     FREE  USED   LIMIT   RESERVE  PRI  NAME
dev        8000      0      7992    0%     0        -     1    /dev/vg00/swap
reserve     -       7992   -7992
memory    61678    51592   10086   84%
total     69678    59584   10086   86%     -       0       -

OK...
Are you on a SAN?
I guess you have memory issues though you have pleanty of...
Since changing your original swap space may be very tricky... for perfomance reason, I suggest you create new swap spaces NOT in vg00: 2 will help a lot, 4 would be perfect, for that, they must be the same size as the one in vg00 so if you have the 4 new swaps preferably in different groups of disks ( load balancing) you would have 40 GB device swap instead of 8... HPUX is a virtual memory system... It reseves in swap the space needed for each process it is going to run, So once it filled you 8GB, if you look at your kernel parameters, I am sur you have swap_mem set to 1, this allows the system to extend the swap area in memory... Doing that you find yourself not being able to load new applications or processes by getting the system replying "Not enough memory" though you have plenty... In ither words if you intent to use all your memory for processes, then you need at least the same amount of device swap..., in your case it would be silly though... So start with what I suggested above and you will see your life change...

1 Like

Thank you for all your inputs.

How can I check if I am on SAN ? I am new to unix.

ant:/home/vbe $ ioscan -funC fc
Class     I  H/W Path  Driver S/W State   H/W Type     Description
=================================================================
fc        0  0/4/0/0   td   CLAIMED     INTERFACE    HP Tachyon XL2 Fibre Channel Mass Storage Adapter
                      /dev/td0
fc        1  0/7/0/0   td   CLAIMED     INTERFACE    HP Tachyon XL2 Fibre Channel Mass Storage Adapter
                      /dev/td1

fc stands for Fiber Channel (HBA...)

Does the below mean that i am on SAN ?

What is the significance of this and how does it matter / behave differently regarding the swap issue.

==> ioscan -funC fc
Class     I  H/W Path       Driver S/W State   H/W Type     Description
=====================================================================
fc        0  9/0/2/1/0/4/0  fcd   CLAIMED     INTERFACE    HP AD194-60001      PCI/PCI-X Fibre Channel 2-port 4Gb FC/2-port 1000B-T Combo Adapter (FC Port 1)
                           /dev/fcd0
fc        1  9/0/2/1/0/4/1  fcd   CLAIMED     INTERFACE    HP AD194-60001      PCI/PCI-X Fibre Channel 2-port 4Gb FC/2-port 1000B-T Combo Adapter (FC Port 2)
                           /dev/fcd1
fc        2  9/0/4/1/0/4/0  fcd   CLAIMED     INTERFACE    HP AD194-60001      PCI/PCI-X Fibre Channel 2-port 4Gb FC/2-port 1000B-T Combo Adapter (FC Port 1)
                           /dev/fcd2
fc        3  9/0/4/1/0/4/1  fcd   CLAIMED     INTERFACE    HP AD194-60001      PCI/PCI-X Fibre Channel 2-port 4Gb FC/2-port 1000B-T Combo Adapter (FC Port 2)
                           /dev/fcd3

You have 2 double port FC cards in your box...
Look at the speed... and there is chances your disk bay has a great cache...

How many VG do you have?

Hi,

Whats VG ? and how can I check that ?