testing 1 2 3

testing


Joe Bishop (joe@qnx.com)

Hi all,

I have written a small photon program, that first generates a pipe using
the pipe command, then forks and within the fork child uses dup2 to
assign a new fd[0], then the child calls execl to run a non photon shell
command. The idea behind is to read the output from an executable
command into the photon application. But this won’t work, the child
crashes during (or after) the execl (but before the new command was
started) → SIGSEGV.
The example is even simple and it’s only a slight variation of the
example at the fork command within the documentation. Are there any
restrictions using the execl command within a forked photon application?

Andre Koppel <akoppel@akso.de> wrote:

I have written a small photon program, that first generates a pipe using
the pipe command, then forks and within the fork child uses dup2 to
assign a new fd[0], then the child calls execl to run a non photon shell
command. The idea behind is to read the output from an executable
command into the photon application. But this won’t work, the child
crashes during (or after) the execl (but before the new command was
started) → SIGSEGV.
The example is even simple and it’s only a slight variation of the
example at the fork command within the documentation. Are there any
restrictions using the execl command within a forked photon application?

Not that I know of. I have several Photon applications that use the
pipe+fork+dup2+exec sequence, and they seem to work fine. Of course,
you must make sure that the forked child doesn’t try to do any Photon
stuff before calling exec(). You also have to make sure that the child
doesn’t calls exit() on error (you should call _exit() instead), but I
guess this is not what causes your crash, is it…

Are you sure it’s not something trivial – didn’t you for instance
forget to put a NULL as the last argument to execl()?..


Wojtek Lerch QNX Software Systems Ltd.