hfawzy
12-07-2003, 01:29 PM
Hello,
Here is what I'm trying to do:
I'm developing a C program whose job is to execute any C++ program.
The C++ program that will be executed have some restrictions to respect:
- execution time mustn't exceed a certain time limit
- memory usage mustn't exceed a certain value.
So my job in the C program I'm developing is to check whether the C++ program being run violate any of the restrictions above.
I managed to check the execution time and kill the process whenever the C++ program exceeds the time limit, however, I can't get to limit data memory usage. I tried using a function called setrlimit but to no avail :(
Here is the code I used:
int data_limit = 1024 * 1024 * 4;
int stack_limit = 1024 * 1024 * 2;
struct rlimit myrlimit;
rl.rlim_cur = data_limit;
rl.rlim_max = data_limit;
setrlimit(RLIMIT_DATA, &myrlimit);
rl.rlim_cur = stack_limit;
rl.rlim_max = stack_limit;
setrlimit(RLIMIT_STACK, &myrlimit);
Can you please help me regarding the second restriction?
I appreciate any help..
Thanks in advance,
Hfawzy.
Here is what I'm trying to do:
I'm developing a C program whose job is to execute any C++ program.
The C++ program that will be executed have some restrictions to respect:
- execution time mustn't exceed a certain time limit
- memory usage mustn't exceed a certain value.
So my job in the C program I'm developing is to check whether the C++ program being run violate any of the restrictions above.
I managed to check the execution time and kill the process whenever the C++ program exceeds the time limit, however, I can't get to limit data memory usage. I tried using a function called setrlimit but to no avail :(
Here is the code I used:
int data_limit = 1024 * 1024 * 4;
int stack_limit = 1024 * 1024 * 2;
struct rlimit myrlimit;
rl.rlim_cur = data_limit;
rl.rlim_max = data_limit;
setrlimit(RLIMIT_DATA, &myrlimit);
rl.rlim_cur = stack_limit;
rl.rlim_max = stack_limit;
setrlimit(RLIMIT_STACK, &myrlimit);
Can you please help me regarding the second restriction?
I appreciate any help..
Thanks in advance,
Hfawzy.