Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.02 KB)

1 986 bneuman
#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 993 ayeager
#include <robot_shared.h>
10 986 bneuman
#include <string.h>
11 906 bcoltin
12 986 bneuman
13 993 ayeager
RobotShared* shared_state;
14 986 bneuman
15
void *tick(int sig)
16
{
17 993 ayeager
  printf("robot process paused. suspending\n");
18 986 bneuman
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 906 bcoltin
void dragonfly_init(int config)
29
{
30 986 bneuman
  struct itimerval iv;
31
  int ret;
32 906 bcoltin
33 993 ayeager
  shared_state = shmat(atoi(envp[0]), NULL, 0);
34 986 bneuman
  if(shared_state < 0)
35
  {
36
          printf("unable to get shared memory region\n");
37
          return 1;
38 993 ayeager
  }
39 986 bneuman
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 906 bcoltin
}