aboutsummaryrefslogtreecommitdiffstats
path: root/french/aster/files/bibc_utilitai_mempid.c.diff
blob: fbcaea8101529c1220d67a2d9259b26dec124fb6 (plain) (blame)
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
--- bibc/utilitai/mempid.c.orig 2013-12-16 09:25:29.000000000 +0100
+++ bibc/utilitai/mempid.c  2014-05-20 22:28:25.000000000 +0200
@@ -19,7 +19,14 @@
 #include "aster.h"
 
 #ifdef _POSIX
-#include <fcntl.h>
+# ifdef __FreeBSD__
+#  include <kvm.h>
+#  include <sys/param.h>
+#  include <sys/sysctl.h>
+#  include <sys/user.h>
+#  include <err.h>
+# endif
+# include <fcntl.h>
 #endif
 
 /*
@@ -40,9 +47,48 @@
     pid_t numpro;
 #ifdef _POSIX
     pid_t getpid(void);
-    
+
     numpro = getpid();
 
+# ifdef __FreeBSD__
+/*
+** FreeBSD and some others without /proc ?
+*/
+
+
+#define B2K(x) ((x) >> 10) /* bytes to kbytes */
+#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */
+
+    char errbuf[_POSIX2_LINE_MAX];
+    struct kinfo_proc *kp;
+    kvm_t *kd;
+    int count;
+    kd = kvm_openfiles(NULL, "/dev/null", NULL, O_RDONLY, errbuf);
+    if (kd == NULL)
+        errx(1, "kvm_openfiles: %s", errbuf);
+
+    kp = kvm_getprocs(kd, KERN_PROC_PID, numpro, &count);
+    if (kp == NULL) {
+        (void)fprintf(stderr, "kvm_getprocs: %s", kvm_geterr(kd));
+        kvm_close(kd);
+        return -1;
+    }
+
+    kvm_close(kd);
+
+    /* VmData */
+    val[0] = P2K((uintmax_t)kp->ki_dsize);
+    /* VmSize */
+    val[1] = B2K((uintmax_t)kp->ki_size);
+    /* VmPeak - not defined in /compat/linux/proc/pid/status */
+    val[2] = -1;
+    /* VmRSS */
+    val[3] = P2K((uintmax_t)kp->ki_rssize);
+    /* VmStk */
+    lmem = P2K((uintmax_t)kp->ki_ssize);
+
+# else /* Linux */
+
     sprintf(filename, "/proc/%ld/status", (long)numpro);
     fd = open(filename, O_RDONLY, 0);
     if (fd==-1) return -1;
@@ -68,7 +114,10 @@
       
     S=strstr(sbuf,"VmStk:")+7;
     lmem = atoi(S);
+# endif
+
     return lmem ;
+
 #else
 /* 
 ** Pour retourner des valeurs sous Windows