mem2swap.c
changeset 64 993b97c4ad2d
parent 63 5a82f89d607e
child 77 49e0babccb23
--- a/mem2swap.c
+++ b/mem2swap.c
@@ -9,6 +9,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
+#include <wait.h>
 
 #define N 1000
 
@@ -29,6 +30,7 @@
 
     int size = sizeof (*p);
     int megs = DEFAULT_MEGS;
+    int pid;
 
     if (argc == 2)
         megs = atoi (argv[1]);
@@ -64,7 +66,17 @@
     }
 
     printf ("\n\n");
-    execve ("/usr/bin/free", args, NULL);
 
-    return EXIT_SUCCESS;
+    pid = fork ();
+    switch (pid) {
+    case 0:
+        execve ("/usr/bin/free", args, NULL);
+    case -1:
+        perror ("Fork Error");
+        return EXIT_FAILURE;
+    default:
+        wait (&pid);
+    }
+
+    return pid;
 }