equal
deleted
inserted
replaced
3 * Copyright (C) 2008 Markus Broeker |
3 * Copyright (C) 2008 Markus Broeker |
4 */ |
4 */ |
5 |
5 |
6 #include <stdio.h> |
6 #include <stdio.h> |
7 #include <stdlib.h> |
7 #include <stdlib.h> |
|
8 #include <wait.h> |
8 #include <unistd.h> |
9 #include <unistd.h> |
9 |
10 |
10 int set_limit (int); |
11 int set_limit (int); |
11 |
12 |
12 int main (int argc, char **argv) |
13 int main (int argc, char **argv) |
13 { |
14 { |
14 int i; |
15 int i; |
|
16 int pid; |
15 |
17 |
16 char **args; |
18 char **args; |
17 |
19 |
18 if (argc < 3) { |
20 if (argc < 3) { |
19 printf ("Usage: %s <mem> <cmd> [args]...\n", argv[0]); |
21 printf ("Usage: %s <mem> <cmd> [args]...\n", argv[0]); |
29 for (i = 2; i < argc; i++) |
31 for (i = 2; i < argc; i++) |
30 args[i - 2] = argv[i]; |
32 args[i - 2] = argv[i]; |
31 |
33 |
32 args[i - 2] = NULL; |
34 args[i - 2] = NULL; |
33 |
35 |
34 if (set_limit (atoi (argv[1])) == 0) { |
36 pid = fork (); |
35 i = execvp (argv[2], args); |
37 switch (pid) { |
36 } else { |
38 case 0: |
37 perror ("Limit Error"); |
39 if (set_limit (atoi (argv[1])) == 0) { |
|
40 i = execvp (argv[2], args); |
|
41 } else { |
|
42 perror ("Limit Error"); |
|
43 return EXIT_FAILURE; |
|
44 } |
|
45 case -1: |
|
46 perror ("Fork Error"); |
38 return EXIT_FAILURE; |
47 return EXIT_FAILURE; |
|
48 default: |
|
49 wait (&i); |
39 } |
50 } |
40 |
51 |
41 if (args != NULL) |
52 if (args != NULL) |
42 free (args); |
53 free (args); |
43 |
54 |