root / branches / simulator / projects / simulator / simulator / core / main.c @ 981
History | View | Annotate | Download (1019 Bytes)
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> |
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 |
|
49 |
int main(int argc, char** argv) |
50 |
{ |
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; |
63 |
} |
64 |
|