0
I have a main program written in C++. It fires children programs using vfork() and execl(). The communication between them works perfectly using FIFO (the father writes and the son 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 blocking problem waiting for another file opening process in the other mode.
The writing is done with
write(fd, write_buffer, sizeof(write_buffer));
On the son’s side 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));
Your message is sent successfully.
For tests I kill the main program using Kill on the linux terminal and the children continue running. I call again the main program and it enters the part of reestablishing communication with the same procedure presented above. So I try to send a message to his son, but he gets nothing.
Does anyone have any idea how I can reestablish this communication?
Make a tour by stackoverflow, learn a little about the rules and good practices. Then edit your question and enter the code that makes the connection.
– Marco Giovanni
I edited the question with code and more details @Marcogiovanni
– felipear
create a complete minimum example and put it here
– zentrunix
Just to clarify, the idea of using FIFO was abandoned because of changes in the project, so I didn’t update the topic. With this also not found a solution to the problem to share here.
– felipear