I wrote a small app that uses shared memory (using shm_open and mmap). It launches say, four child processes (via four threads) that all look at a shared memory location for data. The way it is now, the data is just a line of characters. I need to have each child process write data to disk, but it has to be in a specific order. Since all four are launched simultaneously, I don't know which will finish its task first. With threads, this isn't a problem as I just use pthread_join() to block until the threads are finished and perform the write in the main thread. But with child processes, there is no such function that I know of. My thought was to set up another shared memory location that holds an int. That int would be used to send control messages between processes.
Here is my code so far:
The code works fine passing characters to/from the shared memory location, but I couldn't get it to work by just passing one int.Code:#define MAXCHRS 255 char mempath = "/tmp/shmem0"; int fd; char *membuffer; fd = shm_open(mempath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); membuffer = (char*)mmap(0, MAXCHRS, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); fd(close);