Revision 984
Function to free memory added, not sure how to test if its working.
robot.c | ||
---|---|---|
3 | 3 |
#include <signal.h> |
4 | 4 |
#include <unistd.h> |
5 | 5 |
#include <stdlib.h> |
6 |
#include <sys/shm.h> |
|
7 |
#include <sys/ipc.h> |
|
8 |
#include <robot_shared.h> |
|
9 |
#include <string.h> |
|
6 | 10 |
|
7 | 11 |
volatile int i; |
8 | 12 |
|
13 |
RobotShared* shared_state; |
|
14 |
|
|
9 | 15 |
void *tick(int sig) |
10 | 16 |
{ |
11 | 17 |
printf("robot process paused. suspending\n"); |
12 | 18 |
|
19 |
shared_state->motor1++; |
|
20 |
|
|
13 | 21 |
if(raise(SIGTSTP)<0) |
14 | 22 |
printf("could not kill self!\n"); |
15 | 23 |
|
... | ... | |
23 | 31 |
int ret; |
24 | 32 |
struct itimerval iv; |
25 | 33 |
|
34 |
shared_state = shmat(atoi(envp[0]), NULL, 0); |
|
35 |
if(shared_state < 0) |
|
36 |
{ |
|
37 |
printf("unable to get shared memory region\n"); |
|
38 |
return 1; |
|
39 |
} |
|
40 |
|
|
41 |
|
|
26 | 42 |
printf("hello. I am a robot w/ env[0] %s\n", envp[0]); |
27 | 43 |
|
28 | 44 |
iv.it_interval.tv_sec = 1; |
... | ... | |
42 | 58 |
while(1) |
43 | 59 |
i++; |
44 | 60 |
|
61 |
shmdt(shared_state); |
|
45 | 62 |
return 0; |
46 | 63 |
} |
Also available in: Unified diff