Home

Awesome

prx

Package Version Hex Docs

An Erlang library for Unix process management and system programming tasks.

prx provides:

Build

$ rebar3 compile

Quick Start

prx has two basic operations: fork and exec.

% Spawn a new system process
{ok, Task} = prx:fork(),

% And a child of the process
{ok, Child} = prx:fork(Task).

After fork()'ing, other calls can be made. For example:

UID = prx:getuid(Task),
PID = prx:getpid(Child).

Calling exec() causes the process I/O to be treated as streams of data:

ok = prx:execvp(Child, ["/bin/cat", "-n"]),
prx:stdin(Child, "test\n"),
receive
    {stdout,Child,Stdout} ->
        Stdout
end.

Usage

beam
  |-erl_child_setup
  |   `-prx
  |       `-prx

After calling exec, the process tree looks like:

beam
  |-erl_child_setup
  |   `-prx
  |       `-cat
    {ok, Task} = prx:fork(),
    {ok, Child} = prx:fork(Task),
    OSPid = prx:getpid(Child),
    ok = prx:execvp(Child, ["/bin/cat", "-n"],
    prx:stdin(Child, "test\n"),
    receive {stdout, Child, _} = Out -> Out end.

Documentation

https://hexdocs.pm/prx/

See also: alcove