Re: Starting an external process from C++



Henrik Goldman schrieb:
If popen satisfies your needs, then it is the way to go. fork/exec will
work almost everywhere, and posix_spawn. For examples and more
information concerning this topic, I'd recommend you to take a look into
APUE2e (Advanced Programming in the UNIX Environment, 2nd edition).


Thanks for your suggestions. The only problem about the popen aproach is
that I loose the pid of the child process. The child is really a daemon so I
need to send a command to it to make it shutdown. Otherwise it would hang
around forever.

Is there a way to signal to the opened process?

Thanks.

-- Henrik



spawning a daemon works by forking two times in sequence and terminating
the process in the middle. So if the daemon is spawned by the process
you start from your application, there will be no direct way of
determining the pid of the spawned daemon. You will have to rely on some
facility provided by the executable used to spawn the daemon. E.g. a pid
file or something similar.

In contrast, if you spawn the daemon by yourself using fork/exec, you
will have full control over what is happening.

Either way, the whole topic isn't really straight forward. So I'd
recommend you to get a book that describes UNIX's processes and the
semantics of fork and exec in detail.

Tom
.



Relevant Pages