Project

General

Profile

Statistics
| Revision:

root / branches / simulator / projects / simulator / libsim / libsim.c @ 993

History | View | Annotate | Download (1.02 KB)

1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <sys/time.h>
4
#include <signal.h>
5
#include <unistd.h>
6
#include <stdlib.h>
7
#include <sys/shm.h>
8
#include <sys/ipc.h>
9
#include <robot_shared.h>
10
#include <string.h>
11

    
12

    
13
RobotShared* shared_state;
14

    
15
void *tick(int sig)
16
{
17
  printf("robot process paused. suspending\n"); 
18

    
19
  if(raise(SIGTSTP)<0)
20
    printf("could not kill self!\n");
21

    
22
  printf("robot resumed\n");
23

    
24
  return NULL;
25
}
26

    
27

    
28
void dragonfly_init(int config)
29
{
30
  struct itimerval iv;
31
  int ret;
32

    
33
  shared_state = shmat(atoi(envp[0]), NULL, 0);
34
  if(shared_state < 0)
35
  {
36
          printf("unable to get shared memory region\n");
37
          return 1;
38
  }
39

    
40
                                             
41
  printf("hello. I am a robot w/ memory_id %s\n", getenv("memory_id"));
42

    
43

    
44
  iv.it_interval.tv_sec = 1;
45
  iv.it_interval.tv_usec = 0;
46
  iv.it_value.tv_sec = 3;
47
  iv.it_value.tv_usec = 0;
48

    
49
  signal(SIGVTALRM, tick);
50

    
51
  ret = setitimer(ITIMER_VIRTUAL, &iv, NULL);
52

    
53
  printf("setitimer returned %d.\n waiting...\n", ret);
54
  fflush(stdout);
55

    
56
  //TODO: clean up code??
57

    
58
}
59