summaryrefslogtreecommitdiff
path: root/doc/reference.texi
blob: 559700018033e3782e3439cfdde1852cbdc4aaa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
@node Reference Manual, , White Paper, Top
@chapter LibGTop Reference Manual

@menu
* System Dependent::            System Dependent Functions.
* Common Functions::            Common Functions.
* Library Functions::           Library Functions.
@end menu

@node System Dependent, Common Functions, Reference Manual, Reference Manual
@section System Dependent Functions

@menu
* glibtop_cpu::                 CPU Usage.
* glibtop_mem::                 Memory Usage.
* glibtop_swap::                Swap Usage.
* glibtop_uptime::              System Uptime.
* glibtop_loadavg::             Load Average.
* glibtop_proclist::            Process List.
* glibtop_proc_state::          Process State.
* glibtop_proc_uid::            Process UID and TTY Information.
* glibtop_proc_mem::            Process Memory Information.
* glibtop_proc_time::           Process Time Information.
* glibtop_proc_signal::         Process Signal Information.
* glibtop_proc_kernel::         Process Kernel Data Information.
* glibtop_proc_segment::        Process Segment Information.
* glibtop_proc_args::           Process Arguments.
* glibtop_proc_map::            Process Memory Maps.
* glibtop_netload::             Network Load.
* glibtop_ppp::                 PPP Usage.
* glibtop_disk::                DISK Usage.
@end menu

@node glibtop_cpu, glibtop_mem, System Dependent, System Dependent
@subsection CPU Usage

Library function @code{glibtop_get_cpu}:

@example
@cartouche
void glibtop_get_cpu (glibtop_cpu *buf);
void glibtop_get_cpu_l (glibtop *server, glibtop_cpu *buf);
@end cartouche
@end example

Declaration of @code{glibtop_cpu} in @file{<glibtop/cpu.h>}:

@example
@cartouche
typedef struct _glibtop_cpu     glibtop_cpu;

struct _glibtop_cpu
@{
    guint64   flags,
        total,
        user,
        nice,
        sys,
        idle,
        iowait,
        irq,
        softirq,
        frequency,
        xcpu_total [GLIBTOP_NCPU],
        xcpu_user [GLIBTOP_NCPU],
        xcpu_nice [GLIBTOP_NCPU],
        xcpu_sys  [GLIBTOP_NCPU],
        xcpu_idle [GLIBTOP_NCPU],
        xcpu_iowait [GLIBTOP_NCPU],
        xcpu_irq [GLIBTOP_NCPU],
        xcpu_softirq [GLIBTOP_NCPU],
        xcpu_flags;
@};
@end cartouche
@end example

All CPU units are measured in @dfn{jiffies} which are normally 1/100th of a
second (in which case @code{frequency} equals 100), but can also be in any
other unit. To get seconds, divide them by @code{frequency}.

@table @code
@item total
Number of clock ticks since system boot.

@item user
Number of clock ticks the system spent in user mode.

@item nice
Number of clock ticks the system spent in user mode (nice).

@item sys
Number of clock ticks the system spent in system mode.

@item idle
Number of clock ticks the system spent in the idle task.

@item iowait
Number of clock ticks the system spent waiting for I/O to complete.

@item irq
Number of clock ticks the system spent servicing interrupts.

@item softirq
Number of clock ticks the system spent servicing softirqs.

@item frequency
Tick frequency (default is 100).

@end table

The @samp{xcpu_} values are for SMP systems - they are the same than
@code{total}, @code{user}, @code{nice}, @code{sys}, @code{idle},
@code{iowait}, @code{irq} and @code{softirq}
except that they are arrays of @code{GLIBTOP_NCPU} (defined in
@file{<glibtop/cpu.h>}) elements and contain one value for each CPU
in the system.

@table @code
@item xcpu_flags
This is interpreted as a bit-field: on systems like Solaris, not all CPUs
need to be running all the time, so we set the corresponding bit for each
CPU that is currently running.
@end table

Please note that all of the cpu values are absolute values measured in
certain units (to get seconds, divide them by @code{frequency}) since system
boot. To get percentual values, you need to call @code{glibtop_cpu}, save the
result, wait some time and then call it again and divide the differences of
the two values by the time you have waited.

@page
@node glibtop_mem, glibtop_swap, glibtop_cpu, System Dependent
@subsection Memory Usage

Library function @code{glibtop_get_mem}:

@example
@cartouche
void glibtop_get_mem (glibtop_mem *buf);
void glibtop_get_mem_l (glibtop *server, glibtop_mem *buf);
@end cartouche
@end example

Declaration of @code{glibtop_mem} in @file{<glibtop/mem.h>}:

@example
@cartouche
typedef struct _glibtop_mem     glibtop_mem;

struct _glibtop_mem
@{
    guint64   flags,
        total,
        used,
        free,
        shared,
        buffer,
        cached,
        user,
        locked;
@};
@end cartouche
@end example

Unless explicitly stated otherwise, all memory units are in bytes.

@table @code
@item total
Total physical memory.

@item used
Used memory size.

@item free
Free memory size.

@item shared
Shared memory size.

This are both segments that are @code{mmap()}ed with @code{MAP_SHARED} and
IPC Shared Memory segments.

@item buffer
Size of buffers.

@item cached
Size of cached memory.

@item user
Memory used from user processes.

This is normally @code{total - free - shared - buffer - cached}.

@item locked
Memory in locked segments.

@end table

@page
@node glibtop_swap, glibtop_uptime, glibtop_mem, System Dependent
@subsection Swap Usage

Library function @code{glibtop_get_swap}:

@example
@cartouche
void glibtop_get_swap (glibtop_swap *buf);
void glibtop_get_swap_l (glibtop *server, glibtop_swap *buf);
@end cartouche
@end example

Declaration of @code{glibtop_swap} in @file{<glibtop/swap.h>}:

@example
@cartouche
typedef struct _glibtop_swap    glibtop_swap;

struct _glibtop_swap
@{
    guint64   flags,
        total,
        used,
        free,
        pagein,
        pageout;
@};
@end cartouche
@end example

The following units are in bytes.

@table @code
@item total
Total swap space in the system.

@item used
Used swap space.

@item free
Free swap space.
@end table

You can use @code{pagein} and @code{pageout} to get some measure about how
much the system is swapping at the moment. They're increased each time a page
is swapped in or out, so you need to save this values, wait a little bit, get
them again and then compare the two results to find out how much the system
swapped in the meantime.

@table @code
@item pagein
Total number of swap pages that have been brought in since system boot

