I have a main program written in C ++. It triggers child programs using vfork () and execl (). The communication between them works perfectly using FIFO (the parent writes and the child reads).
In the main program the sequence to establish the communication is
if (mkfifo(CONTROLLER_file, 0666) < 0)
perror("mkfifo");
if((aux_fd = open(CONTROLLER_file, O_RDONLY | O_NONBLOCK) )< 0)
perror("ERRO AO ABRIR O arquivo");
if((fd = open(CONTROLLER_file, O_WRONLY)) < 0)
perror("ERRO AO ABRIR O arquivo");
I do this to avoid the blocking problem waiting for another process to open the file in the other mode.
The writing is done with
write(fd, write_buffer, sizeof(write_buffer));
On the side of the child I do
if (mkfifo(CONTROLLER_file, 0666) < 0)
perror("mkfifo");
if((file_descriptor = open(CONTROLLER_file, O_RDONLY)) < 0)
perror("ERRO AO ABRIR O ARQUIVO");
And I read with
fcntl(file_descriptor, F_SETFL, flags | O_NONBLOCK);
read(file_descriptor, read_buffer, sizeof(read_buffer));
The message is sent successfully.
For testing I kill the main program using kill on the linux terminal and the children continue to run. I call again the main program and it goes into the part of re-establishing the communication with the same procedure presented above. I then try to send a message to the child, but he does not receive anything.
Does anyone have any idea how I can reestablish this communication?