This is what inheriting open file descriptors is for.
Make a FIFO. Open a close-on-exec write-only file descriptor to it in the parent shell. All of the fork()
ed children will inherit it, and then close it when they execve()
. Open a read-only file descriptor to it in the process that needs to detect the execve()
, or have that process inherit an already-open read-only file descriptor. When the write-only ends are closed by the execve()
, the read-only end will return EOF.
For detecting individual execve()
s, generalize to multiple FIFOs. Indeed, at that point you can not bother with FIFOs and just use a second set of pipes, with their write file descriptors set to close-on-exec.
Since you have not explained what this is actually for, working out how to build this into what you are actually trying to do is your task alone.
less
sets up and tears down its full-screen TUI. – JdeBP Jan 17 '18 at 11:08