@item pageout
Total number of swap pages that have been brought out since system boot

@end table

@page
@node glibtop_uptime, glibtop_loadavg, glibtop_swap, System Dependent
@subsection Uptime

Library function @code{glibtop_get_uptime}:

@example
@cartouche
void glibtop_get_uptime (glibtop_uptime *buf);
void glibtop_get_uptime_l (glibtop *server, glibtop_uptime *buf);
@end cartouche
@end example

Declaration of @code{glibtop_uptime} in @file{<glibtop/uptime.h>}:

@example
@cartouche
typedef struct _glibtop_uptime  glibtop_uptime;

struct _glibtop_uptime
@{
    guint64 flags;
    double uptime,
        idletime;
    guint64 boot_time;
@};
@end cartouche
@end example

When porting LibGTop to a new system, you only need to implement @code{uptime}
and @code{idletime} if there's a faster or better way to obtain them as using
@code{glibtop_cpu} for it. Look at @file{sysdeps/freebsd/uptime.c} for an
example on how to obtain them using @code{glibtop_cpu}.

@table @code
@item uptime
Time in seconds since system boot.

@item idletime
Time in seconds the system spent in the idle task since system boot.
@end table

The following one was from a request on the @samp{linux-kernel} mailing list;
on a laptop with advanced power management @code{glibtop_cpu.total} may not
reflect the correct boot time of the system if the power was turned off by
means of APM in the meantime.

@table @code
@item boot_time
Time of last system boot in seconds since the epoch.
@end table

@page
@node glibtop_loadavg, glibtop_proclist, glibtop_uptime, System Dependent
@subsection Load Average

Library function @code{glibtop_get_loadavg}:

@example
@cartouche
void glibtop_get_loadavg (glibtop_loadavg *buf);
void glibtop_get_loadavg_l (glibtop *server, glibtop_loadavg *buf);
@end cartouche
@end example

Declaration of @code{glibtop_loadavg} in @file{<glibtop/loadavg.h>}:

@example
@cartouche
typedef struct _glibtop_loadavg glibtop_loadavg;

struct _glibtop_loadavg
@{
    guint64 flags;
    double loadavg [3];
    guint64 nr_running,
        nr_tasks,
        last_pid;
@};
@end cartouche
@end example

@table @code
@item loadavg

Number of jobs running simultaneously averaged over 1, 5 and 15 minutes.

@end table

The following fields are Linux specific and deprecated. You don't need to
implement them when porting LibGTop to a new system as they may be removed
in a future version.

@table @code
@item nr_running
Number of tasks currently running.

@item nr_tasks
Total number of tasks.

@item last_pid
Last PID.
@end table

@page
@node glibtop_proclist, glibtop_proc_state, glibtop_loadavg, System Dependent
@subsection Process List

Library function @code{glibtop_get_proclist}:

@example
@cartouche
unsigned *
glibtop_get_proclist (glibtop_proclist *buf,
                      gint64 which, gint64 arg);

unsigned *
glibtop_get_proclist_l (glibtop *server, glibtop_proclist *buf,
                        gint64 which, gint64 arg);
@end cartouche
@end example

Constants for the @code{which} argument:

@example
@cartouche
#define GLIBTOP_KERN_PROC_ALL           0
#define GLIBTOP_KERN_PROC_PID           1
#define GLIBTOP_KERN_PROC_PGRP          2
#define GLIBTOP_KERN_PROC_SESSION       3
#define GLIBTOP_KERN_PROC_TTY           4
#define GLIBTOP_KERN_PROC_UID           5
#define GLIBTOP_KERN_PROC_RUID          6

#define GLIBTOP_KERN_PROC_MASK          15

#define GLIBTOP_EXCLUDE_IDLE            0x1000
#define GLIBTOP_EXCLUDE_SYSTEM          0x2000
#define GLIBTOP_EXCLUDE_NOTTY           0x4000
@end cartouche
@end example

Declaration of @code{glibtop_proclist} in @file{<glibtop/proclist.h>}:

@example
@cartouche
typedef struct _glibtop_proclist        glibtop_proclist;

struct _glibtop_proclist
@{
    guint64   flags,
        number,
        total,
        size;
@};
@end cartouche
@end example

This function returns a list of all or a selected subset of all running
processes. You can use the @code{which} and @code{arg} arguments to
specify which processes should be returned.

You can use the following values for the @code{which} argument:

@table @code
@item GLIBTOP_KERN_PROC_ALL
Return information about all processes (the @code{arg} argument is ignored).

@item GLIBTOP_KERN_PROC_PID
Return information about all process with the pid @var{PID} which is passed
in @code{arg}. You can use this to find out whether some process still exists.

@item GLIBTOP_KERN_PROC_PGRP
Return all processes in process group @var{PGRP} which is passed in
@code{arg}.

@item GLIBTOP_KERN_PROC_SESSION
Return all processes in session @var{SESSION} which is passed in @code{arg}.

@item GLIBTOP_KERN_PROC_TTY
Return all processes which have the controlling tty @var{TTY} which is passed
in @code{arg} (@var{TTY} is interpreted as device number).

@item GLIBTOP_KERN_PROC_UID
Return all processes with effective uid @var{UID} which is passed in @code{arg}.

@item GLIBTOP_KERN_PROC_RUID
Return all processes with real uid @var{RUID} which is passed in @code{arg}.

@end table

You can alter the list of returned processes by using a binary OR of
@code{which} and the following constants:

@table @code
@item GLIBTOP_EXCLUDE_IDLE
Exclude idle processes.
@item GLIBTOP_EXCLUDE_SYSTEM
Exclude system processes.
@item GLIBTOP_EXCLUDE_NOTTY
Exclude processes without a controlling terminal.
@end table

The return value of @code{glibtop_get_proclist} is either @code{NULL} on
error or a @code{unsigned *} list of pids. Additionally, the following fields
of @code{glibtop_proclist} are set:

@table @code
@item number
Number of entries in the returned list.

@item total
Total size of the returned list (this equals @code{number * size}).

@item size
Size of a single entry in the returned list
(this equals @code{sizeof (unsigned)}).
@end table

The returned list is allocated using @code{g_malloc} and must be freed
using @code{g_free} to avoid a memory leak.

@page
@node glibtop_proc_state, glibtop_proc_uid, glibtop_proclist, System Dependent
@subsection Process State

Library function @code{glibtop_get_proc_state}:

@example
@cartouche
void
glibtop_get_proc_state (glibtop_proc_state *buf, pid_t pid);

