Ottenere informazioni sulle statistiche di sistema globali con la funzione esterna sysinfo()

Da Gambas-it.org - Wikipedia.

La funzione esterna "sysinfo()", dichiarata nel file header /usr/include/x86_64-linux-gnu/sys/sysinfo.h e contenuta nella libreria condivisa libc.so.6, consente di conoscere alcune informazioni sulle statistiche di sistema come ricavabili dalla Struttura sysinfo, contenuta nella libreria /usr/include/linux/sysinfo.h .

Mostriamo un semplice esempio pratico:

Library "libc:6"

Public Struct sysinfo
  uptime As Long
  loads[3] As Long
  totalram As Long
  freeram As Long
  sharedram As Long
  bufferram As Long
  totalswap As Long
  freeswap As Long
  procs As Short
  pad As Short
  totalhigh As Long
  freehigh As Long
  mem_unit As Integer
End Struct

' int sysinfo (struct sysinfo *__info)
' Returns information on overall system statistics.
Private Extern sysinfo(info As Sysinfo) As Integer


Public Sub Main()

 Dim si As New Sysinfo
 Dim err As Integer
 Dim MB As Float = 1024 * 1024

 err = sysinfo(si)
 If err < 0 Then Error.Raise("Il puntatore alla Struttura 'sysinfo' non è valido !")
 
 With si
   Print "Tempo dall'avvio:         "; Time(0, 0, 0, CInt(.uptime * 1000))
   Print "Numero dei processi:      "; .procs
   Print "RAM totale:               "; Format(.totalram / MB, "0.0")
   Print "RAM libera:               "; Format(.freeram / MB, "0.0")
   Print "Shared memory:            "; Format(.sharedram / MB, "0.0")
   Print "Buffers RAM:              "; Format(.bufferram / MB, "0.0")
   Print "Buffers RAM:              "; Format(.bufferram / MB, "0.0")
   Print "Swap totale:              "; Format(.totalswap / MB, "0.0")
   Print "Swap disponibile:         "; Format(.freeswap / MB, "0.0")
   Print "Totale memoria alta:      "; Format(.totalhigh / MB, "0.0")
   Print "Memoria alta disponibile: "; Format(.freehigh / MB, "0.0")
 End With
 
End


Riferimenti