mem2swap.c
changeset 64 993b97c4ad2d
parent 63 5a82f89d607e
child 77 49e0babccb23
equal deleted inserted replaced
63:5a82f89d607e 64:993b97c4ad2d
     7 
     7 
     8 #include <stdio.h>
     8 #include <stdio.h>
     9 #include <stdlib.h>
     9 #include <stdlib.h>
    10 #include <unistd.h>
    10 #include <unistd.h>
    11 #include <errno.h>
    11 #include <errno.h>
       
    12 #include <wait.h>
    12 
    13 
    13 #define N 1000
    14 #define N 1000
    14 
    15 
    15 #ifndef DEFAULT_MEGS
    16 #ifndef DEFAULT_MEGS
    16 #define DEFAULT_MEGS 64
    17 #define DEFAULT_MEGS 64
    27 
    28 
    28     char *args[] = { "/usr/bin/free", "-m", NULL };
    29     char *args[] = { "/usr/bin/free", "-m", NULL };
    29 
    30 
    30     int size = sizeof (*p);
    31     int size = sizeof (*p);
    31     int megs = DEFAULT_MEGS;
    32     int megs = DEFAULT_MEGS;
       
    33     int pid;
    32 
    34 
    33     if (argc == 2)
    35     if (argc == 2)
    34         megs = atoi (argv[1]);
    36         megs = atoi (argv[1]);
    35 
    37 
    36     printf ("Mem2Swap - Version 1.0\n");
    38     printf ("Mem2Swap - Version 1.0\n");
    62         printf ("and %ld MB allocated\n", p[n * N - 1] / 1024 / 1024);
    64         printf ("and %ld MB allocated\n", p[n * N - 1] / 1024 / 1024);
    63         free (p);
    65         free (p);
    64     }
    66     }
    65 
    67 
    66     printf ("\n\n");
    68     printf ("\n\n");
    67     execve ("/usr/bin/free", args, NULL);
       
    68 
    69 
    69     return EXIT_SUCCESS;
    70     pid = fork ();
       
    71     switch (pid) {
       
    72     case 0:
       
    73         execve ("/usr/bin/free", args, NULL);
       
    74     case -1:
       
    75         perror ("Fork Error");
       
    76         return EXIT_FAILURE;
       
    77     default:
       
    78         wait (&pid);
       
    79     }
       
    80 
       
    81     return pid;
    70 }
    82 }