void
glibtop_get_proc_state_l (glibtop *server, glibtop_proc_state *buf,
                          pid_t pid);
@end cartouche
@end example

Declaration of @code{glibtop_proc_state} in @file{<glibtop/procstate.h>}:

@example
@cartouche
typedef struct _glibtop_proc_state      glibtop_proc_state;

struct _glibtop_proc_state
@{
    guint64 flags;
    char cmd[40];
@ifset LIBGTOP-1-1
    unsigned state;
@end ifset
@ifclear LIBGTOP-1-1
    char state;
@end ifclear
    int uid,
        gid,
        ruid,
        rgid;
    int has_cpu,
        processor,
        last_processor;

@};
@end cartouche
@end example

@table @code
@item cmd
Basename of the executable file in the call to @code{exec}.
@item state
@ifset LIBGTOP-1-1
Process state (see the constants defined below).
@end ifset
@ifclear LIBGTOP-1-1
Process state ('R' = running, 'S' = sleeping, 'D' = uninterruptible,
'Z' = zombie, 'T' = stopped, 'I' = idle).

This was changed to an @code{unsigned} bitfield in LibGTop 1.1.x where there
are also some constants for it.
@end ifclear
@end table

When porting LibGTop, please @emph{try hard} to implement the following
fields. For security reasons, it is @strong{very important} that you
@strong{only} set the @code{flags} bits for those fields if their
@strong{values are correct}.

@table @code
@item uid
Effective UID of the process.
@item gid
Effective GID of the process.
@item ruid
Real UID of the process.
@item rgid
Read GID of the process.
@end table

The following fields are for SMP systems:

@table @code
@item has_cpu
This is either 0 or 1 depending on whether the process currently has a CPU
or not.

@item processor
This is the processor id of the CPU this process is currently running on
(which can be used as index in the @samp{xcpu_} fields of @code{glibtop_cpu}
for instance; since zero is a valid processor id, you must check @code{has_cpu}
in this case to find out whether the process really has a CPU).

@item last_processor
The is the processor id of the CPU the process was last running on.
@end table

@ifset LIBGTOP-1-1
There are some constants for the @code{state} field:

@example
@cartouche
#define GLIBTOP_PROCESS_RUNNING                 1
#define GLIBTOP_PROCESS_INTERRUPTIBLE           2
#define GLIBTOP_PROCESS_UNINTERRUPTIBLE         4
#define GLIBTOP_PROCESS_ZOMBIE                  8
#define GLIBTOP_PROCESS_STOPPED                 16
#define GLIBTOP_PROCESS_SWAPPING                32
#define GLIBTOP_PROCESS_DEAD                    64
@end cartouche
@end example
@end ifset

@table @code
@item GLIBTOP_PROCESS_RUNNING
The process is currently running.
@item GLIBTOP_PROCESS_INTERRUPTIBLE
The process is currently in an interruptible sleep.
@item GLIBTOP_PROCESS_UNINTERRUPTIBLE
The process is currently in uninterruptible sleep
(the so-called @dfn{disk sleep}).
@item GLIBTOP_PROCESS_ZOMBIE
The process is a zombie.
@item GLIBTOP_PROCESS_STOPPED
The process is currently stopped (received @code{SIGSTOP}
or attached to a debugger).
@item GLIBTOP_PROCESS_SWAPPING
The process is currently swapping.
@end table

@page
@node glibtop_proc_uid, glibtop_proc_mem, glibtop_proc_state, System Dependent
@subsection Process UID and TTY information

Library function @code{glibtop_get_proc_uid}:

@example
@cartouche
void
glibtop_get_proc_uid (glibtop_proc_uid *buf, pid_t pid);

void
glibtop_get_proc_uid_l (glibtop *server, glibtop_proc_uid *buf,
                        pid_t pid);
@end cartouche
@end example

Declaration of @code{glibtop_proc_uid} in @file{<glibtop/procuid.h>}:

@example
@cartouche
typedef struct _glibtop_proc_uid        glibtop_proc_uid;

struct _glibtop_proc_uid
@{
    guint64 flags;
    int uid,
        euid,
        gid,
        egid,
        suid,
        sgid,
        fsuid,
        fsgid,
        pid,
        ppid,
        pgrp,
        session,
        tty,
        tpgid,
        priority,
        nice,
        ngroups,
        groups [GLIBTOP_MAX_GROUPS];
@};
@end cartouche
@end example

@table @code
@item uid
User ID
@item euid
Effective User ID
@item gid
Group ID
@item egid
Effective Group ID
@item pid
Process ID
@item ppid
PID of parent process
@item pgrp
Process group ID
@item session
Session ID
@item tty
Full device number of controlling terminal
@item tpgid
Terminal process group ID
@item priority
Kernel scheduling priority.
@item nice
Standard unix nice level of process.
@item ngroups
Number of additional process groups.
@item groups
Array of additional process groups@*
(@code{GLIBTOP_MAX_GROUPS} is defined in @file{<glibtop/procuid.h>}).
@end table

@page
@node glibtop_proc_mem, glibtop_proc_time, glibtop_proc_uid, System Dependent
@subsection Process Memory information

Library function @code{glibtop_get_proc_mem}:

@example
@cartouche
void
glibtop_get_proc_mem (glibtop_proc_mem *buf, pid_t pid);

void
glibtop_get_proc_mem_l (glibtop *server, glibtop_proc_mem *buf,
                        pid_t pid);
@end cartouche
@end example

Declaration of @code{glibtop_proc_mem} in @file{<glibtop/procmem.h>}:

@example
@cartouche
typedef struct _glibtop_proc_mem        glibtop_proc_mem;

struct _glibtop_proc_mem
@{
    guint64   flags,
        size,
        vsize,
        resident,
        share,
        rss,
        rss_rlim;
@};
@end cartouche
@end example

