prog_limit.c
changeset 64 993b97c4ad2d
parent 60 47c13ca8c4d0
child 67 abe63a276a36
--- a/prog_limit.c
+++ b/prog_limit.c
@@ -5,6 +5,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <wait.h>
 #include <unistd.h>
 
 int set_limit (int);
@@ -12,6 +13,7 @@
 int main (int argc, char **argv)
 {
     int i;
+    int pid;
 
     char **args;
 
@@ -31,11 +33,20 @@
 
     args[i - 2] = NULL;
 
-    if (set_limit (atoi (argv[1])) == 0) {
-        i = execvp (argv[2], args);
-    } else {
-        perror ("Limit Error");
+    pid = fork ();
+    switch (pid) {
+    case 0:
+        if (set_limit (atoi (argv[1])) == 0) {
+            i = execvp (argv[2], args);
+        } else {
+            perror ("Limit Error");
+            return EXIT_FAILURE;
+        }
+    case -1:
+        perror ("Fork Error");
         return EXIT_FAILURE;
+    default:
+        wait (&i);
     }
 
     if (args != NULL)