Share POSIX semaphore among multiple processes

前端 未结 2 802
梦谈多话
梦谈多话 2021-02-04 07:24

I need to create two child processes each of which calls execvp ater being forked, and the executables share POSIX semaphores between them.

Do I need to cr

2条回答
  •  感动是毒
    2021-02-04 08:03

    Shared memory approach will also work here, only thing here is parent process has to initialise the shared memory. There seems one bug in this code instead of two child, parent function will fork 3 child process here. There should be break statement inside

        if (pids[i] == 0) {
            if (execl(CHILD_PROGRAM, CHILD_PROGRAM, NULL) < 0) {
                perror("execl(2) failed");
                exit(EXIT_FAILURE);
            }
         break; //this is required
      }
    

提交回复
热议问题