So basically I want to suspend a bit the child process after it's creation, just so the parent prepare some data for it in a shared memory. I'm trying to use a semaphore, as suggested here: How to share semaphores between processes using shared memory.
Problem nr 1: the child can't open the semaphore.
Problem nr 2: strerror returns an int, but man strerror clearly says it returns an char *.
To avoid "what have you tried":
sem = sem_open("/semaphore", O_CREAT, 0644, 0);
for (i = 0; i < num; i++)
{
pid = fork();
if (pid == 0)
{
sem = sem_open("/semaphore", 0);
if (sem == SEM_FAILED)
{
printf( "Error : %d\n", strerror(errno ));
exit(0);
}
sem_wait(sem);
exit(0);
}
}
prepare_data_for_child_processes();
for (i = 0; i < mpi_comm_world->np; i++)
sem_post(sem);
sem_close(sem);
sem_unlink("/semaphore");