Revision 981
Added signal handling code to core simulator
added a robot_test directory which contiains code to run the timer and deal with the robot side signaling. To compile it you need to run gcc
robot_test/robot.c -o robot_test/robot. This whole file is temporary. It is just proof of concept until it gets added to the simulator library
main.c | ||
---|---|---|
1 | 1 |
#include "gtk_gui.h" |
2 |
#include <stdio.h> |
|
3 |
#include <unistd.h> |
|
4 |
#include <stdlib.h> |
|
5 |
#include <signal.h> |
|
6 |
#include <sys/wait.h> |
|
2 | 7 |
|
8 |
int create_robot(char *execname, int id) |
|
9 |
{ |
|
10 |
/* do shared memory stuff here */ |
|
11 |
|
|
12 |
int child; |
|
13 |
|
|
14 |
if((child = fork())<0){ |
|
15 |
printf("error with fork!\n"); |
|
16 |
return -1; |
|
17 |
} |
|
18 |
|
|
19 |
char *envp[] = {"test=1", NULL}; |
|
20 |
|
|
21 |
if(!child){ |
|
22 |
/* restore default sigchld handler */ |
|
23 |
signal(SIGCHLD, SIG_DFL); |
|
24 |
|
|
25 |
execve(execname, NULL, envp); //TODO: keep the other env. stuff around |
|
26 |
printf ("error! exec failed\n"); |
|
27 |
exit(-1); |
|
28 |
} |
|
29 |
|
|
30 |
return child; |
|
31 |
} |
|
32 |
|
|
33 |
void *sig_chld_handler(int sig) |
|
34 |
{ |
|
35 |
pid_t pid; |
|
36 |
int cstat; |
|
37 |
|
|
38 |
printf("SIGCHLD: parent waiting\n"); |
|
39 |
|
|
40 |
pid = waitpid(0, &cstat, WUNTRACED); |
|
41 |
|
|
42 |
printf("got %d from %d\n", cstat, pid); |
|
43 |
|
|
44 |
kill(pid, SIGCONT); |
|
45 |
|
|
46 |
return NULL; |
|
47 |
} |
|
48 |
|
|
3 | 49 |
int main(int argc, char** argv) |
4 | 50 |
{ |
5 |
return gtk_gui_run(argc, argv); |
|
51 |
signal(SIGCHLD, sig_chld_handler); |
|
52 |
|
|
53 |
create_robot("robot_test/robot", 0); |
|
54 |
|
|
55 |
printf("returned to parent\n"); |
|
56 |
|
|
57 |
|
|
58 |
gtk_gui_run(argc, argv); |
|
59 |
|
|
60 |
printf("parent exiting.\n"); |
|
61 |
|
|
62 |
return 0; |
|
6 | 63 |
} |
7 | 64 |
|
Also available in: Unified diff