Linux systems programming, suggestions wanted
OK, I know people will find this amusing, but I am doing system level Linux programming for the first time in a very long time (15+ years?) and I'm not actually sure what the best recommendation is for doing something as simple as starting a process.
Now, since I'm trying to get some low level infrastructure to work correctly, I want to do things right.
So, the question is: How do I properly detect that execv
has failed? Sure, the function will return, but when what do I do?
I then remembered seeing that the JVM implementation of Runtime.exec
is implemented by sending messages on a pipe, so I decided to try that.
I tried using pipe
to create a pipe, I set the CLOEXEC
flag on it, and I then send a message on the pipe after execv
returns. The idea was that if execv
suceeded, it would close the pipe, and I can monitor this using epoll
on the calling side. This doesn't work, for some reason that I have yet to figure out (I don't get a notification when the pipe is closed, perhaps it isn't closed at all?)
Last time I did this, I was using Solaris, so I fixed all the race conditions and other issues that can occur with fork
and exec
by using posix_spawn
. But it appears that Linux doesn't actually implement this on the kernel level.