@table @code
@item size
Total number of pages of memory.
@item vsize
Number of pages of virtual memory.
@item resident
Number of residnet set (non-swapped) pages.
@item share
Number of pages of shared (mmap\'d) memory.
@item rss
Number of pages the process has in real memory, minus 3 for administrative
purposes.

This is just the pages which count towards text, data, or stack space.
This does not include pages which have not been demand-loaded in, or which
are swapped out.
@item rss_rlim
Current limit in bytes on the rss of the process (usually 2,147,483,647).
@end table

The description above is taken from the manual page of the @file{/proc}
filesystem under Linux and is a little bit confusing, so I make this clear
here. 

@strong{A word for people porting LibGTop to other systems:}
Every operating system has its own idea about the memory usage of a process
and also system utilities like @code{ps} show different things on different
systems.

Nevertheless, we should try to make LibGTop as system independent as possible,
so I give you some hints here how @code{glibtop_get_proc_mem} should work. 

@itemize @bullet
@item
When you use @code{mmap} with either @code{MAP_SHARED} or @code{MAP_PRIVATE},
this should only affect the @code{vsize} of the process and none of its
@code{size}, @code{resident}, @code{shared} and @code{rss} sizes.

@item
As soon as you read some of the @code{mmap()}ed pages, they will be demand-
oaded and thus count towards the @code{size} of the process.

Also - we assume there is enough free memory - they are resident in memory
until they get stolen or swapped out and thus increase the @code{resident} and
@code{rss} sizes of the process.

@item
If the process has used @code{MAP_SHARED} and another process attaches the
same file also @code{MAP_SHARED}, some of the pages are shared with this
process and thus increase the @code{shared} sizes of both processes.

@item
If the process has used @code{MAP_PRIVATE} and writes to the @code{mmap()}ed
pages, the only difference to reading from them is that they get dirty and
cannot be stolen any longer but will get swapped out.

@item
When memory gets rare, clean pages are normally stolen, which decreases the
@code{size}, @code{resident}, @code{shared} and @code{rss} sizes of the process.

@item
When dirty pages are swapped out, this will not decrease the @code{size} of the
process but only its @code{resident} and @code{rss} sizes (dirty pages cannot
be shared).

@item
The @code{vsize} of a process can @emph{only} be changed by the process
itself when it requests or frees memory but @emph{never} due to swapping
activity of the system.

@item
If the @code{shared} size changes, this @emph{only} means that the number of
pages that are currently shared with other processes has changed; if this
happens, this will @emph{never} affect any of the other sizes of the process.
@end itemize

The hints above describe how it works under Linux - but we should try to make
@code{glibtop_get_proc_mem} show the same behavior under every other system.

@page
@node glibtop_proc_time, glibtop_proc_signal, glibtop_proc_mem, System Dependent
@subsection Process Time information

Library function @code{glibtop_get_proc_time}:

@example
@cartouche
void
glibtop_get_proc_time (glibtop_proc_time *buf, pid_t pid);

void
glibtop_get_proc_time_l (glibtop *server, glibtop_proc_time *buf,
                         pid_t pid);
@end cartouche
@end example

Declaration of @code{glibtop_proc_time} in @file{<glibtop/proctime.h>}:

@example
@cartouche
typedef struct _glibtop_proc_time       glibtop_proc_time;

struct _glibtop_proc_time
@{
    guint64   flags,
        start_time,
        rtime,
        utime,
        stime,
        cutime,
        cstime,
        timeout,
        it_real_value,
        frequency,
        xcpu_utime [GLIBTOP_NCPU],
        xcpu_stime [GLIBTOP_NCPU],
        xcpu_flags;
@};
@end cartouche
@end example


@table @code
@item start_time
Start time of process in seconds since the epoch
@item rtime
Real time accumulated by process (should be @code{utime} + @code{stime})
@item utime
User-mode CPU time accumulated by process
@item stime
Kernel-mode CPU time accumulated by process
@item cutime
Cumulative utime of process and reaped children
@item cstime
Cumulative stime of process and reaped children
@item timeout
The time (in jiffies) of the process's next timeout
@item it_real_value
The time (in jiffies) before the next SIGALRM is sent to the process due
to an interval timer.
@item frequency
Tick frequency
@item xcpu_utime
SMP user-mode CPU time accumulated by process
@item xcpu_stime
SMP kernel-mode CPU time accumulated by process
@end table


Please note that under Linux, @code{start_time} value may be strange.
Linux kernel defines @code{INITIAL_JIFFIES} which implies a time
shift. Because @code{INITIAL_JIFFIES} is not user-space defined, we
cannot use it to compute accurate @code{start_time}. On Linux2.6,
@code{INITIAL_JIFFIES} is 300 so @code{start_time} is always 3s
different from real start time of the given process. You may also get
shift results if your system clock is not synchronised with your
hardware clock. See @samp{man hwclock}.



@page
@node glibtop_proc_signal, glibtop_proc_kernel, glibtop_proc_time, System Dependent
@subsection Process Signal information

Library function @code{glibtop_get_proc_signal}:

@example
@cartouche
void
glibtop_get_proc_signal (glibtop_proc_signal *buf, pid_t pid);

void
glibtop_get_proc_signal_l (glibtop *server, glibtop_proc_signal *buf,
                           pid_t pid);
@end cartouche
@end example

Declaration of @code{glibtop_proc_signal} in @file{<glibtop/procsignal.h>}:

@example
@cartouche
typedef struct _glibtop_proc_signal     glibtop_proc_signal;

struct _glibtop_proc_signal
@{
    guint64   flags,
        signal [2],
        blocked [2],
        sigignore [2],
        sigcatch [2];
@};
@end cartouche
@end example

@table @code
@item signal
Mask of pending signals
@item blocked
Mask of blocked signals
@item sigignore
Mask of ignored signals
@item sigcatch
Mask of caught signals
@end table

All signal masks are interpreted as bit mask; it is an array of two
@code{guint64}'s so we can save 128 signals there.

@page
@node glibtop_proc_kernel, glibtop_proc_segment, glibtop_proc_signal, System Dependent
@subsection Process Kernel Data information

Library function @code{glibtop_get_proc_kernel}:

@example
@cartouche
void
glibtop_get_proc_kernel (glibtop_proc_kernel *buf, pid_t pid);

void
glibtop_get_proc_kernel_l (glibtop *server, glibtop_proc_kernel *buf,
                           pid_t pid);
@end cartouche
@end example

Declaration of @code{glibtop_proc_kernel} in @file{<glibtop/prockernel.h>}:

@example
@cartouche
typedef struct _glibtop_proc_kernel     glibtop_proc_kernel;

struct _glibtop_proc_kernel
@{
    guint64 flags;
    guint64 k_flags,
        min_flt,
        maj_flt,
        cmin_flt,
        cmaj_flt,
        kstk_esp,
        kstk_eip,
        nwchan;
    char wchan [40];
@};
@end cartouche
@end example

@table @code
@item k_flags
Kernel flags of the process. See the constants defined below.
@item min_flt
The number of minor faults the process has made, those which have not required
loading a memory page from disk.
@item maj_flt
The number of major faults the process has made, those which have required loading
a memory page from disk.
@item cmin_flt
The number of minor faults that the process and its children have made.
@item cmaj_flt
The number of major faults that the process and its children have made.
@item kstk_esp
The current value of @code{esp} (32-bit stack pointer), as found in the kernel stack
page for the process.
@item kstk_eip
The current @code{eip} (32-bit instruction pointer).
@item nwchan
This is the "channel" in which the process is waiting. This is the address of a system
call, and can be looked up in a namelist if you need a textual name.
(If you have an up-to-date @file{/etc/psdatabase}, then try @code{ps -l} to see the
WCHAN field in action).
@item wchan
This is the textual name of the @code{nwchan} field.
@end table

There are some constants for the @code{k_flags} field:

@example
@cartouche
#define GLIBTOP_KFLAGS_STARTING         1
#define GLIBTOP_KFLAGS_EXITING          2
#define GLIBTOP_KFLAGS_PTRACED          4
#define GLIBTOP_KFLAGS_TRACESYS         8
#define GLIBTOP_KFLAGS_FORKNOEXEC       16
#define GLIBTOP_KFLAGS_SUPERPRIV        32
#define GLIBTOP_KFLAGS_DUMPEDCORE       64
#define GLIBTOP_KFLAGS_SIGNALED         128
@end cartouche
@end example

@table @code
@item GLIBTOP_KFLAGS_STARTING
Process is being created.
@item GLIBTOP_KFLAGS_EXITING
Process is exiting.
@item GLIBTOP_KFLAGS_PTRACED
Process is being traced (via @code{ptrace ()}).
@item GLIBTOP_KFLAGS_TRACESYS
Process is tracing system calls.
@item GLIBTOP_KFLAGS_FORKNOEXEC
Process @code{fork()}ed, but didn't @code{exec()} yet.
@item GLIBTOP_KFLAGS_SUPERPRIV
Process used super-user privileges.
@item GLIBTOP_KFLAGS_DUMPEDCORE
Process dumped core.
@item GLIBTOP_KFLAGS_SIGNALED
Process was killed by a signal.
@end table

@page
@node glibtop_proc_segment, glibtop_proc_args, glibtop_proc_kernel, System Dependent
@subsection Process Segment information

Library function @code{glibtop_get_proc_segment}:

@example
@cartouche
void
glibtop_get_proc_segment (glibtop_proc_segment *buf, pid_t pid);

void
glibtop_get_proc_segment_l (glibtop *server, glibtop_proc_segment *buf,
                            pid_t pid);
@end cartouche
@end example

Declaration of @code{glibtop_proc_segment} in @file{<glibtop/procsegment.h>}:

@example
@cartouche
typedef struct _glibtop_proc_segment    glibtop_proc_segment;

struct _glibtop_proc_segment
@{
    guint64   flags,
        text_rss,
        shlib_rss,
        data_rss,
        stack_rss,
        dirty_size,
        start_code,
        end_code,
        start_stack;
@};
@end cartouche
@end example

@table @code
@item text_rss
Text resident set size
@item shlib_rss
Shared-Lib resident set size
@item data_rss
Data resident set size
@item stack_rss
Stack resident set size
@item dirty_size
Total size of dirty pages
@item start_code
Address of beginning of code segment
@item end_code
Address of end of code segment
@item start_stack
Address of the bottom of stack segmen
@end table

@page
@node glibtop_proc_args, glibtop_proc_map, glibtop_proc_segment, System Dependent
@subsection Process Arguments

Library function @code{glibtop_get_proc_args}:

@example
@cartouche
char *
glibtop_get_proc_args(glibtop_proc_args *buf, pid_t pid,
                         unsigned max_len);

char *
glibtop_get_proc_args_l (glibtop *server, glibtop_proc_args *buf,
                         pid_t pid, unsigned max_len);
@end cartouche
@end example

Declaration of @code{glibtop_proc_args} in @file{<glibtop/procargs.h>}:

@example
@cartouche
typedef struct _glibtop_proc_args       glibtop_proc_args;

struct _glibtop_proc_args
@{
    guint64   flags,
        size;
@};
@end cartouche
@end example

Returns a string with all command line arguments of process @code{pid}
(up to @code{max_len} characters, use zero to get all arguments).

The command line arguments in the returned string are separated by zero bytes;
the lenght of this string is returned in the @code{size} field.

Remember to @code{g_free} the returned string to avoid a memory leak.

@strong{New functions}

@example
@cartouche
char **
glibtop_get_proc_argv(glibtop_proc_args *buf, pid_t pid,
                         unsigned max_len);

char **
glibtop_get_proc_argv_l (glibtop *server, glibtop_proc_args *buf,
                         pid_t pid, unsigned max_len);
@end cartouche
@end example

Returns a NULL-terminated array of strings with all arguments of
process @code{pid} (up to @code{max_len} characters, use zero to get
all arguments). @code{glibtop_get_proc_argv()} and
@code{glibtop_get_proc_argv_l()} are wrappers to
@code{glibtop_get_proc_args()} and @code{glibtop_get_proc_args_l()}
that return process' arguments like the C @code{argv}.

Remember to @code{g_strfreev} the returned array to avoid a memory
leak.

@page
@node glibtop_proc_map, glibtop_netload, glibtop_proc_args, System Dependent
@subsection Process Memory Maps

Library function @code{glibtop_get_proc_map}:

@example
@cartouche
glibtop_map_entry *
glibtop_get_proc_map (glibtop_proc_map *buf, pid_t pid);

glibtop_map_entry *
glibtop_get_proc_map_l (glibtop *server, glibtop_proc_map *buf,
                        pid_t pid);
@end cartouche
@end example

Declaration of @code{glibtop_proc_map} in @file{<glibtop/procmap.h>}:

@example
@cartouche
typedef struct _glibtop_proc_map        glibtop_proc_map;

struct _glibtop_proc_map
@{
    guint64   flags,
        number,
        total,
        size;
@};
@end cartouche
@end example

Returns a @code{glibtop_map_entry *} list (which needs to be freed with
@code{g_free}) of memory maps of process @code{pid}.

@table @code
@item number
Number of entries in the returned list.

@item total
Total size of the returned list (this equals @code{number * size}).

@item size
Size of a single entry in the returned list
(this equals @code{sizeof (glibtop_map_entry)}).
@end table

@example
@cartouche
typedef struct _glibtop_map_entry       glibtop_map_entry;

struct _glibtop_map_entry
@{
    guint64 flags, start, end, offset, perm, inode, device;
    char filename [GLIBTOP_MAP_FILENAME_LEN+1];
@};
@end cartouche
@end example

The @code{flags} member is a bit field and specifies which of the other
fields are valid:

@example
@cartouche
#define GLIBTOP_MAP_ENTRY_START         0
#define GLIBTOP_MAP_ENTRY_END           1
#define GLIBTOP_MAP_ENTRY_OFFSET        2
#define GLIBTOP_MAP_ENTRY_PERM          3
#define GLIBTOP_MAP_ENTRY_INODE         4
#define GLIBTOP_MAP_ENTRY_DEVICE        5
#define GLIBTOP_MAP_ENTRY_FILENAME      6
@end cartouche
@end example

Constants for the @code{perm} member:

@example
@cartouche
#define GLIBTOP_MAP_PERM_READ           1
#define GLIBTOP_MAP_PERM_WRITE          2
#define GLIBTOP_MAP_PERM_EXECUTE        4
#define GLIBTOP_MAP_PERM_SHARED         8
#define GLIBTOP_MAP_PERM_PRIVATE        16
@end cartouche
@end example

@page
@node glibtop_netload, glibtop_ppp, glibtop_proc_map, System Dependent
@subsection Network Load

Library function @code{glibtop_get_netload}:

@example
@cartouche
void
glibtop_get_netload (glibtop_netload *buf, const char *interface);

void
glibtop_get_netload_l (glibtop *server, glibtop_netload *buf,
                       const char *interface);
@end cartouche
@end example

Declaration of @code{glibtop_netload} in @file{<glibtop/netload.h>}:

@example
@cartouche
typedef struct _glibtop_netload glibtop_netload;

struct _glibtop_netload
@{
    guint64   flags,
        if_flags,
        mtu,
        subnet,
        address,
        packets_in,
        packets_out,
        packets_total,
        bytes_in,
        bytes_out,
        bytes_total,
        errors_in,
        errors_out,
        errors_total,
        collisions;
@};
@end cartouche
@end example

Returns network statistics for interface @code{interface} (which is the same
than in @code{ifconfig}).

@table @code
@item if_flags
Interface flags. See the contants defined below.
@item mtu
Maximum Transfer Unit (MTU)
@item subnet
Subnet Address
@item address
Interface Address
@item packets_in
Total number of incoming packets
@item packets_out
Total number of outgoing packets
@item packets_total
Total number of packets
@item bytes_in
Total number of incoming bytes
@item bytes_out
Total number of outgoing bytes
@item bytes_total
Total number of bytes
@item errors_in
Total number of errors in incoming direction
@item errors_out
Total number of errors in outgoing direction
@item errors_total
Total number of errors
@item collisions
Total number of collisions
@end table

Please note that not all operating systems distinguish between incoming/outgoing
bytes/packets/errors - in this case only the @samp{_total} fields are valid.
Otherwise, they're just @samp{_in} plus @samp{_out}.

Constants for @code{if_flags}:

@example
@cartouche
enum @{
    GLIBTOP_IF_FLAGS_UP = 1,
    GLIBTOP_IF_FLAGS_BROADCAST,
    GLIBTOP_IF_FLAGS_DEBUG,
    GLIBTOP_IF_FLAGS_LOOPBACK,
    GLIBTOP_IF_FLAGS_POINTOPOINT,
    GLIBTOP_IF_FLAGS_RUNNING,
    GLIBTOP_IF_FLAGS_NOARP,
    GLIBTOP_IF_FLAGS_PROMISC,
    GLIBTOP_IF_FLAGS_ALLMULTI,
    GLIBTOP_IF_FLAGS_OACTIVE,
    GLIBTOP_IF_FLAGS_SIMPLEX,
    GLIBTOP_IF_FLAGS_LINK0,
    GLIBTOP_IF_FLAGS_LINK1,
    GLIBTOP_IF_FLAGS_LINK2,
    GLIBTOP_IF_FLAGS_ALTPHYS,
    GLIBTOP_IF_FLAGS_MULTICAST
@};
@end cartouche
@end example

@page
@node glibtop_ppp, glibtop_disk, glibtop_netload, System Dependent
@subsection PPP Statistics

Library function @code{glibtop_get_ppp}:

@example
@cartouche
void
glibtop_get_ppp_l (glibtop *server, glibtop_ppp *buf,
                   unsigned short device);

void
glibtop_get_ppp (glibtop_ppp *buf, unsigned short device);
@end cartouche
@end example

Declaration of @code{glibtop_ppp} in @file{<glibtop/ppp.h>}:

@example
@cartouche
typedef struct _glibtop_ppp     glibtop_ppp;

struct _glibtop_ppp
@{
    guint64   flags,
        state,
        bytes_in,
        bytes_out;
@};
@end cartouche
@end example

@table @code
@item bytes_in
Number of input bytes
@item bytes_out
Number of output bytes
@end table

There are some constants for @code{state}:

@example
@cartouche
enum @{
    GLIBTOP_PPP_STATE_UNKNOWN = 0,
    GLIBTOP_PPP_STATE_HANGUP,
    GLIBTOP_PPP_STATE_ONLINE
@};
@end cartouche
@end example

@table @code
@item GLIBTOP_PPP_STATE_UNKNOWN
LibGTop was unable to determine the current ppp state.
@item GLIBTOP_PPP_STATE_HANGUP
We're currently offline.
@item GLIBTOP_PPP_STATE_ONLINE
We're currently online.
@end table

@page
@node glibtop_disk, , glibtop_ppp, System Dependent
@subsection DISK Usage

Library function @code{glibtop_get_disk}:

@example
@cartouche
void glibtop_get_disk (glibtop_disk *buf);
void glibtop_get_disk_l (glibtop *server, glibtop_disk *buf);
@end cartouche
@end example

Declaration of @code{glibtop_disk} in @file{<glibtop/disk.h>}:

@example
@cartouche
typedef struct _glibtop_disk     glibtop_disk;

struct _glibtop_disk
@{
    xdisk_sectors_read [GLIBTOP_NDISK],
    xdisk_time_read [GLIBTOP_NDISK],
    xdisk_sectors_write [GLIBTOP_NDISK],
    xdisk_time_write [GLIBTOP_NDISK],
@};
@end cartouche
@end example

All DISK reads and writes are measured by @dfn{sectors} which are normally 512 bytes each. 
All disk time are measured in milliseconds which is 1/1000th of a second.

@table @code
@item xdisk_sectors_read
Number of sectors read since system boot.

@item xdisk_time_read
Number of milliseconds spent reading since system boot.

@item xdisk_sectors_write
Number of sectors written since system boot.

@item xdisk_time_write
Number of milliseconds spent writing since system boot.

@end table

The @samp{xdisk_} are values from arrays of @code{GLIBTOP_NDISK} (defined in
@file{<glibtop/disk.h>}) elements and contain one value for each DISK
in the system.

Please note that all of the disk values are absolute values measured in
certain units since system boot. To get bandwidth values (bytes/s), you need to call @code{glibtop_disk}, save the
result, wait some time and then call it again and divide the differences of
the two values by the time spent reading or writing.

@page
@node Common Functions, Library Functions, System Dependent, Reference Manual
@section Common Functions

This are functions which a common implementation for all systems; we never
use the server for them.

The file system code is taken from GNU Fileutils.

@menu
* glibtop_mountlist::           Mount List.
* glibtop_fsusage::             File System Usage.
@end menu

@node glibtop_mountlist, glibtop_fsusage, Common Functions, Common Functions
@subsection Mount List

Library function @code{glibtop_get_mountlist}:

@example
@cartouche
glibtop_mountentry *
glibtop_get_mountlist_l (glibtop *server, glibtop_mountlist *buf,
                         int all_fs);

glibtop_mountentry *
glibtop_get_mountlist (glibtop_mountlist *buf, int all_fs);
@end cartouche
@end example

The @code{all_fs} parameter specifies whether information about all
filesystems should be returned; this will include filesystem types like
@code{autofs} and @code{procfs}. You should not use this in disk usage
programs, but it can be useful to get a list of all currently mounted
filesystems.

Declaration of @code{glibtop_proc_map} in @file{<glibtop/procmap.h>}:

@example
@cartouche
typedef struct _glibtop_mountlist       glibtop_mountlist;

struct _glibtop_mountlist
@{
    guint64   flags,
        number,
        total,
        size;
@};
@end cartouche
@end example

Returns a @code{glibtop_mountentry *} list (which needs to be freed with
@code{g_free}) of mounted filesystems.

@table @code
@item number
Number of entries in the returned list.

@item total
Total size of the returned list (this equals @code{number * size}).

@item size
Size of a single entry in the returned list
(this equals @code{sizeof (glibtop_mountentry)}).
@end table

@example
@cartouche
typedef struct _glibtop_mountentry      glibtop_mountentry;

struct _glibtop_mountentry
@{
    guint64 dev;
    char devname [GLIBTOP_MOUNTENTRY_LEN+1];
    char mountdir [GLIBTOP_MOUNTENTRY_LEN+1];
    char type [GLIBTOP_MOUNTENTRY_LEN+1];
@};
@end cartouche
@end example

@code{GLIBTOP_MOUNTENTRY_LEN} is defined in @file{<glibtop.h>}.

@table @code
@item devname
Full pathname (such as @samp{/dev/sdb1} for instance) to the mounted device.
@item mountdir
Full pathname of the mountpoint (such as @samp{/usr/local} for instance).
@item type
Filesystem type as a textual string (such as @samp{ext2fs}).
@end table

@page
@node glibtop_fsusage,  , glibtop_mountlist, Common Functions
@subsection File System Usage

Library function @code{glibtop_get_fsusage}:

@example
@cartouche
void
glibtop_get_fsusage_l (glibtop *server, glibtop_fsusage *buf,
                       const char *mount_dir);

void
glibtop_get_fsusage (glibtop_fsusage *buf, const char *mount_dir);
@end cartouche
@end example

Declaration of @code{glibtop_fsusage} in @file{<glibtop/fsusage.h>}:

@example
@cartouche
typedef struct _glibtop_fsusage         glibtop_fsusage;

struct _glibtop_fsusage
@{
    guint64   flags,
        blocks,
        bfree,
        bavail,
        files,
        ffree;
    guint32   block_size;
    guint64 read,
        write;
@};
@end cartouche
@end example

@table @code
@item blocks
Total blocks in the filesystem.
@item bfree
Free blocks available to the superuser.
@item bavail
Free blocks available to ordinary users.
@item files
Total file nodes.
@item ffree
Free file nodes.
@item block_size
Block size in bytes.
@item read
Total blocks read.
@item write
Total blocks written.
@end table

@page
@node Library Functions,  , Common Functions, Reference Manual
@section Library Functions

This are general library functions which can be used to get information
about the library and to control its behavior.

@menu
* glibtop_init::                Server Initialization.
* glibtop_sysdeps::             Server Sysdeps.
* Library Parameters::          Library Parameters.
@end menu

@node glibtop_init, glibtop_sysdeps, Library Functions, Library Functions
@subsection Server Initialization

You do not need to worry about the @code{glibtop *} server structure if
you don't need - the library exports a @code{glibtop_global_server}
which you can use everywhere a @code{glibtop *} is expected.

Most of the library and all of the sysdeps function also have an alias
(which is the function name without the @samp{_l}, @samp{_s} or @samp{_r}
suffix) which don't take a @code{glibtop *} as argument but uses the
@code{glibtop_global_server} instead.

@example
@cartouche
extern glibtop *glibtop_global_server;
@end cartouche
@end example

Library function @code{glibtop_init}:

@example
@cartouche
glibtop *
glibtop_init_r (glibtop **server_ptr, unsigned long features,
                unsigned flags);

void
glibtop_init (void);
@end cartouche
@end example

This function initializes a LibGTop server. It is automatically called
when you use any of the LibGTop functions and will use the global server
in this case.

However, it's appreciated to call @code{glibtop_init} during the
initialization of your application.

You can for instance use

@example
glibtop_init ();
@end example

@noindent
which is equivalent to

@example
glibtop_init_r (&glibtop_global_server, 0, 0);
@end example

Please note that the @code{server_ptr} argument is a pointer to a pointer
(and thus is of type @code{glibtop **}).

To control what @code{glibtop_init} should actually do, you can use the
@code{features} and @code{flags} arguments.

The @code{features} argument is a bit-mask (interpreted in the same way
than @samp{sysdeps.features}) and tells the library which features you're
interested in. The library will only start the server if this is required
for any of those features.

You can use the following constants for the @code{flags} parameter to
control the behavior of the library:

@table @code
@item GLIBTOP_INIT_NO_INIT
Tells the library to do nothing. If the value pointed to by the
@code{server_ptr} argument is @code{NULL}, it will set it to the
@code{glibtop_global_server} and then return.
@item GLIBTOP_INIT_NO_OPEN
Do the initialization, but do not start the server.
@end table

To modify the way the @code{features} are interpretet, you can use the
following constants for @code{flags} (as a bit mask):

@table @code
@item GLIBTOP_FEATURES_NO_SERVER
Never use the server, always call the sysdeps code directly.
If you require any privileges to get them and you don't have those
privileges, the this will obviously not work and the library will
fail to return some or all of the requested values.
@item GLIBTOP_FEATURES_EXCEPT
Inverts the matching of the @code{features} parameter, i.e. if you use
this flag this means that @code{features} are all the features you are
@emph{not} interested in.
Might be useful to say something like "I want everything but ppp".
@end table

@node glibtop_sysdeps, Library Parameters, glibtop_init, Library Functions
@subsection Server Sysdeps

Library function @code{glibtop_get_sysdeps}:

@example
@cartouche
void
glibtop_get_sysdeps_r (glibtop *server, glibtop_sysdeps *buf);

void
glibtop_get_sysdeps (glibtop_sysdeps *buf);
@end cartouche
@end example

Declaration of @code{glibtop_sysdeps} in @file{<glibtop/sysdeps.h>}:

@example
@cartouche
typedef struct _glibtop_sysdeps         glibtop_sysdeps;

struct _glibtop_sysdeps
@{
    guint64 flags,
        features,
        pointer_size,
        cpu,
        mem,
        swap,
        uptime,
        loadavg,
        shm_limits,
        msg_limits,
        sem_limits,
        proclist,
        proc_state,
        proc_uid,
        proc_mem,
        proc_time,
        proc_signal,
        proc_kernel,
        proc_segment,
        proc_args,
        proc_map,
        mountlist,
        fsusage,
        netload,
        ppp;
@};
@end cartouche
@end example

@table @code
@item features
This is a bit field (the so-called @dfn{server features}) stating
for which features we need to use the server.
@item pointer_size
This was added in LibGTop 1.1.0 and tells you the number of bits a
@code{void*} has in the server (this may be different from the
size on the client machine if we're talking over the daemon to a
remove machine).
@end table

The following constants from @file{<glibtop/sysdeps.h>} serve as bit-indices
for the @code{features} field:

@example
@cartouche
#define GLIBTOP_SYSDEPS_CPU             0
#define GLIBTOP_SYSDEPS_MEM             1
#define GLIBTOP_SYSDEPS_SWAP            2
#define GLIBTOP_SYSDEPS_UPTIME          3
#define GLIBTOP_SYSDEPS_LOADAVG         4
#define GLIBTOP_SYSDEPS_SHM_LIMITS      5
#define GLIBTOP_SYSDEPS_MSG_LIMITS      6
#define GLIBTOP_SYSDEPS_SEM_LIMITS      7
#define GLIBTOP_SYSDEPS_PROCLIST        8
#define GLIBTOP_SYSDEPS_PROC_STATE      9
#define GLIBTOP_SYSDEPS_PROC_UID        10
#define GLIBTOP_SYSDEPS_PROC_MEM        11
#define GLIBTOP_SYSDEPS_PROC_TIME       12
#define GLIBTOP_SYSDEPS_PROC_SIGNAL     13
#define GLIBTOP_SYSDEPS_PROC_KERNEL     14
#define GLIBTOP_SYSDEPS_PROC_SEGMENT    15
#define GLIBTOP_SYSDEPS_PROC_ARGS       16
#define GLIBTOP_SYSDEPS_PROC_MAP        17
#define GLIBTOP_SYSDEPS_MOUNTLIST       18
#define GLIBTOP_SYSDEPS_FSUSAGE         19
#define GLIBTOP_SYSDEPS_NETLOAD         20
#define GLIBTOP_SYSDEPS_PPP             21
@end cartouche
@end example

@node Library Parameters,  , glibtop_sysdeps, Library Functions
@subsection Library Parameters

Library function @code{glibtop_get_parameter}:

@example
@cartouche
size_t
glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
                         void *data_ptr, size_t data_size);

