Current section

Files

Jump to
alcove edoc fexecve-5.edoc
Raw

edoc/fexecve-5.edoc

@doc fexecve(2): replace the process image
Replace the process image, specifying the environment for the new process
image, using a previously opened file descriptor. The file descriptor
can be set to close after exec() by passing the O_CLOEXEC flag to open:
```
{ok, Pid} = alcove:fork(Drv, []),
{ok, FD} = alcove:open(Drv, [Pid], "/bin/ls", [o_rdonly,o_cloexec], 0),
ok = alcove:fexecve(Drv, [Pid], FD, ["ls", "-al"], ["FOO=123"]).
'''
Linux requires an environment to be set unlike with execve(2). The
environment can be empty:
```
% Environment required on Linux
ok = alcove:fexecve(Drv, [Pid], FD, ["ls", "-al"], [""]).
'''
== Support ==
• Linux
• FreeBSD
== Examples ==
```
1> {ok, Drv} = alcove_drv:start([{exec, "sudo -n"}]).
{ok,<0.177.0>}
2> {ok, Pid} = alcove:fork(Drv, []).
{ok,31491}
3> {ok, FD} = alcove:open(Drv, [Pid], "/usr/bin/env", [o_rdonly,o_cloexec], 0).
{ok,6}
4> alcove:fexecve(Drv, [Pid], FD, ["env", "-0"], ["FOO=123"]).
ok
5> flush().
Shell got {alcove_stdout,<0.177.0>,[31491],<<70,79,79,61,49,50,51,0>>}
Shell got {alcove_event,<0.177.0>,[31491],{exit_status,0}}
ok
'''