1#include <sys/types.h>
2#include <sys/ipc.h>
3#include <sys/shm.h>
4#include <stdio.h>
5#include <barrelfish/barrelfish.h>
6
7#define SHMSZ     27
8
9int main(int argc, char *argv[])
10{
11    char c;
12    int shmid;
13    key_t key;
14    char *shm, *s;
15
16    /*
17     * We'll name our shared memory segment
18     * "5678".
19     */
20    key = 5678;
21
22    /*
23     * Create the segment.
24     */
25    if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
26        debug_printf("server: error in shmid\n");
27        return 1;
28    }
29
30    debug_printf("server: shmget performed correctly id: %d\n", shmid);
31
32    /*
33     * Now we attach the segment to our data space.
34     */
35    if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
36        debug_printf("server: error in shmat\n");
37        return 1;
38    }
39
40    debug_printf("server: shmat performed correctly shm: %p\n", shm);
41
42    /*
43     * Now put some things into the memory for the
44     * other process to read.
45     */
46    s = shm;
47
48    for (c = 'a'; c <= 'z'; c++)
49        *s++ = c;
50    *s = 0;
51
52    debug_printf("server: written some data, waiting for *\n");
53    /*
54     * Finally, we wait until the other process
55     * changes the first character of our memory
56     * to '*', indicating that it has read what
57     * we put there.
58     */
59    while (*shm != '*') thread_yield();
60        //sleep(1);
61
62    debug_printf("server: got it, exiting\n");
63
64    return 0;
65}
66