size_t
glibtop_get_parameter (const unsigned parameter, void *data_ptr,
                       size_t data_size);
@end cartouche
@end example

This function is used to retrieve a library parameter (see below for a more
detailed description). It returns the size of the retrieved parameter on
success, zero on failure or minus the actual size of the parameter if
@code{data_size} was too small.

You may call this function with @code{data_ptr} set to @code{NULL} to get the
actual size of a parameter (as a negative value).

@table @code
@item parameter
The parameter you want to retrieve (see below for constants).
@item data_ptr
Pointer to a place where the parameter should be stored.
@item data_size
Maximum size of the parameter.
@end table

Library function @code{glibtop_set_parameter}:

@example
@cartouche
void
glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
                         const void *data_ptr, size_t data_size);

void
glibtop_set_parameter (const unsigned parameter, const void *data_ptr,
                       size_t data_size);
@end cartouche
@end example

This function is used to modify a library parameter. Please not that you
may not set all parameters since some of them are read-only.

@table @code
@item parameter
The parameter you want to modify (see below for constants).
@item data_ptr
Pointer to the value which should be set.
@item data_size
Size of the new value. For fixed-size parameters, this must match
the exact size of the parameter or you'll get an error.
@end table

The following parameters are defined in @file{<glibtop/parameter.h>}:

