mem2swap.c
changeset 138 dff18d1ac2af
parent 113 397270b5d21a
child 139 cb1d3f4cf18e
equal deleted inserted replaced
137:d8a0984b72fc 138:dff18d1ac2af
    15 
    15 
    16 #ifndef DEFAULT_MEGS
    16 #ifndef DEFAULT_MEGS
    17 #define DEFAULT_MEGS 64
    17 #define DEFAULT_MEGS 64
    18 #endif
    18 #endif
    19 
    19 
       
    20 #ifdef __linux__
       
    21 #define CMD_FREE "/usr/bin/free"
       
    22 #define CMD_ARGS "-m"
       
    23 #elif __unix__
       
    24 #define CMD_FREE "/sbin/sysctl"
       
    25 #define CMD_ARGS "hw.usermem"
       
    26 #endif
       
    27 
    20 int set_limit (int);
    28 int set_limit (int);
    21 
    29 
    22 int main (int argc, char **argv)
    30 int main (int argc, char **argv)
    23 {
    31 {
    24     int i, n = 0;
    32     int i, n = 0;
    25 
    33 
    26     long int *p;
    34     long int *p;
    27     long int *p_new;
    35     long int *p_new;
    28 
    36 
    29     char *args[] = { "/usr/bin/free", "-m", NULL };
    37     char *args[] = { CMD_FREE, CMD_ARGS, NULL };
    30 
    38 
    31     int size = sizeof (*p);
    39     int size = sizeof (*p);
    32     int megs = DEFAULT_MEGS;
    40     int megs = DEFAULT_MEGS;
    33     int pid;
    41     int pid;
    34 
    42 
    67     printf ("\n\n");
    75     printf ("\n\n");
    68 
    76 
    69     pid = fork ();
    77     pid = fork ();
    70     switch (pid) {
    78     switch (pid) {
    71     case 0:
    79     case 0:
    72         execve ("/usr/bin/free", args, NULL);
    80         execve (CMD_FREE, args, NULL);
    73     case -1:
    81     case -1:
    74         perror ("Fork Error");
    82         perror ("Fork Error");
    75         return EXIT_FAILURE;
    83         return EXIT_FAILURE;
    76     default:
    84     default:
    77         wait (&pid);
    85         wait (&pid);