diff --git a/mem2swap.c b/mem2swap.c --- a/mem2swap.c +++ b/mem2swap.c @@ -17,6 +17,14 @@ #define DEFAULT_MEGS 64 #endif +#ifdef __linux__ +#define CMD_FREE "/usr/bin/free" +#define CMD_ARGS "-m" +#elif __unix__ +#define CMD_FREE "/sbin/sysctl" +#define CMD_ARGS "hw.usermem" +#endif + int set_limit (int); int main (int argc, char **argv) @@ -26,7 +34,7 @@ long int *p; long int *p_new; - char *args[] = { "/usr/bin/free", "-m", NULL }; + char *args[] = { CMD_FREE, CMD_ARGS, NULL }; int size = sizeof (*p); int megs = DEFAULT_MEGS; @@ -69,7 +77,7 @@ pid = fork (); switch (pid) { case 0: - execve ("/usr/bin/free", args, NULL); + execve (CMD_FREE, args, NULL); case -1: perror ("Fork Error"); return EXIT_FAILURE;