equal
deleted
inserted
replaced
|
1 /** |
|
2 * $Id: prog_limit.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $ |
|
3 * $Source: /development/c/mem2swap/prog_limit.c,v $ |
|
4 * |
|
5 */ |
|
6 |
|
7 #include <stdio.h> |
|
8 #include <stdlib.h> |
|
9 #include <unistd.h> |
|
10 #include <sys/time.h> |
|
11 #include <sys/resource.h> |
|
12 |
|
13 int set_limit (int); |
|
14 |
|
15 int main (int argc, char **argv) |
|
16 { |
|
17 int i; |
|
18 char **args; |
|
19 |
|
20 if (argc < 3) { |
|
21 printf ("Usage: %s <mem> <cmd> [args]...\n", argv[0]); |
|
22 printf ("Report bugs to mbroeker@largo.homelinux.org\n"); |
|
23 return EXIT_SUCCESS; |
|
24 } |
|
25 |
|
26 if ((args = calloc ((argc - 2), sizeof (char *))) == NULL) { |
|
27 perror ("calloc"); |
|
28 return EXIT_FAILURE; |
|
29 } |
|
30 |
|
31 for (i = 2; i < argc; i++) |
|
32 args[i - 2] = argv[i]; |
|
33 |
|
34 args[i] = NULL; |
|
35 |
|
36 if (set_limit (atoi (argv[1]) * 1024 * 1024) == 0) |
|
37 execvp (argv[2], args); |
|
38 else |
|
39 perror ("Limit Error"); |
|
40 |
|
41 if (args != NULL) |
|
42 free (args); |
|
43 |
|
44 return EXIT_SUCCESS; |
|
45 } |