@table @code
@item GLIBTOP_PARAM_FEATURES
This is a read-only @code{unsigned long} representing the @code{features}
field of @code{glibtop_sysdeps}.
@item GLIBTOP_PARAM_REQUIRED
This is a @code{glibtop_sysdeps} structure specifying which features the
client requires the library return. If it fails to get any of them, you'll
get an error.
@item GLIBTOP_PARAM_ERROR_METHOD
This is an @code{unsigned} telling the library what to do if it fails to
get any of the features that are marked as required via the
@code{GLIBTOP_PARAM_REQUIRED} parameter (see below for constants).
@end table

You can use the following constants for @code{GLIBTOP_PARAM_ERROR_METHOD}
(defined in @file{<glibtop/open.h>}):

@table @code
@item GLIBTOP_ERROR_METHOD_IGNORE
Ignore the error condition.
@item GLIBTOP_ERROR_METHOD_WARN_ONCE
Warn once about the absense of some of the required features, then modify
@code{GLIBTOP_PARAM_REQUIRED} so that the missing ones are no longer
required. This is the prefered value for applications since it'll only
print out the warning message once and not each time the library tries to
get one of those features.
@item GLIBTOP_ERROR_METHOD_WARN
Warn each time the library fails to get some of the required features.
@item GLIBTOP_ERROR_METHOD_ABORT
Abort if the library fails to get some of the required features. This
should not be used by applications.
@end table