I have encountered such a problem in my work. There are two programs. The first program will make a process EXEC calling the second program. After calling, the first program continues to perform the parent process. I asked the first program's parent process to stop running until the second program exits or runs to some time.
Below is the code of two examples
Run the GUI program first, run the Player program
./gui and running in the background
./player
/*GUI.C *
#include
#include
#include
#include
#include
#define FIFO_SERVER "./fifoserver"
int main ()
{
Int fd;
Char BUF;
Printf ("GUI: CREATE NAME PIPE / N);
Umask (0);
// IF (Mkfifo (FIFO_SERVER, O_CREAT | O_EXCL))
IF (Mkfifo (FIFO_SERVER, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP))
{
Printf ("Cannot Create FifoServer / N);
}
Printf ("GUI: Open Namepipe ... / n");
// = Open (FIFO_SERVER, O_WRONLY | O_NONBLOCK, 0);
FD = Open (FIFO_SERVER, O_RDWR, 0);
// fd = open (FIFO_SERVER, O_RDONLY, 0);
IF (fd == - 1)
{
Printf ("GUI: Open Error / N");
Return 0;
}
Printf ("GUI: Wait Namepipe Write ... / n");
READ (FD, (CHAR *) (& BUF), 1); // The program will stop here until the Player program is running
Printf ("GUI: Player Finished! / N");
Unlink (FIFO_SERVER);
}
/*Player.c*/
#include
#include
#include
#include
#include
#define FIFO_SERVER "./fifoserver"
int main ()
{
Int fd;
FD = Open (FIFO_SERVER, O_WRONLY, 0);
IF (fd == - 1)
{
Printf ("Open for Read Error / N");
Return 0;
}
Write (fd, (char *) "over", 5); // After the data is written, the GUI continues to run
Close (FD);
}