Project

General

Profile

Revision 961

Added by Brad Neuman over 12 years ago

added tests of two possible ways to control proc's.

leaning heavily towards the itimer method

View differences:

branches/simulator/projects/simulator/core/test_rlimit.c
1
#include <stdio.h>
2
#include <sys/time.h>
3
#include <sys/resource.h>
4

  
5
int main()
6
{
7
  int ret;
8
  struct rlimit rl;
9

  
10
  ret = getrlimit(RLIMIT_CPU, &rl);
11

  
12
  printf("getrlimit(RLIMIT_CPU) returned %d.\n"
13
	 "soft = %d\nhard = %d\n",
14
	 ret, rl.rlim_cur, rl.rlim_max);
15

  
16
  printf("seting soft limit to 3 seconds...\n");
17

  
18
  rl.rlim_cur = 30;
19
  ret = setrlimit(RLIMIT_CPU, &rl);
20

  
21
  printf("done. returned %d\nentering loop", ret);
22

  
23
  while(1);
24

  
25
  return 0;
26
}
branches/simulator/projects/simulator/core/test_timer.c
1
#include <stdio.h>
2
#include <sys/time.h>
3
#include <signal.h>
4

  
5
void *tick(int sig)
6
{
7
  printf("tick\n");
8
  fflush(stdout);
9

  
10
  return NULL;
11
}
12

  
13
int main()
14
{
15
  int ret;
16
  struct itimerval iv;
17

  
18
  iv.it_interval.tv_sec = 1;
19
  iv.it_interval.tv_usec = 0;
20
  iv.it_value.tv_sec = 5;
21
  iv.it_value.tv_usec = 0;
22

  
23
  signal(SIGVTALRM, tick);
24

  
25
  ret = setitimer(ITIMER_VIRTUAL, &iv, NULL);
26

  
27
  printf("setitimer returned %d.\n waiting...\n", ret);
28
  fflush(stdout);
29

  
30
  while(1);
31

  
32
  return 0;
33
}

Also available in: Unified diff