Differenze tra le versioni di "Ottenere informazioni sulle statistiche di sistema globali con la funzione esterna sysinfo()"

Da Gambas-it.org - Wikipedia.
 
(2 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
La funzione esterna ''sysinfo()'', contenuta nella libreria ''/usr/include/x86_64-linux-gnu/sys/sysinfo.h'', consente di conoscere alcune informazioni sulle statistiche di sistema come ricavabili dalla Struttura ''sysinfo'', contenuta nella libreria ''/usr/include/linux/sysinfo.h'' .
+
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:
 
Mostriamo un semplice esempio pratico:
Riga 26: Riga 25:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
   
 
   
 
   Dim si As New Sysinfo
 
   Dim si As New Sysinfo
 
   Dim err As Integer
 
   Dim err As Integer
 
   Dim MB As Float = 1024 * 1024
 
   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
 
    
 
    
  err = sysinfo(si)
+
  End
  If err < 0 Then Error.Raise("Il puntatore alla Struttura 'sysinfo' non è valido !")
 
 
 
  With si
 
    Print "Tempo dall'avvio:        ", Date(0, 0, 0, 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'''
 
 
 
  
  

Versione attuale delle 15:30, 8 giu 2023

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